@@ -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 | ]; |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $view = $view($uri, $engine); |
68 | 68 | } |
69 | 69 | |
70 | - if (! $view instanceof ViewInterface) { |
|
70 | + if ( ! $view instanceof ViewInterface) { |
|
71 | 71 | throw new FailedToInstantiateViewException( |
72 | 72 | sprintf( |
73 | 73 | _('Could not instantiate view "%s".'), |
@@ -73,7 +73,7 @@ |
||
73 | 73 | * |
74 | 74 | * @since 0.1.0 |
75 | 75 | * |
76 | - * @param mixed $view View to instantiate. |
|
76 | + * @param \BrightNucleus\View\Support\Findable $view View to instantiate. |
|
77 | 77 | * @param string $uri URI to use for the view. |
78 | 78 | * @param EngineInterface|null $engine Optional. Engine to use with the view. |
79 | 79 | * |
@@ -26,91 +26,91 @@ |
||
26 | 26 | class ViewFinder extends AbstractFinder |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Find a result based on a specific criteria. |
|
31 | - * |
|
32 | - * @since 0.1.0 |
|
33 | - * |
|
34 | - * @param array $criteria Criteria to search for. |
|
35 | - * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
36 | - * |
|
37 | - * @return ViewInterface View that was found. |
|
38 | - */ |
|
39 | - public function find(array $criteria, EngineInterface $engine = null) |
|
40 | - { |
|
41 | - $uri = $criteria[0]; |
|
29 | + /** |
|
30 | + * Find a result based on a specific criteria. |
|
31 | + * |
|
32 | + * @since 0.1.0 |
|
33 | + * |
|
34 | + * @param array $criteria Criteria to search for. |
|
35 | + * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
36 | + * |
|
37 | + * @return ViewInterface View that was found. |
|
38 | + */ |
|
39 | + public function find(array $criteria, EngineInterface $engine = null) |
|
40 | + { |
|
41 | + $uri = $criteria[0]; |
|
42 | 42 | |
43 | - $this->initializeViews($uri, $engine); |
|
43 | + $this->initializeViews($uri, $engine); |
|
44 | 44 | |
45 | - foreach ($criteria as $entry) { |
|
46 | - foreach ($this->findables as $viewObject) { |
|
47 | - if ($viewObject->canHandle($entry)) { |
|
48 | - return $viewObject; |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
45 | + foreach ($criteria as $entry) { |
|
46 | + foreach ($this->findables as $viewObject) { |
|
47 | + if ($viewObject->canHandle($entry)) { |
|
48 | + return $viewObject; |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - return $this->getNullObject(); |
|
54 | - } |
|
53 | + return $this->getNullObject(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initialize the views that can be iterated. |
|
58 | - * |
|
59 | - * @since 0.1.0 |
|
60 | - * |
|
61 | - * @param string $uri URI to use for the view. |
|
62 | - * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
63 | - */ |
|
64 | - protected function initializeViews($uri, EngineInterface $engine = null) |
|
65 | - { |
|
66 | - foreach ($this->findables as &$view) { |
|
67 | - $view = $this->initializeView($view, $uri, $engine); |
|
68 | - } |
|
69 | - } |
|
56 | + /** |
|
57 | + * Initialize the views that can be iterated. |
|
58 | + * |
|
59 | + * @since 0.1.0 |
|
60 | + * |
|
61 | + * @param string $uri URI to use for the view. |
|
62 | + * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
63 | + */ |
|
64 | + protected function initializeViews($uri, EngineInterface $engine = null) |
|
65 | + { |
|
66 | + foreach ($this->findables as &$view) { |
|
67 | + $view = $this->initializeView($view, $uri, $engine); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Initialize a single view by instantiating class name strings and calling closures. |
|
73 | - * |
|
74 | - * @since 0.1.0 |
|
75 | - * |
|
76 | - * @param mixed $view View to instantiate. |
|
77 | - * @param string $uri URI to use for the view. |
|
78 | - * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
79 | - * |
|
80 | - * @return ViewInterface Instantiated view. |
|
81 | - * @throws FailedToInstantiateViewException If the view could not be instantiated. |
|
82 | - */ |
|
83 | - protected function initializeView($view, $uri, EngineInterface $engine = null) |
|
84 | - { |
|
85 | - if (is_string($view)) { |
|
86 | - $view = new $view($uri, $engine); |
|
87 | - } |
|
71 | + /** |
|
72 | + * Initialize a single view by instantiating class name strings and calling closures. |
|
73 | + * |
|
74 | + * @since 0.1.0 |
|
75 | + * |
|
76 | + * @param mixed $view View to instantiate. |
|
77 | + * @param string $uri URI to use for the view. |
|
78 | + * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
79 | + * |
|
80 | + * @return ViewInterface Instantiated view. |
|
81 | + * @throws FailedToInstantiateViewException If the view could not be instantiated. |
|
82 | + */ |
|
83 | + protected function initializeView($view, $uri, EngineInterface $engine = null) |
|
84 | + { |
|
85 | + if (is_string($view)) { |
|
86 | + $view = new $view($uri, $engine); |
|
87 | + } |
|
88 | 88 | |
89 | - if (is_callable($view)) { |
|
90 | - $view = $view($uri, $engine); |
|
91 | - } |
|
89 | + if (is_callable($view)) { |
|
90 | + $view = $view($uri, $engine); |
|
91 | + } |
|
92 | 92 | |
93 | - if (! $view instanceof ViewInterface) { |
|
94 | - throw new FailedToInstantiateViewException( |
|
95 | - sprintf( |
|
96 | - _('Could not instantiate view "%s".'), |
|
97 | - serialize($view) |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
93 | + if (! $view instanceof ViewInterface) { |
|
94 | + throw new FailedToInstantiateViewException( |
|
95 | + sprintf( |
|
96 | + _('Could not instantiate view "%s".'), |
|
97 | + serialize($view) |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | |
102 | - return $view; |
|
103 | - } |
|
102 | + return $view; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Get the config key for the Findables definitions. |
|
107 | - * |
|
108 | - * @since 0.1.0 |
|
109 | - * |
|
110 | - * @return string Config key use to define the Findables. |
|
111 | - */ |
|
112 | - protected function getFindablesConfigKey() |
|
113 | - { |
|
114 | - return 'Views'; |
|
115 | - } |
|
105 | + /** |
|
106 | + * Get the config key for the Findables definitions. |
|
107 | + * |
|
108 | + * @since 0.1.0 |
|
109 | + * |
|
110 | + * @return string Config key use to define the Findables. |
|
111 | + */ |
|
112 | + protected function getFindablesConfigKey() |
|
113 | + { |
|
114 | + return 'Views'; |
|
115 | + } |
|
116 | 116 | } |
@@ -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,24 +24,24 @@ |
||
24 | 24 | abstract class AbstractEngine implements EngineInterface, Findable |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Check whether a given URI has a specific extension. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param string $uri URI to check the extension of. |
|
33 | - * @param string $extension Extension to check for. |
|
34 | - * |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - protected function hasExtension($uri, $extension) |
|
38 | - { |
|
39 | - $uriLength = mb_strlen($uri); |
|
40 | - $extensionLength = mb_strlen($extension); |
|
41 | - if ($extensionLength > $uriLength) { |
|
42 | - return false; |
|
43 | - } |
|
27 | + /** |
|
28 | + * Check whether a given URI has a specific extension. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param string $uri URI to check the extension of. |
|
33 | + * @param string $extension Extension to check for. |
|
34 | + * |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + protected function hasExtension($uri, $extension) |
|
38 | + { |
|
39 | + $uriLength = mb_strlen($uri); |
|
40 | + $extensionLength = mb_strlen($extension); |
|
41 | + if ($extensionLength > $uriLength) { |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | |
45 | - return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
46 | - } |
|
45 | + return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
46 | + } |
|
47 | 47 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | */ |
57 | 57 | public function render($uri, array $context = []) |
58 | 58 | { |
59 | - if (! is_readable($uri)) { |
|
59 | + if ( ! is_readable($uri)) { |
|
60 | 60 | throw new FailedToLoadViewException( |
61 | 61 | sprintf( |
62 | 62 | _('The View URI "%1$s" is not accessible or readable.'), |
@@ -25,73 +25,73 @@ |
||
25 | 25 | class PHPEngine extends AbstractEngine |
26 | 26 | { |
27 | 27 | |
28 | - const PHP_EXTENSION = '.php'; |
|
28 | + const PHP_EXTENSION = '.php'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Check whether the Findable can handle an individual criterion. |
|
32 | - * |
|
33 | - * @since 0.1.0 |
|
34 | - * |
|
35 | - * @param mixed $criterion Criterion to check. |
|
36 | - * |
|
37 | - * @return bool Whether the Findable can handle the criterion. |
|
38 | - */ |
|
39 | - public function canHandle($criterion) |
|
40 | - { |
|
41 | - return $this->hasExtension($criterion, static::PHP_EXTENSION) |
|
42 | - && is_readable($criterion); |
|
43 | - } |
|
30 | + /** |
|
31 | + * Check whether the Findable can handle an individual criterion. |
|
32 | + * |
|
33 | + * @since 0.1.0 |
|
34 | + * |
|
35 | + * @param mixed $criterion Criterion to check. |
|
36 | + * |
|
37 | + * @return bool Whether the Findable can handle the criterion. |
|
38 | + */ |
|
39 | + public function canHandle($criterion) |
|
40 | + { |
|
41 | + return $this->hasExtension($criterion, static::PHP_EXTENSION) |
|
42 | + && is_readable($criterion); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Render a given URI. |
|
47 | - * |
|
48 | - * @since 0.1.0 |
|
49 | - * |
|
50 | - * @param string $uri URI to render. |
|
51 | - * @param array $context Context in which to render. |
|
52 | - * |
|
53 | - * @return string Rendered HTML. |
|
54 | - * @throws FailedToLoadViewException If the View URI is not accessible or readable. |
|
55 | - * @throws FailedToLoadViewException If the View URI could not be loaded. |
|
56 | - */ |
|
57 | - public function render($uri, array $context = []) |
|
58 | - { |
|
59 | - if (! is_readable($uri)) { |
|
60 | - throw new FailedToLoadViewException( |
|
61 | - sprintf( |
|
62 | - _('The View URI "%1$s" is not accessible or readable.'), |
|
63 | - $uri |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
45 | + /** |
|
46 | + * Render a given URI. |
|
47 | + * |
|
48 | + * @since 0.1.0 |
|
49 | + * |
|
50 | + * @param string $uri URI to render. |
|
51 | + * @param array $context Context in which to render. |
|
52 | + * |
|
53 | + * @return string Rendered HTML. |
|
54 | + * @throws FailedToLoadViewException If the View URI is not accessible or readable. |
|
55 | + * @throws FailedToLoadViewException If the View URI could not be loaded. |
|
56 | + */ |
|
57 | + public function render($uri, array $context = []) |
|
58 | + { |
|
59 | + if (! is_readable($uri)) { |
|
60 | + throw new FailedToLoadViewException( |
|
61 | + sprintf( |
|
62 | + _('The View URI "%1$s" is not accessible or readable.'), |
|
63 | + $uri |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | |
68 | - extract($context, EXTR_SKIP); |
|
68 | + extract($context, EXTR_SKIP); |
|
69 | 69 | |
70 | - // Save current buffering level so we can backtrack in case of an error. |
|
71 | - // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
72 | - $bufferLevel = ob_get_level(); |
|
73 | - ob_start(); |
|
70 | + // Save current buffering level so we can backtrack in case of an error. |
|
71 | + // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
72 | + $bufferLevel = ob_get_level(); |
|
73 | + ob_start(); |
|
74 | 74 | |
75 | - try { |
|
76 | - include($uri); |
|
77 | - } catch (Exception $exception) { |
|
75 | + try { |
|
76 | + include($uri); |
|
77 | + } catch (Exception $exception) { |
|
78 | 78 | |
79 | - // Remove whatever levels were added up until now. |
|
80 | - while (ob_get_level() > $bufferLevel) { |
|
81 | - ob_end_clean(); |
|
82 | - } |
|
79 | + // Remove whatever levels were added up until now. |
|
80 | + while (ob_get_level() > $bufferLevel) { |
|
81 | + ob_end_clean(); |
|
82 | + } |
|
83 | 83 | |
84 | - throw new FailedToLoadViewException( |
|
85 | - sprintf( |
|
86 | - _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
87 | - $uri, |
|
88 | - $exception->getMessage() |
|
89 | - ), |
|
90 | - $exception->getCode(), |
|
91 | - $exception |
|
92 | - ); |
|
93 | - } |
|
84 | + throw new FailedToLoadViewException( |
|
85 | + sprintf( |
|
86 | + _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
87 | + $uri, |
|
88 | + $exception->getMessage() |
|
89 | + ), |
|
90 | + $exception->getCode(), |
|
91 | + $exception |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | - return ob_get_clean(); |
|
96 | - } |
|
95 | + return ob_get_clean(); |
|
96 | + } |
|
97 | 97 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | $engine = $engine(); |
86 | 86 | } |
87 | 87 | |
88 | - if (! $engine instanceof EngineInterface) { |
|
88 | + if ( ! $engine instanceof EngineInterface) { |
|
89 | 89 | throw new FailedToInstantiateEngineException( |
90 | 90 | sprintf( |
91 | 91 | _('Could not instantiate engine "%s".'), |
@@ -71,7 +71,7 @@ |
||
71 | 71 | * |
72 | 72 | * @since 0.1.0 |
73 | 73 | * |
74 | - * @param mixed $engine Engine to instantiate. |
|
74 | + * @param \BrightNucleus\View\Support\Findable $engine Engine to instantiate. |
|
75 | 75 | * |
76 | 76 | * @return EngineInterface Instantiated engine. |
77 | 77 | * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
@@ -25,84 +25,84 @@ |
||
25 | 25 | class EngineFinder extends AbstractFinder |
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 | - * |
|
35 | - * @return EngineInterface Result of the search. |
|
36 | - */ |
|
37 | - public function find(array $criteria) |
|
38 | - { |
|
39 | - $this->initializeEngines(); |
|
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 | + * |
|
35 | + * @return EngineInterface Result of the search. |
|
36 | + */ |
|
37 | + public function find(array $criteria) |
|
38 | + { |
|
39 | + $this->initializeEngines(); |
|
40 | 40 | |
41 | - foreach ($criteria as $entry) { |
|
42 | - foreach ($this->findables as $engine) { |
|
43 | - if ($engine->canHandle($entry)) { |
|
44 | - return $engine; |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
41 | + foreach ($criteria as $entry) { |
|
42 | + foreach ($this->findables as $engine) { |
|
43 | + if ($engine->canHandle($entry)) { |
|
44 | + return $engine; |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - return $this->getNullObject(); |
|
50 | - } |
|
49 | + return $this->getNullObject(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Initialize the engines that can be iterated. |
|
54 | - * |
|
55 | - * @since 0.1.0 |
|
56 | - * |
|
57 | - */ |
|
58 | - protected function initializeEngines() |
|
59 | - { |
|
60 | - foreach ($this->findables as &$engine) { |
|
61 | - $engine = $this->initializeEngine($engine); |
|
62 | - } |
|
63 | - } |
|
52 | + /** |
|
53 | + * Initialize the engines that can be iterated. |
|
54 | + * |
|
55 | + * @since 0.1.0 |
|
56 | + * |
|
57 | + */ |
|
58 | + protected function initializeEngines() |
|
59 | + { |
|
60 | + foreach ($this->findables as &$engine) { |
|
61 | + $engine = $this->initializeEngine($engine); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Initialize a single engine by instantiating class name strings and calling closures. |
|
67 | - * |
|
68 | - * @since 0.1.0 |
|
69 | - * |
|
70 | - * @param mixed $engine Engine to instantiate. |
|
71 | - * |
|
72 | - * @return EngineInterface Instantiated engine. |
|
73 | - * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
|
74 | - */ |
|
75 | - protected function initializeEngine($engine) |
|
76 | - { |
|
77 | - if (is_string($engine)) { |
|
78 | - $engine = new $engine(); |
|
79 | - } |
|
65 | + /** |
|
66 | + * Initialize a single engine by instantiating class name strings and calling closures. |
|
67 | + * |
|
68 | + * @since 0.1.0 |
|
69 | + * |
|
70 | + * @param mixed $engine Engine to instantiate. |
|
71 | + * |
|
72 | + * @return EngineInterface Instantiated engine. |
|
73 | + * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
|
74 | + */ |
|
75 | + protected function initializeEngine($engine) |
|
76 | + { |
|
77 | + if (is_string($engine)) { |
|
78 | + $engine = new $engine(); |
|
79 | + } |
|
80 | 80 | |
81 | - if (is_callable($engine)) { |
|
82 | - $engine = $engine(); |
|
83 | - } |
|
81 | + if (is_callable($engine)) { |
|
82 | + $engine = $engine(); |
|
83 | + } |
|
84 | 84 | |
85 | - if (! $engine instanceof EngineInterface) { |
|
86 | - throw new FailedToInstantiateEngineException( |
|
87 | - sprintf( |
|
88 | - _('Could not instantiate engine "%s".'), |
|
89 | - serialize($engine) |
|
90 | - ) |
|
91 | - ); |
|
92 | - } |
|
85 | + if (! $engine instanceof EngineInterface) { |
|
86 | + throw new FailedToInstantiateEngineException( |
|
87 | + sprintf( |
|
88 | + _('Could not instantiate engine "%s".'), |
|
89 | + serialize($engine) |
|
90 | + ) |
|
91 | + ); |
|
92 | + } |
|
93 | 93 | |
94 | - return $engine; |
|
95 | - } |
|
94 | + return $engine; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Get the config key for the Findables definitions. |
|
99 | - * |
|
100 | - * @since 0.1.0 |
|
101 | - * |
|
102 | - * @return string Config key use to define the Findables. |
|
103 | - */ |
|
104 | - protected function getFindablesConfigKey() |
|
105 | - { |
|
106 | - return 'Engines'; |
|
107 | - } |
|
97 | + /** |
|
98 | + * Get the config key for the Findables definitions. |
|
99 | + * |
|
100 | + * @since 0.1.0 |
|
101 | + * |
|
102 | + * @return string Config key use to define the Findables. |
|
103 | + */ |
|
104 | + protected function getFindablesConfigKey() |
|
105 | + { |
|
106 | + return 'Engines'; |
|
107 | + } |
|
108 | 108 | } |
@@ -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 | } |
@@ -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 |
|
42 | - */ |
|
43 | - protected $extensions; |
|
36 | + /** |
|
37 | + * Extensions that this location can accept. |
|
38 | + * |
|
39 | + * @since 0.1.0 |
|
40 | + * |
|
41 | + * @var array |
|
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|false 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|false 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 | } |
@@ -22,14 +22,14 @@ |
||
22 | 22 | interface LocationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Get an URI that matches the given criteria. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @param array $criteria Criteria to match. |
|
31 | - * |
|
32 | - * @return string|false URI that matches the criteria or false if none found. |
|
33 | - */ |
|
34 | - public function getURI(array $criteria); |
|
25 | + /** |
|
26 | + * Get an URI that matches the given criteria. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @param array $criteria Criteria to match. |
|
31 | + * |
|
32 | + * @return string|false URI that matches the criteria or false if none found. |
|
33 | + */ |
|
34 | + public function getURI(array $criteria); |
|
35 | 35 | } |