| Total Complexity | 7 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ViewHelpers |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Array of template functions. |
||
| 16 | * @var callable[] |
||
| 17 | */ |
||
| 18 | private $helpers = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Add a new template function. |
||
| 22 | * @param string $name |
||
| 23 | * @param callback $callback |
||
| 24 | * @return ViewHelpers |
||
| 25 | */ |
||
| 26 | public function add(string $name, callable $callback): self |
||
| 27 | { |
||
| 28 | if ($this->exists($name)) { |
||
| 29 | throw new LogicException( |
||
| 30 | 'The helper function name "' . $name . '" is already registered.' |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | $this->helpers[$name] = $callback; |
||
| 35 | |||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Remove a template function. |
||
| 41 | * @param string $name |
||
| 42 | * @return ViewHelpers |
||
| 43 | */ |
||
| 44 | public function remove(string $name): self |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get a template function. |
||
| 59 | * @param string $name |
||
| 60 | * @return callable |
||
| 61 | */ |
||
| 62 | public function get(string $name): callable |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Check if a template function exists. |
||
| 73 | * @param string $name |
||
| 74 | * @return boolean |
||
| 75 | */ |
||
| 76 | public function exists(string $name): bool |
||
| 79 | } |
||
| 80 | } |
||
| 81 |