Data.php
3 years ago
Directory.php
3 years ago
FileExtension.php
3 years ago
Folder.php
3 years ago
Folders.php
3 years ago
Func.php
3 years ago
Functions.php
3 years ago
Name.php
3 years ago
Template.php
3 years ago
Folders.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\League\Plates\Template; |
| 4 | |
| 5 | use LogicException; |
| 6 | /** |
| 7 | * A collection of template folders. |
| 8 | */ |
| 9 | class Folders |
| 10 | { |
| 11 | /** |
| 12 | * Array of template folders. |
| 13 | * @var array |
| 14 | */ |
| 15 | protected $folders = array(); |
| 16 | /** |
| 17 | * Add a template folder. |
| 18 | * @param string $name |
| 19 | * @param string $path |
| 20 | * @param boolean $fallback |
| 21 | * @return Folders |
| 22 | */ |
| 23 | public function add($name, $path, $fallback = \false) |
| 24 | { |
| 25 | if ($this->exists($name)) { |
| 26 | throw new LogicException('The template folder "' . $name . '" is already being used.'); |
| 27 | } |
| 28 | $this->folders[$name] = new Folder($name, $path, $fallback); |
| 29 | return $this; |
| 30 | } |
| 31 | /** |
| 32 | * Remove a template folder. |
| 33 | * @param string $name |
| 34 | * @return Folders |
| 35 | */ |
| 36 | public function remove($name) |
| 37 | { |
| 38 | if (!$this->exists($name)) { |
| 39 | throw new LogicException('The template folder "' . $name . '" was not found.'); |
| 40 | } |
| 41 | unset($this->folders[$name]); |
| 42 | return $this; |
| 43 | } |
| 44 | /** |
| 45 | * Get a template folder. |
| 46 | * @param string $name |
| 47 | * @return Folder |
| 48 | */ |
| 49 | public function get($name) |
| 50 | { |
| 51 | if (!$this->exists($name)) { |
| 52 | throw new LogicException('The template folder "' . $name . '" was not found.'); |
| 53 | } |
| 54 | return $this->folders[$name]; |
| 55 | } |
| 56 | /** |
| 57 | * Check if a template folder exists. |
| 58 | * @param string $name |
| 59 | * @return boolean |
| 60 | */ |
| 61 | public function exists($name) |
| 62 | { |
| 63 | return isset($this->folders[$name]); |
| 64 | } |
| 65 | } |
| 66 |