@@ -24,24 +24,24 @@ |
||
24 | 24 | class ExtensionCollection extends ArrayCollection |
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 | - public static 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 | + public static 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 | } |
@@ -26,73 +26,73 @@ |
||
26 | 26 | class PHPEngine extends AbstractEngine |
27 | 27 | { |
28 | 28 | |
29 | - const PHP_EXTENSION = '.php'; |
|
29 | + const PHP_EXTENSION = '.php'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Check whether the Findable can handle an individual criterion. |
|
33 | - * |
|
34 | - * @since 0.1.0 |
|
35 | - * |
|
36 | - * @param mixed $criterion Criterion to check. |
|
37 | - * |
|
38 | - * @return bool Whether the Findable can handle the criterion. |
|
39 | - */ |
|
40 | - public function canHandle($criterion) |
|
41 | - { |
|
42 | - return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) |
|
43 | - && is_readable($criterion); |
|
44 | - } |
|
31 | + /** |
|
32 | + * Check whether the Findable can handle an individual criterion. |
|
33 | + * |
|
34 | + * @since 0.1.0 |
|
35 | + * |
|
36 | + * @param mixed $criterion Criterion to check. |
|
37 | + * |
|
38 | + * @return bool Whether the Findable can handle the criterion. |
|
39 | + */ |
|
40 | + public function canHandle($criterion) |
|
41 | + { |
|
42 | + return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) |
|
43 | + && is_readable($criterion); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Render a given URI. |
|
48 | - * |
|
49 | - * @since 0.1.0 |
|
50 | - * |
|
51 | - * @param string $uri URI to render. |
|
52 | - * @param array $context Context in which to render. |
|
53 | - * |
|
54 | - * @return string Rendered HTML. |
|
55 | - * @throws FailedToLoadViewException If the View URI is not accessible or readable. |
|
56 | - * @throws FailedToLoadViewException If the View URI could not be loaded. |
|
57 | - */ |
|
58 | - public function render($uri, array $context = []) |
|
59 | - { |
|
60 | - if (! is_readable($uri)) { |
|
61 | - throw new FailedToLoadViewException( |
|
62 | - sprintf( |
|
63 | - _('The View URI "%1$s" is not accessible or readable.'), |
|
64 | - $uri |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
46 | + /** |
|
47 | + * Render a given URI. |
|
48 | + * |
|
49 | + * @since 0.1.0 |
|
50 | + * |
|
51 | + * @param string $uri URI to render. |
|
52 | + * @param array $context Context in which to render. |
|
53 | + * |
|
54 | + * @return string Rendered HTML. |
|
55 | + * @throws FailedToLoadViewException If the View URI is not accessible or readable. |
|
56 | + * @throws FailedToLoadViewException If the View URI could not be loaded. |
|
57 | + */ |
|
58 | + public function render($uri, array $context = []) |
|
59 | + { |
|
60 | + if (! is_readable($uri)) { |
|
61 | + throw new FailedToLoadViewException( |
|
62 | + sprintf( |
|
63 | + _('The View URI "%1$s" is not accessible or readable.'), |
|
64 | + $uri |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - extract($context, EXTR_SKIP); |
|
69 | + extract($context, EXTR_SKIP); |
|
70 | 70 | |
71 | - // Save current buffering level so we can backtrack in case of an error. |
|
72 | - // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
73 | - $bufferLevel = ob_get_level(); |
|
74 | - ob_start(); |
|
71 | + // Save current buffering level so we can backtrack in case of an error. |
|
72 | + // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
73 | + $bufferLevel = ob_get_level(); |
|
74 | + ob_start(); |
|
75 | 75 | |
76 | - try { |
|
77 | - include($uri); |
|
78 | - } catch (Exception $exception) { |
|
76 | + try { |
|
77 | + include($uri); |
|
78 | + } catch (Exception $exception) { |
|
79 | 79 | |
80 | - // Remove whatever levels were added up until now. |
|
81 | - while (ob_get_level() > $bufferLevel) { |
|
82 | - ob_end_clean(); |
|
83 | - } |
|
80 | + // Remove whatever levels were added up until now. |
|
81 | + while (ob_get_level() > $bufferLevel) { |
|
82 | + ob_end_clean(); |
|
83 | + } |
|
84 | 84 | |
85 | - throw new FailedToLoadViewException( |
|
86 | - sprintf( |
|
87 | - _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
88 | - $uri, |
|
89 | - $exception->getMessage() |
|
90 | - ), |
|
91 | - $exception->getCode(), |
|
92 | - $exception |
|
93 | - ); |
|
94 | - } |
|
85 | + throw new FailedToLoadViewException( |
|
86 | + sprintf( |
|
87 | + _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
88 | + $uri, |
|
89 | + $exception->getMessage() |
|
90 | + ), |
|
91 | + $exception->getCode(), |
|
92 | + $exception |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | - return ob_get_clean(); |
|
97 | - } |
|
96 | + return ob_get_clean(); |
|
97 | + } |
|
98 | 98 | } |