summaryrefslogtreecommitdiff
path: root/src/FunctionHandler/AttributeBase.php
blob: 71a035dc96a666213b01f8cbb19d4c3fb2f95441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace Smarty\FunctionHandler;

use Smarty\Template;

/**
 * Abstract implementation for function handlers which support custom attributes
 */
abstract class AttributeBase implements AttributeFunctionHandlerInterface
{
	/**
	 * Array of names of required attribute required by tag
	 *
	 * @var array
	 */
	protected array $required_attributes = [];

	/**
	 * Array of names of optional attribute required by tag
	 * use array('_any') if there is no restriction of attributes names
	 *
	 * @var array
	 */
	protected array $optional_attributes = [];

	/**
	 * Shorttag attribute order defined by its names
	 *
	 * @var array
	 */
	protected array $shorttag_order = [];

	/**
	 * Array of names of valid option flags
	 *
	 * @var array
	 */
	protected array $option_flags = [];

	/**
	 * Return whether the output is cacheable.
	 * @var bool
	 */
	protected bool $cacheable = true;

	/**
	 * Return whether the output is cacheable.
	 * @return bool
	 */
	public function isCacheable(): bool
	{
		return $this->cacheable;
	}

	/**
	 * Function body
	 * @param mixed $params The supplied parameters.
	 * @param Smarty\Template $template 
	 * @return mixed 
	 */
	abstract public function handle($params, Template $template): ?string;

	/**
	 * Return the support attributes for this function.
	 * @return array<string, array> 
	 */
	public function getSupportedAttributes(): array
	{
		return [
			'required_attributes' => $this->required_attributes,
			'optional_attributes' => $this->optional_attributes,
			'shorttag_order' => $this->shorttag_order,
			'option_flags' => $this->option_flags,
		];
	}
}