@@ -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 | } |
@@ -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 | } |
@@ -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 engine can render a given URI. |
|
32 | - * |
|
33 | - * @since 0.1.0 |
|
34 | - * |
|
35 | - * @param string $uri URI that wants to be rendered. |
|
36 | - * |
|
37 | - * @return bool Whether the engine can render the given URI. |
|
38 | - */ |
|
39 | - public function canRender($uri) |
|
40 | - { |
|
41 | - return $this->hasExtension($uri, static::PHP_EXTENSION) |
|
42 | - && is_readable($uri); |
|
43 | - } |
|
30 | + /** |
|
31 | + * Check whether the engine can render a given URI. |
|
32 | + * |
|
33 | + * @since 0.1.0 |
|
34 | + * |
|
35 | + * @param string $uri URI that wants to be rendered. |
|
36 | + * |
|
37 | + * @return bool Whether the engine can render the given URI. |
|
38 | + */ |
|
39 | + public function canRender($uri) |
|
40 | + { |
|
41 | + return $this->hasExtension($uri, static::PHP_EXTENSION) |
|
42 | + && is_readable($uri); |
|
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 | } |
@@ -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.'), |
@@ -22,26 +22,26 @@ |
||
22 | 22 | interface EngineInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Check whether the engine can render a given URI. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @param string $uri URI that wants to be rendered. |
|
31 | - * |
|
32 | - * @return bool Whether the engine can render the given URI. |
|
33 | - */ |
|
34 | - public function canRender($uri); |
|
25 | + /** |
|
26 | + * Check whether the engine can render a given URI. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @param string $uri URI that wants to be rendered. |
|
31 | + * |
|
32 | + * @return bool Whether the engine can render the given URI. |
|
33 | + */ |
|
34 | + public function canRender($uri); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Render a given URI. |
|
38 | - * |
|
39 | - * @since 0.1.0 |
|
40 | - * |
|
41 | - * @param string $uri URI to render. |
|
42 | - * @param array $context Context in which to render. |
|
43 | - * |
|
44 | - * @return string Rendered HTML. |
|
45 | - */ |
|
46 | - public function render($uri, array $context = []); |
|
36 | + /** |
|
37 | + * Render a given URI. |
|
38 | + * |
|
39 | + * @since 0.1.0 |
|
40 | + * |
|
41 | + * @param string $uri URI to render. |
|
42 | + * @param array $context Context in which to render. |
|
43 | + * |
|
44 | + * @return string Rendered HTML. |
|
45 | + */ |
|
46 | + public function render($uri, array $context = []); |
|
47 | 47 | } |
@@ -25,87 +25,87 @@ |
||
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 mixed 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 mixed Result of the search. |
|
36 | + */ |
|
37 | + public function find(array $criteria) |
|
38 | + { |
|
39 | + $this->initializeEngines(); |
|
40 | 40 | |
41 | - foreach ($criteria as $entry) { |
|
42 | - /** @var EngineInterface $engine */ |
|
43 | - foreach ($this->findables as $engine) { |
|
44 | - if ($engine->canRender($entry)) { |
|
45 | - return $engine; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
41 | + foreach ($criteria as $entry) { |
|
42 | + /** @var EngineInterface $engine */ |
|
43 | + foreach ($this->findables as $engine) { |
|
44 | + if ($engine->canRender($entry)) { |
|
45 | + return $engine; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - return $this->nullObject; |
|
51 | - } |
|
50 | + return $this->nullObject; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Initialize the engines that can be iterated. |
|
55 | - * |
|
56 | - * @since 0.1.0 |
|
57 | - * |
|
58 | - */ |
|
59 | - protected function initializeEngines() |
|
60 | - { |
|
61 | - foreach ($this->findables as &$engine) { |
|
62 | - $engine = $this->initializeEngine($engine); |
|
63 | - } |
|
53 | + /** |
|
54 | + * Initialize the engines that can be iterated. |
|
55 | + * |
|
56 | + * @since 0.1.0 |
|
57 | + * |
|
58 | + */ |
|
59 | + protected function initializeEngines() |
|
60 | + { |
|
61 | + foreach ($this->findables as &$engine) { |
|
62 | + $engine = $this->initializeEngine($engine); |
|
63 | + } |
|
64 | 64 | |
65 | - $this->nullObject = $this->initializeEngine($this->nullObject); |
|
66 | - } |
|
65 | + $this->nullObject = $this->initializeEngine($this->nullObject); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Initialize a single engine by instantiating class name strings and calling closures. |
|
70 | - * |
|
71 | - * @since 0.1.0 |
|
72 | - * |
|
73 | - * @param mixed $engine Engine to instantiate. |
|
74 | - * |
|
75 | - * @return EngineInterface Instantiated engine. |
|
76 | - * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
|
77 | - */ |
|
78 | - protected function initializeEngine($engine) |
|
79 | - { |
|
80 | - if (is_string($engine)) { |
|
81 | - $engine = new $engine(); |
|
82 | - } |
|
68 | + /** |
|
69 | + * Initialize a single engine by instantiating class name strings and calling closures. |
|
70 | + * |
|
71 | + * @since 0.1.0 |
|
72 | + * |
|
73 | + * @param mixed $engine Engine to instantiate. |
|
74 | + * |
|
75 | + * @return EngineInterface Instantiated engine. |
|
76 | + * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
|
77 | + */ |
|
78 | + protected function initializeEngine($engine) |
|
79 | + { |
|
80 | + if (is_string($engine)) { |
|
81 | + $engine = new $engine(); |
|
82 | + } |
|
83 | 83 | |
84 | - if (is_callable($engine)) { |
|
85 | - $engine = $engine(); |
|
86 | - } |
|
84 | + if (is_callable($engine)) { |
|
85 | + $engine = $engine(); |
|
86 | + } |
|
87 | 87 | |
88 | - if (! $engine instanceof EngineInterface) { |
|
89 | - throw new FailedToInstantiateEngineException( |
|
90 | - sprintf( |
|
91 | - _('Could not instantiate engine "%s".'), |
|
92 | - serialize($engine) |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
88 | + if (! $engine instanceof EngineInterface) { |
|
89 | + throw new FailedToInstantiateEngineException( |
|
90 | + sprintf( |
|
91 | + _('Could not instantiate engine "%s".'), |
|
92 | + serialize($engine) |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | 96 | |
97 | - return $engine; |
|
98 | - } |
|
97 | + return $engine; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Get the config key for the Findables definitions. |
|
102 | - * |
|
103 | - * @since 0.1.0 |
|
104 | - * |
|
105 | - * @return string Config key use to define the Findables. |
|
106 | - */ |
|
107 | - protected function getFindablesConfigKey() |
|
108 | - { |
|
109 | - return 'Engines'; |
|
110 | - } |
|
100 | + /** |
|
101 | + * Get the config key for the Findables definitions. |
|
102 | + * |
|
103 | + * @since 0.1.0 |
|
104 | + * |
|
105 | + * @return string Config key use to define the Findables. |
|
106 | + */ |
|
107 | + protected function getFindablesConfigKey() |
|
108 | + { |
|
109 | + return 'Engines'; |
|
110 | + } |
|
111 | 111 | } |
@@ -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".'), |
@@ -24,32 +24,32 @@ |
||
24 | 24 | class NullEngine implements EngineInterface, NullObject |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Check whether the engine can render a given URI. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param string $uri URI that wants to be rendered. |
|
33 | - * |
|
34 | - * @return bool Whether the engine can render the given URI. |
|
35 | - */ |
|
36 | - public function canRender($uri) |
|
37 | - { |
|
38 | - return true; |
|
39 | - } |
|
27 | + /** |
|
28 | + * Check whether the engine can render a given URI. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param string $uri URI that wants to be rendered. |
|
33 | + * |
|
34 | + * @return bool Whether the engine can render the given URI. |
|
35 | + */ |
|
36 | + public function canRender($uri) |
|
37 | + { |
|
38 | + return true; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Render a given URI. |
|
43 | - * |
|
44 | - * @since 0.1.0 |
|
45 | - * |
|
46 | - * @param string $uri URI to render. |
|
47 | - * @param array $context Context in which to render. |
|
48 | - * |
|
49 | - * @return string Rendered HTML. |
|
50 | - */ |
|
51 | - public function render($uri, array $context = []) |
|
52 | - { |
|
53 | - return ''; |
|
54 | - } |
|
41 | + /** |
|
42 | + * Render a given URI. |
|
43 | + * |
|
44 | + * @since 0.1.0 |
|
45 | + * |
|
46 | + * @param string $uri URI to render. |
|
47 | + * @param array $context Context in which to render. |
|
48 | + * |
|
49 | + * @return string Rendered HTML. |
|
50 | + */ |
|
51 | + public function render($uri, array $context = []) |
|
52 | + { |
|
53 | + return ''; |
|
54 | + } |
|
55 | 55 | } |
@@ -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 | } |