| Total Complexity | 10 |
| Total Lines | 107 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class View |
||
| 19 | { |
||
| 20 | use \Drone\Util\ParamTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * View name |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $name; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The path where views are located. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $path; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Returns the view name |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function getName() |
||
| 42 | { |
||
| 43 | return $this->name; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns the path |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function getPath() |
||
| 52 | { |
||
| 53 | return $this->path; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Sets the view name |
||
| 58 | * |
||
| 59 | * @param string |
||
| 60 | * |
||
| 61 | * @return null |
||
| 62 | */ |
||
| 63 | public function setName($name) |
||
| 64 | { |
||
| 65 | $this->name = $name; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Sets the path |
||
| 70 | * |
||
| 71 | * @param string |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function setPath($path) |
||
| 76 | { |
||
| 77 | $this->path = $path; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Constructor |
||
| 82 | * |
||
| 83 | * @param string $name |
||
| 84 | * @param array $parameters |
||
| 85 | */ |
||
| 86 | public function __construct($name, Array $parameters = []) |
||
| 87 | { |
||
| 88 | $this->name = $name; |
||
| 89 | $this->setParams($parameters); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get the contents of the view |
||
| 94 | * |
||
| 95 | * @throws Exception\ViewNotFoundException |
||
| 96 | * |
||
| 97 | * @return null |
||
| 98 | */ |
||
| 99 | public function getContents() |
||
| 100 | { |
||
| 101 | $_view = $this->path . DIRECTORY_SEPARATOR . $this->name . '.phtml'; |
||
| 102 | |||
| 103 | if (!file_exists($_view)) |
||
| 104 | throw new Exception\ViewNotFoundException("The view '" .$this->name. "' does not exists"); |
||
| 105 | |||
| 106 | $contents = file_get_contents($_view); |
||
| 107 | |||
| 108 | if ($contents === false) |
||
| 109 | throw new Exception\ViewGetContentsErrorException("The view '" .$this->name. "' does not exists"); |
||
| 110 | |||
| 111 | return $contents; |
||
|
|
|||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Loads the view |
||
| 116 | * |
||
| 117 | * @return null |
||
| 118 | */ |
||
| 119 | public function render() |
||
| 125 | } |
||
| 126 | } |