diff --git a/app/Config/View.php b/app/Config/View.php index a1c649a5c214..f674325ee74f 100644 --- a/app/Config/View.php +++ b/app/Config/View.php @@ -47,9 +47,9 @@ class View extends BaseView * have a chance to alter the generated output just prior to caching * the results. * - * All classes must implement CodeIgniter\View\ViewDecorator + * All classes must implement CodeIgniter\View\ViewDecoratorInterface * - * @var array + * @var class-string<\CodeIgniter\View\ViewDecoratorInterface>[] */ public $decorators = []; } diff --git a/system/Config/View.php b/system/Config/View.php index 2522a9727b03..fb3f2ec00c82 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -93,9 +93,9 @@ class View extends BaseConfig * have a chance to alter the generated output just prior to caching * the results. * - * All classes must implement CodeIgniter\View\ViewDecorator + * All classes must implement CodeIgniter\View\ViewDecoratorInterface * - * @var array + * @var class-string<\CodeIgniter\View\ViewDecoratorInterface>[] */ public $decorators = []; diff --git a/system/Language/en/View.php b/system/Language/en/View.php index 3aad53122a78..ac94be50fd82 100644 --- a/system/Language/en/View.php +++ b/system/Language/en/View.php @@ -17,5 +17,5 @@ 'noCellClass' => 'No view cell class provided.', 'invalidCellClass' => 'Unable to locate view cell class: {0}.', 'tagSyntaxError' => 'You have a syntax error in your Parser tags: {0}', - 'invalidDecoratorClass' => '{0} is not a valid ViewDecorator.', + 'invalidDecoratorClass' => '{0} is not a valid View Decorator.', ]; diff --git a/system/View/ViewDecoratorTrait.php b/system/View/ViewDecoratorTrait.php index 1bff8b06a750..23ace6e7c4a6 100644 --- a/system/View/ViewDecoratorTrait.php +++ b/system/View/ViewDecoratorTrait.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + namespace CodeIgniter\View; use CodeIgniter\View\Exceptions\ViewException; @@ -12,7 +21,7 @@ trait ViewDecoratorTrait * Runs the generated output through and declared * view decorators. */ - private function decorateOutput(string $html): string + protected function decorateOutput(string $html): string { $decorators = config('View')->decorators; diff --git a/tests/_support/View/WorldDecorator.php b/tests/_support/View/WorldDecorator.php index b305dbb38573..09f17a43ed44 100644 --- a/tests/_support/View/WorldDecorator.php +++ b/tests/_support/View/WorldDecorator.php @@ -23,8 +23,6 @@ class WorldDecorator implements ViewDecoratorInterface { public static function decorate(string $html): string { - $html = str_ireplace('World', 'Galaxy', $html); - - return $html; + return str_ireplace('World', 'Galaxy', $html); } } diff --git a/tests/system/View/DecoratorsTest.php b/tests/system/View/DecoratorsTest.php index 0a19965a142f..571005897099 100644 --- a/tests/system/View/DecoratorsTest.php +++ b/tests/system/View/DecoratorsTest.php @@ -38,7 +38,7 @@ protected function setUp(): void public function testNoDecoratorsDoesntAlter() { - $config = $this->config; + $config = $this->config; $config->decorators = []; Factories::injectMock('config', 'View', $config); @@ -55,7 +55,7 @@ public function testThrowsOnInvalidClass() $this->expectException(ViewException::class); $this->expectExceptionMessage(lang('View.invalidDecoratorClass', ['Tests\Support\View\BadDecorator'])); - $config = $this->config; + $config = $this->config; $config->decorators = [BadDecorator::class]; Factories::injectMock('config', 'View', $config); @@ -69,7 +69,7 @@ public function testThrowsOnInvalidClass() public function testDecoratorAltersOutput() { - $config = $this->config; + $config = $this->config; $config->decorators = [WorldDecorator::class]; Factories::injectMock('config', 'View', $config); @@ -83,7 +83,7 @@ public function testDecoratorAltersOutput() public function testParserNoDecoratorsDoesntAlter() { - $config = $this->config; + $config = $this->config; $config->decorators = []; Factories::injectMock('config', 'View', $config); @@ -95,7 +95,7 @@ public function testParserNoDecoratorsDoesntAlter() public function testParserDecoratorAltersOutput() { - $config = $this->config; + $config = $this->config; $config->decorators = [WorldDecorator::class]; Factories::injectMock('config', 'View', $config); diff --git a/user_guide_src/source/outgoing/view_decorators.rst b/user_guide_src/source/outgoing/view_decorators.rst index 0b0590035e8d..acf5c825072a 100644 --- a/user_guide_src/source/outgoing/view_decorators.rst +++ b/user_guide_src/source/outgoing/view_decorators.rst @@ -19,9 +19,9 @@ the resulting HTML. namespace App\Views\Decorators; - use CodeIgniter\Views\Interfaces\ViewDecorator; + use CodeIgniter\Views\ViewDecoratorInterface; - class MyDecorator implements ViewDecorator + class MyDecorator implements ViewDecoratorInterface { public static function decorate(string $html): string {