diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 35dd2102f4a..7a299094cce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,6 +50,8 @@ jobs: name: Setup Zephir Extensions run: | echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" +# echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> "$GITHUB_ENV" # Need to change the templates to use this + # PHP CodeSniffer inspection phpcs: @@ -180,6 +182,7 @@ jobs: $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } echo "::set-output name=extension-path::$PhalconExtPath" +# echo "extension-path=$PhalconExtPath" >> "$GITHUB_ENV" # This needs to be checked, used below somehow - name: Creates build artifact with Phalcon extension uses: ./.github/actions/pack-phalcon-ext @@ -388,6 +391,7 @@ jobs: id: get-version run: | echo ::set-output name=version::${GITHUB_REF#refs/tags/} +# echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV" # This needs to be checked - name: Download Phalcon build artifacts id: download diff --git a/CHANGELOG-5.0.md b/CHANGELOG-5.0.md index e7581e9cfc3..07797a7b6a2 100644 --- a/CHANGELOG-5.0.md +++ b/CHANGELOG-5.0.md @@ -6,10 +6,12 @@ - Changed `Phalcon\Mvc\Model::getMessages()` to also filter with an array of fields [#16265](https://github.com/phalcon/cphalcon/issues/16265) - Changed `Phalcon\DataMapper\Query\Select::columns()` to accept an array of columns (keys as aliases) instead of `func_get_args` [#16451](https://github.com/phalcon/cphalcon/issues/16451) +- Changed `Phalcon\Html\Helper\AbstractSeries::__invoke()` to no longer clear the internal store when called [#16441](https://github.com/phalcon/cphalcon/issues/16441) ### Added - Added the ability to define interpolator characters for the `Phalcon\Logger\Formatter\Line` [#16430](https://github.com/phalcon/cphalcon/issues/16430) +- Added `Phalcon\Html\Helper\AbstractSeries::reset()` to clear the internal store when needed [#16441](https://github.com/phalcon/cphalcon/issues/16441) ### Fixed diff --git a/phalcon/Assets/Manager.zep b/phalcon/Assets/Manager.zep index 939172b3785..4707bc5194d 100644 --- a/phalcon/Assets/Manager.zep +++ b/phalcon/Assets/Manager.zep @@ -1008,7 +1008,7 @@ class Manager extends AbstractInjectionAware string type, string name ) -> string { - var helper, params, tag; + var helper, output, params, tag; let params = parameters; @@ -1061,6 +1061,13 @@ class Manager extends AbstractInjectionAware helper->__invoke(""); // no indentation helper->add(tag, params); - return (string) helper; + let output = (string) helper; + + /** + * This is because the helper no longer resets the store automatically + */ + helper->reset(); + + return output; } } diff --git a/phalcon/Html/Helper/AbstractSeries.zep b/phalcon/Html/Helper/AbstractSeries.zep index f7f59b95e5d..f3208c5ee13 100644 --- a/phalcon/Html/Helper/AbstractSeries.zep +++ b/phalcon/Html/Helper/AbstractSeries.zep @@ -37,8 +37,7 @@ abstract class AbstractSeries extends AbstractHelper string delimiter = null ) -> { let this->delimiter = null === delimiter ? PHP_EOL : delimiter, - this->indent = indent, - this->store = []; + this->indent = indent; return this; } @@ -56,6 +55,16 @@ abstract class AbstractSeries extends AbstractHelper ); } + /** + * Resets the internal store. + */ + public function reset() -> + { + let this->store = []; + + return this; + } + /** * Returns the tag name. * diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php index 146a154a109..b5b5836bf6f 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php @@ -178,6 +178,7 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester $I->assertSame($expected, $actual); // Style executed in code + $this->tag->style()->reset(); $expected = '+' . PHP_EOL . '+' @@ -186,6 +187,7 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester $I->assertSame($expected, $actual); // Style after volt parsing + $this->tag->style()->reset(); $code = 'echo $this->tag->style("+")->add("/css/some.css")->add("/css/other.css");'; $expected = '+' . PHP_EOL @@ -210,10 +212,12 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester . PHP_EOL . '+' . PHP_EOL; + $this->tag->script()->reset(); $actual = (string) $this->tag->script('+')->add('/js/some.js')->add('/js/other.js'); $I->assertSame($expected, $actual); // Script after volt parsing + $this->tag->script()->reset(); $code = 'echo $this->tag->script("+")->add("/js/some.js")->add("/js/other.js");'; $expected = '+' . PHP_EOL diff --git a/tests/unit/Html/Helper/Link/UnderscoreInvokeCest.php b/tests/unit/Html/Helper/Link/UnderscoreInvokeCest.php index 9ed41ac92a8..44dcafeabeb 100644 --- a/tests/unit/Html/Helper/Link/UnderscoreInvokeCest.php +++ b/tests/unit/Html/Helper/Link/UnderscoreInvokeCest.php @@ -60,6 +60,58 @@ public function htmlHelperLinkUnderscoreInvoke(UnitTester $I, Example $example) $I->assertSame($expected, $actual); } + /** + * Tests Phalcon\Html\Helper\Link :: __invoke() - reset + * + * @param UnitTester $I + * + * @author Phalcon Team + * @since 2023-10-24 + */ + public function htmlHelperLinkUnderscoreInvokeReset(UnitTester $I) + { + $I->wantToTest('Html\Helper\Link - __invoke() - reset'); + + $escaper = new Escaper(); + $helper = new Link($escaper); + + $helper + ->add( + 'https://phalcon.io/page/1', + ['rel' => 'prev'] + ) + ; + + $expected = " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + + $helper + ->add( + 'https://phalcon.io/page/2', + ['rel' => 'next'] + ) + ; + + $expected = " " . PHP_EOL + . " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + + $helper->reset(); + + $helper + ->add( + 'https://phalcon.io/page/2', + ['rel' => 'next'] + ) + ; + + $expected = " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + } + /** * @return array */ diff --git a/tests/unit/Html/Helper/Meta/UnderscoreInvokeCest.php b/tests/unit/Html/Helper/Meta/UnderscoreInvokeCest.php index 7b60772aa75..8fe1844e1e0 100644 --- a/tests/unit/Html/Helper/Meta/UnderscoreInvokeCest.php +++ b/tests/unit/Html/Helper/Meta/UnderscoreInvokeCest.php @@ -71,6 +71,40 @@ public function htmlHelperMetaUnderscoreInvoke(UnitTester $I, Example $example) $I->assertSame($expected, $actual); } + /** + * Tests Phalcon\Html\Helper\Meta :: __invoke() - reset + * + * @param UnitTester $I + * + * @throws Exception + * + * @author Phalcon Team + * @since 2023-10-24 + */ + public function htmlHelperMetaUnderscoreInvokeReset(UnitTester $I) + { + $I->wantToTest('Html\Helper\Meta - __invoke() - reset'); + + $escaper = new Escaper(); + $helper = new Meta($escaper); + $helper + ->add(['charset' => 'utf-8']) + ->addName('generator', 'Phalcon') + ; + + $expected = " " . PHP_EOL + . " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + + $helper->reset(); + + $helper->addName('generator', 'Phalcon Team'); + $expected = " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + } + /** * @return array */ diff --git a/tests/unit/Html/Helper/Style/UnderscoreInvokeCest.php b/tests/unit/Html/Helper/Style/UnderscoreInvokeCest.php index 6c261fb67eb..c19ab5e95e5 100644 --- a/tests/unit/Html/Helper/Style/UnderscoreInvokeCest.php +++ b/tests/unit/Html/Helper/Style/UnderscoreInvokeCest.php @@ -73,6 +73,48 @@ public function htmlHelperStyleUnderscoreInvoke(UnitTester $I, Example $example) $I->assertSame($expected, $actual); } + /** + * Tests Phalcon\Html\Helper\Style :: __invoke() - reset + * + * @param UnitTester $I + * + * @throws Exception + * + * @author Phalcon Team + * @since 2023-10-24 + */ + public function htmlHelperStyleUnderscoreInvokeReset(UnitTester $I) + { + $I->wantToTest('Html\Helper\Style - __invoke() - reset'); + + $escaper = new Escaper(); + $helper = new Style($escaper); + $helper->add('custom.css'); + + $expected = " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + + $helper->add('print.css', ['media' => 'print']); + + $expected = " " . PHP_EOL + . " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + + $helper->reset(); + + $helper->add('print.css', ['media' => 'print']); + + $expected = " " . PHP_EOL; + $actual = (string)$helper; + $I->assertSame($expected, $actual); + } + /** * @return array */