@@ -42,7 +42,7 @@ |
||
| 42 | 42 | private $data = array(); |
| 43 | 43 | |
| 44 | 44 | /** @param array<string, mixed> $data */ |
| 45 | - public function __construct( string $template, array $data = array() ) { |
|
| 45 | + public function __construct(string $template, array $data = array()) { |
|
| 46 | 46 | $this->template = $template; |
| 47 | 47 | $this->data = $data; |
| 48 | 48 | } |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @param Renderable $engine |
| 63 | 63 | */ |
| 64 | - public function __construct( Renderable $engine, Component_Compiler $component_compiler ) { |
|
| 64 | + public function __construct(Renderable $engine, Component_Compiler $component_compiler) { |
|
| 65 | 65 | $this->engine = $engine; |
| 66 | 66 | $this->component_compiler = $component_compiler; |
| 67 | 67 | |
| 68 | 68 | // Populate engine with compiler. |
| 69 | - $this->engine->set_component_compiler( $component_compiler ); |
|
| 69 | + $this->engine->set_component_compiler($component_compiler); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param bool $print Print or Return the HTML |
| 78 | 78 | * @return string|void |
| 79 | 79 | */ |
| 80 | - public function render( string $view, iterable $view_data = array(), bool $print = self::PRINT_VIEW ) { |
|
| 81 | - return $this->engine->render( $view, $view_data, $print ); |
|
| 80 | + public function render(string $view, iterable $view_data = array(), bool $print = self::PRINT_VIEW) { |
|
| 81 | + return $this->engine->render($view, $view_data, $print); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * @param bool $print Print or Return the HTML |
| 89 | 89 | * @return string|void |
| 90 | 90 | */ |
| 91 | - public function component( Component $component, bool $print = self::PRINT_VIEW ) { |
|
| 92 | - return $this->engine->component( $component, $print ); |
|
| 91 | + public function component(Component $component, bool $print = self::PRINT_VIEW) { |
|
| 92 | + return $this->engine->component($component, $print); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @param bool $print Print or Return the HTML |
| 100 | 100 | * @return string|void |
| 101 | 101 | */ |
| 102 | - public function view_model( View_Model $view_model, bool $print = self::PRINT_VIEW ) { |
|
| 103 | - return $this->engine->view_model( $view_model, $print ); |
|
| 102 | + public function view_model(View_Model $view_model, bool $print = self::PRINT_VIEW) { |
|
| 103 | + return $this->engine->view_model($view_model, $print); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param callable $to_buffer |
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | - public static function print_buffer( callable $to_buffer ): string { |
|
| 112 | + public static function print_buffer(callable $to_buffer): string { |
|
| 113 | 113 | ob_start(); |
| 114 | 114 | $to_buffer(); |
| 115 | 115 | $output = ob_get_contents(); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param DI_Container $di_container |
| 66 | 66 | * @return self |
| 67 | 67 | */ |
| 68 | - public function set_container( DI_Container $di_container ): self { |
|
| 68 | + public function set_container(DI_Container $di_container): self { |
|
| 69 | 69 | $this->di_container = $di_container; |
| 70 | 70 | return $this; |
| 71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param Hook_Loader $loader |
| 77 | 77 | * @return self |
| 78 | 78 | */ |
| 79 | - public function set_loader( Hook_Loader $loader ): self { |
|
| 79 | + public function set_loader(Hook_Loader $loader): self { |
|
| 80 | 80 | $this->loader = $loader; |
| 81 | 81 | return $this; |
| 82 | 82 | } |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * @param Registration_Middleware $middleware |
| 88 | 88 | * @return self |
| 89 | 89 | */ |
| 90 | - public function push_middleware( Registration_Middleware $middleware ): self { |
|
| 91 | - $this->middleware[ \get_class( $middleware ) ] = $middleware; |
|
| 90 | + public function push_middleware(Registration_Middleware $middleware): self { |
|
| 91 | + $this->middleware[\get_class($middleware)] = $middleware; |
|
| 92 | 92 | return $this; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param array<string> $class_list |
| 99 | 99 | * @return self |
| 100 | 100 | */ |
| 101 | - public function set_classes( array $class_list ): self { |
|
| 101 | + public function set_classes(array $class_list): self { |
|
| 102 | 102 | $this->class_list = $class_list; |
| 103 | 103 | return $this; |
| 104 | 104 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param string $class |
| 110 | 110 | * @return self |
| 111 | 111 | */ |
| 112 | - public function push_class( string $class ): self { |
|
| 112 | + public function push_class(string $class): self { |
|
| 113 | 113 | $this->class_list[] = $class; |
| 114 | 114 | return $this; |
| 115 | 115 | } |
@@ -122,32 +122,32 @@ discard block |
||
| 122 | 122 | public function process(): void { |
| 123 | 123 | |
| 124 | 124 | // Filter all classes, before processing. |
| 125 | - $class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list ); |
|
| 125 | + $class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list); |
|
| 126 | 126 | |
| 127 | - foreach ( $this->middleware as $middleware ) { |
|
| 127 | + foreach ($this->middleware as $middleware) { |
|
| 128 | 128 | |
| 129 | 129 | // Set the container if requested. |
| 130 | - if ( is_object( $middleware ) && \method_exists( $middleware, 'set_di_container' ) ) { |
|
| 131 | - $middleware->set_di_container( $this->di_container ); |
|
| 130 | + if (is_object($middleware) && \method_exists($middleware, 'set_di_container')) { |
|
| 131 | + $middleware->set_di_container($this->di_container); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Set the hook loader if requested. |
| 135 | - if ( is_object( $middleware ) && \method_exists( $middleware, 'set_hook_loader' ) && ! is_null( $this->loader ) ) { |
|
| 136 | - $middleware->set_hook_loader( $this->loader ); |
|
| 135 | + if (is_object($middleware) && \method_exists($middleware, 'set_hook_loader') && ! is_null($this->loader)) { |
|
| 136 | + $middleware->set_hook_loader($this->loader); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Run middleware setup |
| 140 | 140 | $middleware->setup(); |
| 141 | 141 | |
| 142 | 142 | // Pass each class to the middleware. |
| 143 | - foreach ( $class_list as $class ) { |
|
| 143 | + foreach ($class_list as $class) { |
|
| 144 | 144 | |
| 145 | 145 | // Construct class using container, |
| 146 | - $class_instance = $this->di_container->create( $class ); |
|
| 146 | + $class_instance = $this->di_container->create($class); |
|
| 147 | 147 | |
| 148 | 148 | // if valid object process via current middleware |
| 149 | - if ( is_object( $class_instance ) ) { |
|
| 150 | - $middleware->process( $class_instance ); |
|
| 149 | + if (is_object($class_instance)) { |
|
| 150 | + $middleware->process($class_instance); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | private $component_aliases = array(); |
| 51 | 51 | |
| 52 | 52 | /** @param array<string, string> $component_aliases */ |
| 53 | - public function __construct( string $component_base_path = '', array $component_aliases = array() ) { |
|
| 53 | + public function __construct(string $component_base_path = '', array $component_aliases = array()) { |
|
| 54 | 54 | $this->component_base_path = $component_base_path; |
| 55 | - $this->component_aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $component_aliases ); |
|
| 55 | + $this->component_aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $component_aliases); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param Component $component |
| 62 | 62 | * @return View_Model |
| 63 | 63 | */ |
| 64 | - public function compile( Component $component ): View_Model { |
|
| 65 | - return new View_Model( $this->get_component_path( $component ), $component->get_variables() ); |
|
| 64 | + public function compile(Component $component): View_Model { |
|
| 65 | + return new View_Model($this->get_component_path($component), $component->get_variables()); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -71,34 +71,34 @@ discard block |
||
| 71 | 71 | * @param Component $component |
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | - private function get_component_path( Component $component ): string { |
|
| 74 | + private function get_component_path(Component $component): string { |
|
| 75 | 75 | |
| 76 | 76 | // Check aliases. |
| 77 | - $aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $this->component_aliases ); |
|
| 77 | + $aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $this->component_aliases); |
|
| 78 | 78 | |
| 79 | - if ( isset( $aliases[ get_class( $component ) ] ) ) { |
|
| 80 | - return esc_attr( $aliases[ get_class( $component ) ] ); |
|
| 79 | + if (isset($aliases[get_class($component)])) { |
|
| 80 | + return esc_attr($aliases[get_class($component)]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $from_annotation = $this->get_annotation( 'view', $component ); |
|
| 83 | + $from_annotation = $this->get_annotation('view', $component); |
|
| 84 | 84 | // If it does have a path defined, use that. |
| 85 | - if ( ! empty( $from_annotation ) ) { |
|
| 86 | - return \trailingslashit( $this->component_base_path ) . $from_annotation; |
|
| 85 | + if ( ! empty($from_annotation)) { |
|
| 86 | + return \trailingslashit($this->component_base_path) . $from_annotation; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // If the component has a defined path |
| 90 | - if ( $component->template() ) { |
|
| 91 | - return \trailingslashit( $this->component_base_path ) . $component->template(); |
|
| 90 | + if ($component->template()) { |
|
| 91 | + return \trailingslashit($this->component_base_path) . $component->template(); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // Get path based on class name. |
| 95 | - $reflect = new \ReflectionClass( $component ); |
|
| 95 | + $reflect = new \ReflectionClass($component); |
|
| 96 | 96 | $short_name = $reflect->getShortName(); |
| 97 | 97 | // Add space between capitals, make lowercase and replace underscores with dashes. |
| 98 | - $short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $short_name ) ?? '' ); |
|
| 99 | - $short_name = str_replace( '_', '-', $short_name ); |
|
| 98 | + $short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $short_name) ?? ''); |
|
| 99 | + $short_name = str_replace('_', '-', $short_name); |
|
| 100 | 100 | |
| 101 | - return \trailingslashit( $this->component_base_path ) . $short_name; |
|
| 101 | + return \trailingslashit($this->component_base_path) . $short_name; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | * @param Component $component |
| 109 | 109 | * @return string|null |
| 110 | 110 | */ |
| 111 | - private function get_annotation( string $annotation, Component $component ): ?string { |
|
| 112 | - $reflect = new \ReflectionClass( $component ); |
|
| 111 | + private function get_annotation(string $annotation, Component $component): ?string { |
|
| 112 | + $reflect = new \ReflectionClass($component); |
|
| 113 | 113 | $comment = $reflect->getDocComment(); |
| 114 | 114 | |
| 115 | 115 | // if no comment, return null. |
| 116 | - if ( empty( $comment ) ) { |
|
| 116 | + if (empty($comment)) { |
|
| 117 | 117 | return null; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // If comment contains the annotation, return the value. |
| 121 | - return strpos( $comment, "@{$annotation}" ) !== false |
|
| 122 | - ? $this->extract_annotation_value( $comment, $annotation ) |
|
| 121 | + return strpos($comment, "@{$annotation}") !== false |
|
| 122 | + ? $this->extract_annotation_value($comment, $annotation) |
|
| 123 | 123 | : null; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | * @param string $annotation |
| 131 | 131 | * @return string|null |
| 132 | 132 | */ |
| 133 | - private function extract_annotation_value( string $comment, string $annotation ): ?string { |
|
| 133 | + private function extract_annotation_value(string $comment, string $annotation): ?string { |
|
| 134 | 134 | $pattern = "/@{$annotation}\s+(.*)/"; |
| 135 | - preg_match( $pattern, $comment, $matches ); |
|
| 135 | + preg_match($pattern, $comment, $matches); |
|
| 136 | 136 | return $matches[1] ?? null; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @param string $base_view_path |
| 53 | 53 | */ |
| 54 | - public function __construct( string $base_view_path ) { |
|
| 55 | - $this->base_view_path = $this->verify_view_path( $base_view_path ); |
|
| 54 | + public function __construct(string $base_view_path) { |
|
| 55 | + $this->base_view_path = $this->verify_view_path($base_view_path); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param Component_Compiler $compiler |
| 62 | 62 | * @return void |
| 63 | 63 | */ |
| 64 | - public function set_component_compiler( Component_Compiler $compiler ): void { |
|
| 64 | + public function set_component_compiler(Component_Compiler $compiler): void { |
|
| 65 | 65 | $this->component_compiler = $compiler; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | * @param bool $print |
| 74 | 74 | * @return string|void |
| 75 | 75 | */ |
| 76 | - public function render( string $view, iterable $data, bool $print = true ) { |
|
| 77 | - $view = $this->resolve_file_path( $view ); |
|
| 78 | - if ( $print ) { |
|
| 79 | - print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 76 | + public function render(string $view, iterable $data, bool $print = true) { |
|
| 77 | + $view = $this->resolve_file_path($view); |
|
| 78 | + if ($print) { |
|
| 79 | + print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 80 | 80 | } else { |
| 81 | - return $this->render_buffer( $view, $data ); |
|
| 81 | + return $this->render_buffer($view, $data); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -88,20 +88,20 @@ discard block |
||
| 88 | 88 | * @param Component $component |
| 89 | 89 | * @return string|void |
| 90 | 90 | */ |
| 91 | - public function component( Component $component, bool $print = true ) { |
|
| 91 | + public function component(Component $component, bool $print = true) { |
|
| 92 | 92 | |
| 93 | 93 | // Throw exception of no compiler passed. |
| 94 | - if ( ! is_a( $this->component_compiler, Component_Compiler::class ) ) { |
|
| 95 | - throw new Exception( 'No component compiler passed to PHP_Engine' ); |
|
| 94 | + if ( ! is_a($this->component_compiler, Component_Compiler::class)) { |
|
| 95 | + throw new Exception('No component compiler passed to PHP_Engine'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Compile the component. |
| 99 | - $compiled = $this->component_compiler->compile( $component ); |
|
| 100 | - $view = sprintf( '%s%s.php', \DIRECTORY_SEPARATOR, $this->clean_filename( $compiled->template() ) ); |
|
| 101 | - if ( $print ) { |
|
| 102 | - print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 99 | + $compiled = $this->component_compiler->compile($component); |
|
| 100 | + $view = sprintf('%s%s.php', \DIRECTORY_SEPARATOR, $this->clean_filename($compiled->template())); |
|
| 101 | + if ($print) { |
|
| 102 | + print($this->render_buffer($view, $compiled->data())); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 103 | 103 | } else { |
| 104 | - return $this->render_buffer( $view, $compiled->data() ); |
|
| 104 | + return $this->render_buffer($view, $compiled->data()); |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param View_Model $view_model |
| 113 | 113 | * @return string|void |
| 114 | 114 | */ |
| 115 | - public function view_model( View_Model $view_model, bool $print = true ) { |
|
| 116 | - return $this->render( $view_model->template(), $view_model->data(), $print ); |
|
| 115 | + public function view_model(View_Model $view_model, bool $print = true) { |
|
| 116 | + return $this->render($view_model->template(), $view_model->data(), $print); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | * @param bool $print |
| 125 | 125 | * @return string|void |
| 126 | 126 | */ |
| 127 | - public function partial( string $view, iterable $data = array(), bool $print = true ) { |
|
| 128 | - if ( $print ) { |
|
| 129 | - $this->render( $view, $data, $print ); |
|
| 127 | + public function partial(string $view, iterable $data = array(), bool $print = true) { |
|
| 128 | + if ($print) { |
|
| 129 | + $this->render($view, $data, $print); |
|
| 130 | 130 | } else { |
| 131 | - return $this->render( $view, $data, $print ); |
|
| 131 | + return $this->render($view, $data, $print); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -140,23 +140,23 @@ discard block |
||
| 140 | 140 | * @return string |
| 141 | 141 | * @throws Exception |
| 142 | 142 | */ |
| 143 | - protected function render_buffer( string $view, iterable $__data ): string { |
|
| 143 | + protected function render_buffer(string $view, iterable $__data): string { |
|
| 144 | 144 | |
| 145 | - if ( ! file_exists( $view ) ) { |
|
| 146 | - throw new Exception( "{$view} doesn't exist" ); |
|
| 145 | + if ( ! file_exists($view)) { |
|
| 146 | + throw new Exception("{$view} doesn't exist"); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $output = ''; |
| 150 | 150 | ob_start(); |
| 151 | 151 | |
| 152 | 152 | // Set all the data values a parameters. |
| 153 | - foreach ( $__data as $__key => $__value ) { |
|
| 154 | - if ( is_string( $__key ) ) { |
|
| 155 | - ${\wp_strip_all_tags( $__key )} = $__value; |
|
| 153 | + foreach ($__data as $__key => $__value) { |
|
| 154 | + if (is_string($__key)) { |
|
| 155 | + ${\wp_strip_all_tags($__key)} = $__value; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Unset the key and value. |
| 159 | - unset( $__key, $__value, $__data ); |
|
| 159 | + unset($__key, $__value, $__data); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | include $view; |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | * @param string $file |
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | - protected function clean_filename( string $file ): string { |
|
| 175 | - $file = ltrim( $file, '/' ); |
|
| 176 | - return substr( $file, -4 ) === '.php' |
|
| 177 | - ? substr( $file, 0, -4 ) |
|
| 174 | + protected function clean_filename(string $file): string { |
|
| 175 | + $file = ltrim($file, '/'); |
|
| 176 | + return substr($file, -4) === '.php' |
|
| 177 | + ? substr($file, 0, -4) |
|
| 178 | 178 | : $file; |
| 179 | 179 | |
| 180 | 180 | } |
@@ -185,12 +185,12 @@ discard block |
||
| 185 | 185 | * @param string $filename |
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | - protected function resolve_file_path( string $filename ): string { |
|
| 189 | - $filename = $this->maybe_resolve_dot_notation( $filename ); |
|
| 188 | + protected function resolve_file_path(string $filename): string { |
|
| 189 | + $filename = $this->maybe_resolve_dot_notation($filename); |
|
| 190 | 190 | return sprintf( |
| 191 | 191 | '%s%s.php', |
| 192 | 192 | $this->base_view_path, |
| 193 | - $this->clean_filename( $filename ) |
|
| 193 | + $this->clean_filename($filename) |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | * @param string $filename |
| 201 | 201 | * @return string |
| 202 | 202 | */ |
| 203 | - protected function maybe_resolve_dot_notation( string $filename ): string { |
|
| 204 | - if ( $this->str_ends_with( '.php', $filename ) ) { |
|
| 205 | - $filename = substr( $filename, 0, -4 ); |
|
| 203 | + protected function maybe_resolve_dot_notation(string $filename): string { |
|
| 204 | + if ($this->str_ends_with('.php', $filename)) { |
|
| 205 | + $filename = substr($filename, 0, -4); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $parts = explode( '.', $filename ); |
|
| 209 | - $filename = implode( DIRECTORY_SEPARATOR, $parts ); |
|
| 208 | + $parts = explode('.', $filename); |
|
| 209 | + $filename = implode(DIRECTORY_SEPARATOR, $parts); |
|
| 210 | 210 | |
| 211 | 211 | return $filename; |
| 212 | 212 | } |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * @param string $haystack |
| 219 | 219 | * @return bool |
| 220 | 220 | */ |
| 221 | - protected function str_ends_with( string $needle, string $haystack ): bool { |
|
| 222 | - $needle_len = strlen( $needle ); |
|
| 223 | - return ( $needle_len === 0 || 0 === substr_compare( $haystack, $needle, - $needle_len ) ); |
|
| 221 | + protected function str_ends_with(string $needle, string $haystack): bool { |
|
| 222 | + $needle_len = strlen($needle); |
|
| 223 | + return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len)); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | * @return string |
| 232 | 232 | * @throws Exception |
| 233 | 233 | */ |
| 234 | - protected function verify_view_path( string $path ): string { |
|
| 234 | + protected function verify_view_path(string $path): string { |
|
| 235 | 235 | |
| 236 | - $path = rtrim( $path, '/' ) . '/'; |
|
| 236 | + $path = rtrim($path, '/') . '/'; |
|
| 237 | 237 | |
| 238 | - if ( ! \is_dir( $path ) ) { |
|
| 239 | - throw new Exception( "{$path} doesn't exist and cant be used as the base view path." ); |
|
| 238 | + if ( ! \is_dir($path)) { |
|
| 239 | + throw new Exception("{$path} doesn't exist and cant be used as the base view path."); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $path; |