@@ -119,7 +119,7 @@ |
||
| 119 | 119 | * @param array $context Optional. The context in which to render the view. |
| 120 | 120 | * @param string|null $type Type of view to create. |
| 121 | 121 | * |
| 122 | - * @return ViewInterface Instance of the requested view. |
|
| 122 | + * @return string Instance of the requested view. |
|
| 123 | 123 | */ |
| 124 | 124 | public static function render($view, array $context = [], $type = null) |
| 125 | 125 | { |
@@ -28,104 +28,104 @@ |
||
| 28 | 28 | class View |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * ViewBuilder Instance. |
|
| 33 | - * |
|
| 34 | - * @since 0.1.0 |
|
| 35 | - * |
|
| 36 | - * @var ViewBuilder |
|
| 37 | - */ |
|
| 38 | - protected static $viewBuilder; |
|
| 31 | + /** |
|
| 32 | + * ViewBuilder Instance. |
|
| 33 | + * |
|
| 34 | + * @since 0.1.0 |
|
| 35 | + * |
|
| 36 | + * @var ViewBuilder |
|
| 37 | + */ |
|
| 38 | + protected static $viewBuilder; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Add a location to the ViewBuilder. |
|
| 42 | - * |
|
| 43 | - * @since 0.1.0 |
|
| 44 | - * |
|
| 45 | - * @param LocationInterface $location Location to add. |
|
| 46 | - */ |
|
| 47 | - public static function addLocation(LocationInterface $location) |
|
| 48 | - { |
|
| 49 | - $viewBuilder = static::getViewBuilder(); |
|
| 50 | - $viewBuilder->addLocation($location); |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * Add a location to the ViewBuilder. |
|
| 42 | + * |
|
| 43 | + * @since 0.1.0 |
|
| 44 | + * |
|
| 45 | + * @param LocationInterface $location Location to add. |
|
| 46 | + */ |
|
| 47 | + public static function addLocation(LocationInterface $location) |
|
| 48 | + { |
|
| 49 | + $viewBuilder = static::getViewBuilder(); |
|
| 50 | + $viewBuilder->addLocation($location); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the ViewBuilder instance. |
|
| 55 | - * |
|
| 56 | - * @since 0.1.0 |
|
| 57 | - * |
|
| 58 | - * @return ViewBuilder |
|
| 59 | - */ |
|
| 60 | - public static function getViewBuilder() |
|
| 61 | - { |
|
| 62 | - if (null === static::$viewBuilder) { |
|
| 63 | - static::$viewBuilder = static::instantiateViewBuilder(); |
|
| 64 | - } |
|
| 53 | + /** |
|
| 54 | + * Get the ViewBuilder instance. |
|
| 55 | + * |
|
| 56 | + * @since 0.1.0 |
|
| 57 | + * |
|
| 58 | + * @return ViewBuilder |
|
| 59 | + */ |
|
| 60 | + public static function getViewBuilder() |
|
| 61 | + { |
|
| 62 | + if (null === static::$viewBuilder) { |
|
| 63 | + static::$viewBuilder = static::instantiateViewBuilder(); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return static::$viewBuilder; |
|
| 67 | - } |
|
| 66 | + return static::$viewBuilder; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Instantiate the ViewBuilder. |
|
| 71 | - * |
|
| 72 | - * @since 0.1.0 |
|
| 73 | - * |
|
| 74 | - * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
| 75 | - * |
|
| 76 | - * @return ViewBuilder Instance of the ViewBuilder. |
|
| 77 | - */ |
|
| 78 | - public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
| 79 | - { |
|
| 80 | - return static::$viewBuilder = new ViewBuilder($config ?: static::getDefaultConfig()); |
|
| 81 | - } |
|
| 69 | + /** |
|
| 70 | + * Instantiate the ViewBuilder. |
|
| 71 | + * |
|
| 72 | + * @since 0.1.0 |
|
| 73 | + * |
|
| 74 | + * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
| 75 | + * |
|
| 76 | + * @return ViewBuilder Instance of the ViewBuilder. |
|
| 77 | + */ |
|
| 78 | + public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
| 79 | + { |
|
| 80 | + return static::$viewBuilder = new ViewBuilder($config ?: static::getDefaultConfig()); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Get the default configuration to inject into the ViewBuilder. |
|
| 85 | - * |
|
| 86 | - * @since 0.1.0 |
|
| 87 | - * |
|
| 88 | - * @return ConfigInterface Default configuration. |
|
| 89 | - */ |
|
| 90 | - public static function getDefaultConfig() |
|
| 91 | - { |
|
| 92 | - return ConfigFactory::create(__DIR__ . '/../config/defaults.php') |
|
| 93 | - ->getSubConfig('BrightNucleus\View'); |
|
| 94 | - } |
|
| 83 | + /** |
|
| 84 | + * Get the default configuration to inject into the ViewBuilder. |
|
| 85 | + * |
|
| 86 | + * @since 0.1.0 |
|
| 87 | + * |
|
| 88 | + * @return ConfigInterface Default configuration. |
|
| 89 | + */ |
|
| 90 | + public static function getDefaultConfig() |
|
| 91 | + { |
|
| 92 | + return ConfigFactory::create(__DIR__ . '/../config/defaults.php') |
|
| 93 | + ->getSubConfig('BrightNucleus\View'); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Create a new view for a given URI. |
|
| 98 | - * |
|
| 99 | - * @since 0.1.0 |
|
| 100 | - * |
|
| 101 | - * @param string $view View identifier to create a view for. |
|
| 102 | - * @param string|null $type Type of view to create. |
|
| 103 | - * |
|
| 104 | - * @return ViewInterface Instance of the requested view. |
|
| 105 | - */ |
|
| 106 | - public static function create($view, $type = null) |
|
| 107 | - { |
|
| 108 | - $viewBuilder = static::getViewBuilder(); |
|
| 96 | + /** |
|
| 97 | + * Create a new view for a given URI. |
|
| 98 | + * |
|
| 99 | + * @since 0.1.0 |
|
| 100 | + * |
|
| 101 | + * @param string $view View identifier to create a view for. |
|
| 102 | + * @param string|null $type Type of view to create. |
|
| 103 | + * |
|
| 104 | + * @return ViewInterface Instance of the requested view. |
|
| 105 | + */ |
|
| 106 | + public static function create($view, $type = null) |
|
| 107 | + { |
|
| 108 | + $viewBuilder = static::getViewBuilder(); |
|
| 109 | 109 | |
| 110 | - return $viewBuilder->create($view, $type); |
|
| 111 | - } |
|
| 110 | + return $viewBuilder->create($view, $type); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Render a view for a given URI. |
|
| 115 | - * |
|
| 116 | - * @since 0.1.0 |
|
| 117 | - * |
|
| 118 | - * @param string $view View identifier to create a view for. |
|
| 119 | - * @param array $context Optional. The context in which to render the view. |
|
| 120 | - * @param string|null $type Type of view to create. |
|
| 121 | - * |
|
| 122 | - * @return ViewInterface Instance of the requested view. |
|
| 123 | - */ |
|
| 124 | - public static function render($view, array $context = [], $type = null) |
|
| 125 | - { |
|
| 126 | - $viewBuilder = static::getViewBuilder(); |
|
| 127 | - $viewObject = $viewBuilder->create($view, $type); |
|
| 113 | + /** |
|
| 114 | + * Render a view for a given URI. |
|
| 115 | + * |
|
| 116 | + * @since 0.1.0 |
|
| 117 | + * |
|
| 118 | + * @param string $view View identifier to create a view for. |
|
| 119 | + * @param array $context Optional. The context in which to render the view. |
|
| 120 | + * @param string|null $type Type of view to create. |
|
| 121 | + * |
|
| 122 | + * @return ViewInterface Instance of the requested view. |
|
| 123 | + */ |
|
| 124 | + public static function render($view, array $context = [], $type = null) |
|
| 125 | + { |
|
| 126 | + $viewBuilder = static::getViewBuilder(); |
|
| 127 | + $viewObject = $viewBuilder->create($view, $type); |
|
| 128 | 128 | |
| 129 | - return $viewObject->render($context); |
|
| 130 | - } |
|
| 129 | + return $viewObject->render($context); |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | */ |
| 90 | 90 | public static function getDefaultConfig() |
| 91 | 91 | { |
| 92 | - return ConfigFactory::create(__DIR__ . '/../config/defaults.php') |
|
| 92 | + return ConfigFactory::create(__DIR__.'/../config/defaults.php') |
|
| 93 | 93 | ->getSubConfig('BrightNucleus\View'); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | * |
| 84 | 84 | * @param string $entry Entry to transform. |
| 85 | 85 | * |
| 86 | - * @return string|bool URI of the view, or false if none found. |
|
| 86 | + * @return string|false URI of the view, or false if none found. |
|
| 87 | 87 | */ |
| 88 | 88 | protected function transform($entry) |
| 89 | 89 | { |
@@ -24,86 +24,86 @@ |
||
| 24 | 24 | class FilesystemLocation implements LocationInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Path that this location points to. |
|
| 29 | - * |
|
| 30 | - * @since 0.1.0 |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $path; |
|
| 27 | + /** |
|
| 28 | + * Path that this location points to. |
|
| 29 | + * |
|
| 30 | + * @since 0.1.0 |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $path; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Extensions that this location can accept. |
|
| 38 | - * |
|
| 39 | - * @since 0.1.0 |
|
| 40 | - * |
|
| 41 | - * @var array<string> |
|
| 42 | - */ |
|
| 43 | - protected $extensions; |
|
| 36 | + /** |
|
| 37 | + * Extensions that this location can accept. |
|
| 38 | + * |
|
| 39 | + * @since 0.1.0 |
|
| 40 | + * |
|
| 41 | + * @var array<string> |
|
| 42 | + */ |
|
| 43 | + protected $extensions; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Instantiate a FilesystemLocation object. |
|
| 47 | - * |
|
| 48 | - * @since 0.1.0 |
|
| 49 | - * |
|
| 50 | - * @param string $path Path that this location points to. |
|
| 51 | - * @param array $extensions Array of extensions that this location can accept. |
|
| 52 | - */ |
|
| 53 | - public function __construct($path, array $extensions = []) |
|
| 54 | - { |
|
| 55 | - $this->path = $path; |
|
| 56 | - $this->extensions = array_merge($extensions, ['']); |
|
| 57 | - } |
|
| 45 | + /** |
|
| 46 | + * Instantiate a FilesystemLocation object. |
|
| 47 | + * |
|
| 48 | + * @since 0.1.0 |
|
| 49 | + * |
|
| 50 | + * @param string $path Path that this location points to. |
|
| 51 | + * @param array $extensions Array of extensions that this location can accept. |
|
| 52 | + */ |
|
| 53 | + public function __construct($path, array $extensions = []) |
|
| 54 | + { |
|
| 55 | + $this->path = $path; |
|
| 56 | + $this->extensions = array_merge($extensions, ['']); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get an URI that matches the given criteria. |
|
| 61 | - * |
|
| 62 | - * @since 0.1.0 |
|
| 63 | - * |
|
| 64 | - * @param array $criteria Criteria to match. |
|
| 65 | - * |
|
| 66 | - * @return string|false URI that matches the criteria or false if none found. |
|
| 67 | - */ |
|
| 68 | - public function getURI(array $criteria) |
|
| 69 | - { |
|
| 70 | - foreach ($criteria as $entry) { |
|
| 71 | - if ($uri = $this->transform($entry)) { |
|
| 72 | - return $uri; |
|
| 73 | - } |
|
| 74 | - } |
|
| 59 | + /** |
|
| 60 | + * Get an URI that matches the given criteria. |
|
| 61 | + * |
|
| 62 | + * @since 0.1.0 |
|
| 63 | + * |
|
| 64 | + * @param array $criteria Criteria to match. |
|
| 65 | + * |
|
| 66 | + * @return string|false URI that matches the criteria or false if none found. |
|
| 67 | + */ |
|
| 68 | + public function getURI(array $criteria) |
|
| 69 | + { |
|
| 70 | + foreach ($criteria as $entry) { |
|
| 71 | + if ($uri = $this->transform($entry)) { |
|
| 72 | + return $uri; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return false; |
|
| 77 | - } |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Try to transform the entry into possible URIs. |
|
| 81 | - * |
|
| 82 | - * @since 0.1.0 |
|
| 83 | - * |
|
| 84 | - * @param string $entry Entry to transform. |
|
| 85 | - * |
|
| 86 | - * @return string|bool URI of the view, or false if none found. |
|
| 87 | - */ |
|
| 88 | - protected function transform($entry) |
|
| 89 | - { |
|
| 90 | - try { |
|
| 91 | - foreach ($this->extensions as $extension) { |
|
| 79 | + /** |
|
| 80 | + * Try to transform the entry into possible URIs. |
|
| 81 | + * |
|
| 82 | + * @since 0.1.0 |
|
| 83 | + * |
|
| 84 | + * @param string $entry Entry to transform. |
|
| 85 | + * |
|
| 86 | + * @return string|bool URI of the view, or false if none found. |
|
| 87 | + */ |
|
| 88 | + protected function transform($entry) |
|
| 89 | + { |
|
| 90 | + try { |
|
| 91 | + foreach ($this->extensions as $extension) { |
|
| 92 | 92 | |
| 93 | - $uri = $entry . $extension; |
|
| 94 | - if (is_readable($uri)) { |
|
| 95 | - return $uri; |
|
| 96 | - } |
|
| 93 | + $uri = $entry . $extension; |
|
| 94 | + if (is_readable($uri)) { |
|
| 95 | + return $uri; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $uri = $this->path . DIRECTORY_SEPARATOR . $uri; |
|
| 99 | - if (is_readable($uri)) { |
|
| 100 | - return $uri; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } catch (Exception $exception) { |
|
| 104 | - // Fail silently. |
|
| 105 | - } |
|
| 98 | + $uri = $this->path . DIRECTORY_SEPARATOR . $uri; |
|
| 99 | + if (is_readable($uri)) { |
|
| 100 | + return $uri; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } catch (Exception $exception) { |
|
| 104 | + // Fail silently. |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return false; |
|
| 108 | - } |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -90,12 +90,12 @@ |
||
| 90 | 90 | try { |
| 91 | 91 | foreach ($this->extensions as $extension) { |
| 92 | 92 | |
| 93 | - $uri = $entry . $extension; |
|
| 93 | + $uri = $entry.$extension; |
|
| 94 | 94 | if (is_readable($uri)) { |
| 95 | 95 | return $uri; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $uri = $this->path . DIRECTORY_SEPARATOR . $uri; |
|
| 98 | + $uri = $this->path.DIRECTORY_SEPARATOR.$uri; |
|
| 99 | 99 | if (is_readable($uri)) { |
| 100 | 100 | return $uri; |
| 101 | 101 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | * |
| 31 | 31 | * @since 0.1.0 |
| 32 | 32 | * |
| 33 | - * @param array $criteria Criteria to search for. |
|
| 33 | + * @param string[] $criteria Criteria to search for. |
|
| 34 | 34 | * @param EngineInterface $engine Optional. Engine to use with the view. |
| 35 | 35 | * |
| 36 | 36 | * @return ViewInterface View that was found. |
@@ -25,15 +25,15 @@ |
||
| 25 | 25 | interface ViewFinderInterface extends FinderInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Find a result based on a specific criteria. |
|
| 30 | - * |
|
| 31 | - * @since 0.1.0 |
|
| 32 | - * |
|
| 33 | - * @param array $criteria Criteria to search for. |
|
| 34 | - * @param EngineInterface $engine Optional. Engine to use with the view. |
|
| 35 | - * |
|
| 36 | - * @return ViewInterface View that was found. |
|
| 37 | - */ |
|
| 38 | - public function find(array $criteria, EngineInterface $engine = null); |
|
| 28 | + /** |
|
| 29 | + * Find a result based on a specific criteria. |
|
| 30 | + * |
|
| 31 | + * @since 0.1.0 |
|
| 32 | + * |
|
| 33 | + * @param array $criteria Criteria to search for. |
|
| 34 | + * @param EngineInterface $engine Optional. Engine to use with the view. |
|
| 35 | + * |
|
| 36 | + * @return ViewInterface View that was found. |
|
| 37 | + */ |
|
| 38 | + public function find(array $criteria, EngineInterface $engine = null); |
|
| 39 | 39 | } |
@@ -12,26 +12,26 @@ |
||
| 12 | 12 | namespace BrightNucleus\View; |
| 13 | 13 | |
| 14 | 14 | $engineFinder = [ |
| 15 | - 'ClassName' => 'BrightNucleus\View\Engine\EngineFinder', |
|
| 16 | - 'Engines' => [ |
|
| 17 | - 'PHPEngine' => 'BrightNucleus\View\Engine\PHPEngine', |
|
| 18 | - ], |
|
| 19 | - 'NullObject' => 'BrightNucleus\View\Engine\NullEngine', |
|
| 15 | + 'ClassName' => 'BrightNucleus\View\Engine\EngineFinder', |
|
| 16 | + 'Engines' => [ |
|
| 17 | + 'PHPEngine' => 'BrightNucleus\View\Engine\PHPEngine', |
|
| 18 | + ], |
|
| 19 | + 'NullObject' => 'BrightNucleus\View\Engine\NullEngine', |
|
| 20 | 20 | ]; |
| 21 | 21 | |
| 22 | 22 | $viewFinder = [ |
| 23 | - 'ClassName' => 'BrightNucleus\View\View\ViewFinder', |
|
| 24 | - 'Views' => [ |
|
| 25 | - 'BaseView' => 'BrightNucleus\View\View\BaseView', |
|
| 26 | - ], |
|
| 27 | - 'NullObject' => 'BrightNucleus\View\View\NullView', |
|
| 23 | + 'ClassName' => 'BrightNucleus\View\View\ViewFinder', |
|
| 24 | + 'Views' => [ |
|
| 25 | + 'BaseView' => 'BrightNucleus\View\View\BaseView', |
|
| 26 | + ], |
|
| 27 | + 'NullObject' => 'BrightNucleus\View\View\NullView', |
|
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | 30 | return [ |
| 31 | - 'BrightNucleus' => [ |
|
| 32 | - 'View' => [ |
|
| 33 | - 'EngineFinder' => $engineFinder, |
|
| 34 | - 'ViewFinder' => $viewFinder, |
|
| 35 | - ], |
|
| 36 | - ], |
|
| 31 | + 'BrightNucleus' => [ |
|
| 32 | + 'View' => [ |
|
| 33 | + 'EngineFinder' => $engineFinder, |
|
| 34 | + 'ViewFinder' => $viewFinder, |
|
| 35 | + ], |
|
| 36 | + ], |
|
| 37 | 37 | ]; |
@@ -22,14 +22,14 @@ |
||
| 22 | 22 | interface FinderInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Find a result based on a specific criteria. |
|
| 27 | - * |
|
| 28 | - * @since 0.1.0 |
|
| 29 | - * |
|
| 30 | - * @param array $criteria Criteria to search for. |
|
| 31 | - * |
|
| 32 | - * @return mixed Result of the search. |
|
| 33 | - */ |
|
| 34 | - public function find(array $criteria); |
|
| 25 | + /** |
|
| 26 | + * Find a result based on a specific criteria. |
|
| 27 | + * |
|
| 28 | + * @since 0.1.0 |
|
| 29 | + * |
|
| 30 | + * @param array $criteria Criteria to search for. |
|
| 31 | + * |
|
| 32 | + * @return mixed Result of the search. |
|
| 33 | + */ |
|
| 34 | + public function find(array $criteria); |
|
| 35 | 35 | } |
@@ -26,102 +26,102 @@ |
||
| 26 | 26 | abstract class AbstractFinder implements FinderInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - use ConfigTrait; |
|
| 29 | + use ConfigTrait; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Array of Findables that the Finder can iterate through to find a match. |
|
| 33 | - * |
|
| 34 | - * @since 0.1.0 |
|
| 35 | - * |
|
| 36 | - * @var Findable[] |
|
| 37 | - */ |
|
| 38 | - protected $findables; |
|
| 31 | + /** |
|
| 32 | + * Array of Findables that the Finder can iterate through to find a match. |
|
| 33 | + * |
|
| 34 | + * @since 0.1.0 |
|
| 35 | + * |
|
| 36 | + * @var Findable[] |
|
| 37 | + */ |
|
| 38 | + protected $findables; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * NullObject that is returned if the Finder could not find a match. |
|
| 42 | - * |
|
| 43 | - * @since 0.1.0 |
|
| 44 | - * |
|
| 45 | - * @var NullObject |
|
| 46 | - */ |
|
| 47 | - protected $nullObject; |
|
| 40 | + /** |
|
| 41 | + * NullObject that is returned if the Finder could not find a match. |
|
| 42 | + * |
|
| 43 | + * @since 0.1.0 |
|
| 44 | + * |
|
| 45 | + * @var NullObject |
|
| 46 | + */ |
|
| 47 | + protected $nullObject; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Instantiate an AbstractFinder object. |
|
| 51 | - * |
|
| 52 | - * @since 0.1.0 |
|
| 53 | - * |
|
| 54 | - * @param ConfigInterface $config Configuration of the EngineFinder. |
|
| 55 | - * |
|
| 56 | - * @throws FailedToProcessConfigException If the config could not be processed. |
|
| 57 | - */ |
|
| 58 | - public function __construct(ConfigInterface $config) |
|
| 59 | - { |
|
| 60 | - $this->processConfig($config); |
|
| 61 | - $this->registerFindables($this->config); |
|
| 62 | - $this->registerNullObject($this->config); |
|
| 63 | - } |
|
| 49 | + /** |
|
| 50 | + * Instantiate an AbstractFinder object. |
|
| 51 | + * |
|
| 52 | + * @since 0.1.0 |
|
| 53 | + * |
|
| 54 | + * @param ConfigInterface $config Configuration of the EngineFinder. |
|
| 55 | + * |
|
| 56 | + * @throws FailedToProcessConfigException If the config could not be processed. |
|
| 57 | + */ |
|
| 58 | + public function __construct(ConfigInterface $config) |
|
| 59 | + { |
|
| 60 | + $this->processConfig($config); |
|
| 61 | + $this->registerFindables($this->config); |
|
| 62 | + $this->registerNullObject($this->config); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Register the Findables defined in the given configuration. |
|
| 67 | - * |
|
| 68 | - * @since 0.1.0 |
|
| 69 | - * |
|
| 70 | - * @param ConfigInterface $config Configuration to register the Findables from. |
|
| 71 | - */ |
|
| 72 | - public function registerFindables(ConfigInterface $config) |
|
| 73 | - { |
|
| 74 | - foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) { |
|
| 75 | - $this->registerFindable($findableKey, $findableObject); |
|
| 76 | - } |
|
| 77 | - } |
|
| 65 | + /** |
|
| 66 | + * Register the Findables defined in the given configuration. |
|
| 67 | + * |
|
| 68 | + * @since 0.1.0 |
|
| 69 | + * |
|
| 70 | + * @param ConfigInterface $config Configuration to register the Findables from. |
|
| 71 | + */ |
|
| 72 | + public function registerFindables(ConfigInterface $config) |
|
| 73 | + { |
|
| 74 | + foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) { |
|
| 75 | + $this->registerFindable($findableKey, $findableObject); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Register the NullObject defined in the given configuration. |
|
| 81 | - * |
|
| 82 | - * @since 0.1.0 |
|
| 83 | - * |
|
| 84 | - * @param ConfigInterface $config Configuration to register the NullObject from. |
|
| 85 | - */ |
|
| 86 | - public function registerNullObject(ConfigInterface $config) |
|
| 87 | - { |
|
| 88 | - $this->nullObject = $config->getKey($this->getNullObjectConfigKey()); |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * Register the NullObject defined in the given configuration. |
|
| 81 | + * |
|
| 82 | + * @since 0.1.0 |
|
| 83 | + * |
|
| 84 | + * @param ConfigInterface $config Configuration to register the NullObject from. |
|
| 85 | + */ |
|
| 86 | + public function registerNullObject(ConfigInterface $config) |
|
| 87 | + { |
|
| 88 | + $this->nullObject = $config->getKey($this->getNullObjectConfigKey()); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Register a single Findable. |
|
| 93 | - * |
|
| 94 | - * @since 0.1.0 |
|
| 95 | - * |
|
| 96 | - * @param string $key Key used to reference the Findable. |
|
| 97 | - * @param mixed $findable Findable as a FQCN, callable or object. |
|
| 98 | - */ |
|
| 99 | - protected function registerFindable($key, $findable) |
|
| 100 | - { |
|
| 101 | - $this->findables[$key] = $findable; |
|
| 102 | - } |
|
| 91 | + /** |
|
| 92 | + * Register a single Findable. |
|
| 93 | + * |
|
| 94 | + * @since 0.1.0 |
|
| 95 | + * |
|
| 96 | + * @param string $key Key used to reference the Findable. |
|
| 97 | + * @param mixed $findable Findable as a FQCN, callable or object. |
|
| 98 | + */ |
|
| 99 | + protected function registerFindable($key, $findable) |
|
| 100 | + { |
|
| 101 | + $this->findables[$key] = $findable; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Get the config key for the Findables definitions. |
|
| 106 | - * |
|
| 107 | - * @since 0.1.0 |
|
| 108 | - * |
|
| 109 | - * @return string Config key use to define the Findables. |
|
| 110 | - */ |
|
| 111 | - protected function getFindablesConfigKey() |
|
| 112 | - { |
|
| 113 | - return 'Findables'; |
|
| 114 | - } |
|
| 104 | + /** |
|
| 105 | + * Get the config key for the Findables definitions. |
|
| 106 | + * |
|
| 107 | + * @since 0.1.0 |
|
| 108 | + * |
|
| 109 | + * @return string Config key use to define the Findables. |
|
| 110 | + */ |
|
| 111 | + protected function getFindablesConfigKey() |
|
| 112 | + { |
|
| 113 | + return 'Findables'; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Get the config key for the NullObject definitions. |
|
| 118 | - * |
|
| 119 | - * @since 0.1.0 |
|
| 120 | - * |
|
| 121 | - * @return string Config key use to define the NullObject. |
|
| 122 | - */ |
|
| 123 | - protected function getNullObjectConfigKey() |
|
| 124 | - { |
|
| 125 | - return 'NullObject'; |
|
| 126 | - } |
|
| 116 | + /** |
|
| 117 | + * Get the config key for the NullObject definitions. |
|
| 118 | + * |
|
| 119 | + * @since 0.1.0 |
|
| 120 | + * |
|
| 121 | + * @return string Config key use to define the NullObject. |
|
| 122 | + */ |
|
| 123 | + protected function getNullObjectConfigKey() |
|
| 124 | + { |
|
| 125 | + return 'NullObject'; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -25,55 +25,55 @@ |
||
| 25 | 25 | abstract class AbstractView implements ViewInterface, Findable |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * URI of the view. |
|
| 30 | - * |
|
| 31 | - * @since 0.1.0 |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $uri; |
|
| 28 | + /** |
|
| 29 | + * URI of the view. |
|
| 30 | + * |
|
| 31 | + * @since 0.1.0 |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $uri; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Engine to use for the view. |
|
| 39 | - * |
|
| 40 | - * @since 0.1.0 |
|
| 41 | - * |
|
| 42 | - * @var EngineInterface |
|
| 43 | - */ |
|
| 44 | - protected $engine; |
|
| 37 | + /** |
|
| 38 | + * Engine to use for the view. |
|
| 39 | + * |
|
| 40 | + * @since 0.1.0 |
|
| 41 | + * |
|
| 42 | + * @var EngineInterface |
|
| 43 | + */ |
|
| 44 | + protected $engine; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Instantiate an AbstractView object. |
|
| 48 | - * |
|
| 49 | - * @since 0.1.0 |
|
| 50 | - * |
|
| 51 | - * @param string $uri URI for the view. |
|
| 52 | - * @param EngineInterface $engine Engine to use for the view. |
|
| 53 | - */ |
|
| 54 | - public function __construct($uri, EngineInterface $engine) |
|
| 55 | - { |
|
| 56 | - $this->uri = $uri; |
|
| 57 | - $this->engine = $engine; |
|
| 58 | - } |
|
| 46 | + /** |
|
| 47 | + * Instantiate an AbstractView object. |
|
| 48 | + * |
|
| 49 | + * @since 0.1.0 |
|
| 50 | + * |
|
| 51 | + * @param string $uri URI for the view. |
|
| 52 | + * @param EngineInterface $engine Engine to use for the view. |
|
| 53 | + */ |
|
| 54 | + public function __construct($uri, EngineInterface $engine) |
|
| 55 | + { |
|
| 56 | + $this->uri = $uri; |
|
| 57 | + $this->engine = $engine; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Render the view. |
|
| 62 | - * |
|
| 63 | - * @since 0.1.0 |
|
| 64 | - * |
|
| 65 | - * @param array $context Optional. The context in which to render the view. |
|
| 66 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
| 67 | - * |
|
| 68 | - * @return string|void Rendered HTML or nothing, depending on $echo argument. |
|
| 69 | - */ |
|
| 70 | - public function render(array $context = [], $echo = false) |
|
| 71 | - { |
|
| 72 | - $output = $this->engine->render($this->uri, $context); |
|
| 73 | - if ($echo) { |
|
| 74 | - echo $output; |
|
| 75 | - } else { |
|
| 76 | - return $output; |
|
| 77 | - } |
|
| 78 | - } |
|
| 60 | + /** |
|
| 61 | + * Render the view. |
|
| 62 | + * |
|
| 63 | + * @since 0.1.0 |
|
| 64 | + * |
|
| 65 | + * @param array $context Optional. The context in which to render the view. |
|
| 66 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
| 67 | + * |
|
| 68 | + * @return string|void Rendered HTML or nothing, depending on $echo argument. |
|
| 69 | + */ |
|
| 70 | + public function render(array $context = [], $echo = false) |
|
| 71 | + { |
|
| 72 | + $output = $this->engine->render($this->uri, $context); |
|
| 73 | + if ($echo) { |
|
| 74 | + echo $output; |
|
| 75 | + } else { |
|
| 76 | + return $output; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -22,14 +22,14 @@ |
||
| 22 | 22 | interface ViewInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Render the view. |
|
| 27 | - * |
|
| 28 | - * @since 0.1.0 |
|
| 29 | - * |
|
| 30 | - * @param array $context Optional. The context in which to render the view. |
|
| 31 | - * |
|
| 32 | - * @return string Rendered HTML. |
|
| 33 | - */ |
|
| 34 | - public function render(array $context = []); |
|
| 25 | + /** |
|
| 26 | + * Render the view. |
|
| 27 | + * |
|
| 28 | + * @since 0.1.0 |
|
| 29 | + * |
|
| 30 | + * @param array $context Optional. The context in which to render the view. |
|
| 31 | + * |
|
| 32 | + * @return string Rendered HTML. |
|
| 33 | + */ |
|
| 34 | + public function render(array $context = []); |
|
| 35 | 35 | } |
@@ -24,16 +24,16 @@ |
||
| 24 | 24 | class NullView implements ViewInterface, NullObject |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Render the view. |
|
| 29 | - * |
|
| 30 | - * @since 0.1.0 |
|
| 31 | - * |
|
| 32 | - * @param array $context Optional. The context in which to render the view. |
|
| 33 | - * |
|
| 34 | - * @return string Rendered HTML. |
|
| 35 | - */ |
|
| 36 | - public function render(array $context = []) |
|
| 37 | - { |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * Render the view. |
|
| 29 | + * |
|
| 30 | + * @since 0.1.0 |
|
| 31 | + * |
|
| 32 | + * @param array $context Optional. The context in which to render the view. |
|
| 33 | + * |
|
| 34 | + * @return string Rendered HTML. |
|
| 35 | + */ |
|
| 36 | + public function render(array $context = []) |
|
| 37 | + { |
|
| 38 | + } |
|
| 39 | 39 | } |