From d334a07bbf356e84af7110541209283afe7457fa Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 10:06:25 -0500 Subject: [PATCH 01/12] added reset for the series --- phalcon/Html/Helper/AbstractSeries.zep | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/phalcon/Html/Helper/AbstractSeries.zep b/phalcon/Html/Helper/AbstractSeries.zep index f7f59b95e5d..0dd60ec1a13 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,14 @@ abstract class AbstractSeries extends AbstractHelper ); } + /** + * Resets the internal store. + */ + public function reset() -> void + { + let this->store = []; + } + /** * Returns the tag name. * From 4f7ae6e70138e0ce7c0106ac1f8b6f1fc7abeed3 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 10:06:30 -0500 Subject: [PATCH 02/12] added tests --- .../Html/Helper/Link/UnderscoreInvokeCest.php | 52 +++++++++++++++++++ .../Html/Helper/Meta/UnderscoreInvokeCest.php | 34 ++++++++++++ .../Helper/Style/UnderscoreInvokeCest.php | 42 +++++++++++++++ 3 files changed, 128 insertions(+) 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 */ From ae2a12700a5b2996a638f63421a2a681a51db111 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 10:37:39 -0500 Subject: [PATCH 03/12] corrected Asset manager (clearing internal store) --- phalcon/Assets/Manager.zep | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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; } } From eb19ea4e8f3c6f2bcebb425d3da2c38d3ba8494b Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 10:37:45 -0500 Subject: [PATCH 04/12] updated changelog --- CHANGELOG-5.0.md | 2 ++ 1 file changed, 2 insertions(+) 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 From fe919dba996b20f18dbb0a7354db8fe02428b783 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 11:59:35 -0500 Subject: [PATCH 05/12] reset now returns the object back --- phalcon/Html/Helper/AbstractSeries.zep | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phalcon/Html/Helper/AbstractSeries.zep b/phalcon/Html/Helper/AbstractSeries.zep index 0dd60ec1a13..f3208c5ee13 100644 --- a/phalcon/Html/Helper/AbstractSeries.zep +++ b/phalcon/Html/Helper/AbstractSeries.zep @@ -58,9 +58,11 @@ abstract class AbstractSeries extends AbstractHelper /** * Resets the internal store. */ - public function reset() -> void + public function reset() -> { let this->store = []; + + return this; } /** From 33a20d06d03671ef1377d004a7afc0ba35578253 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 11:59:41 -0500 Subject: [PATCH 06/12] test corrections --- .../Mvc/View/Engine/Volt/Compiler/CompileStringCest.php | 4 ++++ 1 file changed, 4 insertions(+) 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 From bb38ba18fb6f14244f021c874b75e24454364f32 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 12:10:53 -0500 Subject: [PATCH 07/12] trying to remove the warnings from the workflow --- .github/workflows/main.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 35dd2102f4a..633c97249df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,7 +49,9 @@ jobs: - id: setup-zephir-ext name: Setup Zephir Extensions run: | - echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" +# echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" + echo "{extensions}=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_STATE + # PHP CodeSniffer inspection phpcs: @@ -179,7 +181,8 @@ jobs: } else { $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } - echo "::set-output name=extension-path::$PhalconExtPath" +# echo "::set-output name=extension-path::$PhalconExtPath" + echo "{extension-path}=$PhalconExtPath" >> $GITHUB_STATE - name: Creates build artifact with Phalcon extension uses: ./.github/actions/pack-phalcon-ext @@ -387,7 +390,8 @@ jobs: - name: Get the release version id: get-version run: | - echo ::set-output name=version::${GITHUB_REF#refs/tags/} +# echo ::set-output name=version::${GITHUB_REF#refs/tags/} + echo "{version}=${GITHUB_REF#refs/tags/}" >> $GITHUB_STATE - name: Download Phalcon build artifacts id: download From 6e1b7dca289a11ed7eac6580aba759b207ed5654 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 12:14:43 -0500 Subject: [PATCH 08/12] trying again with the GitHub env --- .github/workflows/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 633c97249df..d9cfe5a658f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,8 +49,9 @@ jobs: - id: setup-zephir-ext name: Setup Zephir Extensions run: | + echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_ENV + # echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" - echo "{extensions}=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_STATE # PHP CodeSniffer inspection @@ -181,8 +182,9 @@ jobs: } else { $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } + echo "extension-path={$PhalconExtPath}" >> $GITHUB_ENV + # echo "::set-output name=extension-path::$PhalconExtPath" - echo "{extension-path}=$PhalconExtPath" >> $GITHUB_STATE - name: Creates build artifact with Phalcon extension uses: ./.github/actions/pack-phalcon-ext @@ -390,8 +392,9 @@ jobs: - name: Get the release version id: get-version run: | + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + # echo ::set-output name=version::${GITHUB_REF#refs/tags/} - echo "{version}=${GITHUB_REF#refs/tags/}" >> $GITHUB_STATE - name: Download Phalcon build artifacts id: download From e7a2cd6ec89e4d5870466d1ba51c5a36f9577f68 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 12:17:17 -0500 Subject: [PATCH 09/12] trying GitHub output --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9cfe5a658f..fecbfbcd2c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,7 +49,7 @@ jobs: - id: setup-zephir-ext name: Setup Zephir Extensions run: | - echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_ENV + echo "extensions=zephir_parser-{${{ env.ZEPHIR_PARSER_VERSION }}}" >> $GITHUB_OUTPUT # echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" @@ -182,7 +182,7 @@ jobs: } else { $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } - echo "extension-path={$PhalconExtPath}" >> $GITHUB_ENV + echo "extension-path={$PhalconExtPath}" >> $GITHUB_OUTPUT # echo "::set-output name=extension-path::$PhalconExtPath" @@ -392,7 +392,7 @@ jobs: - name: Get the release version id: get-version run: | - echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT # echo ::set-output name=version::${GITHUB_REF#refs/tags/} From 2a9bc7ab09d89078e6712d880e2501343903aba7 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 12:21:44 -0500 Subject: [PATCH 10/12] trying a different syntax to load the zephir extension --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fecbfbcd2c3..34261c4cbf4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,7 +49,7 @@ jobs: - id: setup-zephir-ext name: Setup Zephir Extensions run: | - echo "extensions=zephir_parser-{${{ env.ZEPHIR_PARSER_VERSION }}}" >> $GITHUB_OUTPUT + echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_OUTPUT # echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" From 03cf1c947bb962c436cc5f50b419b2645c6a280a Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 13:31:28 -0500 Subject: [PATCH 11/12] trying a correction to the phalcon extension variable --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34261c4cbf4..985b117a724 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -182,7 +182,7 @@ jobs: } else { $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } - echo "extension-path={$PhalconExtPath}" >> $GITHUB_OUTPUT + echo "extension-path=$PhalconExtPath" >> $GITHUB_OUTPUT # echo "::set-output name=extension-path::$PhalconExtPath" From 4d5f7bafe022228740e4b60772b3aa8554308f9d Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 24 Oct 2023 13:46:37 -0500 Subject: [PATCH 12/12] reverting code to set-output --- .github/workflows/main.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 985b117a724..7a299094cce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,9 +49,8 @@ jobs: - id: setup-zephir-ext name: Setup Zephir Extensions run: | - echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> $GITHUB_OUTPUT - -# echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" + 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 @@ -182,9 +181,8 @@ jobs: } else { $PhalconExtPath = "$(php-config --extension-dir)/phalcon.so" } - echo "extension-path=$PhalconExtPath" >> $GITHUB_OUTPUT - -# echo "::set-output name=extension-path::$PhalconExtPath" + 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 @@ -392,9 +390,8 @@ jobs: - name: Get the release version id: get-version run: | - echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - -# echo ::set-output name=version::${GITHUB_REF#refs/tags/} + 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