From 2a15b75e4301621ef445df642ff61ca14d5bb422 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 17 May 2023 13:48:51 -0400 Subject: [PATCH] [WIP] Deprecating the stimulus functionality in favor of an upcoming StimulusBundle --- .github/workflows/static.yml | 2 +- CHANGELOG.md | 5 + doc/index.rst | 157 +----------------- src/CacheWarmer/EntrypointCacheWarmer.php | 3 - .../Compiler/RemoveStimulusServicesPass.php | 24 +++ src/Dto/AbstractStimulusDto.php | 2 + src/Dto/StimulusActionsDto.php | 3 + src/Dto/StimulusControllersDto.php | 3 + src/Dto/StimulusTargetsDto.php | 3 + src/Twig/StimulusTwigExtension.php | 3 + src/WebpackEncoreBundle.php | 6 + 11 files changed, 54 insertions(+), 157 deletions(-) create mode 100644 src/DependencyInjection/Compiler/RemoveStimulusServicesPass.php diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 7a42b56f..a681edd5 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -49,7 +49,7 @@ jobs: composer-options: "--working-dir=tools/php-cs-fixer" - name: PHP-CS-Fixer - run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr + run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run psalm: name: Psalm diff --git a/CHANGELOG.md b/CHANGELOG.md index 854e4d18..ae65c9b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v1.17.0 + +- Deprecated the `stimulus_controller()`, `stimulus_action()` and `stimulus_target` + functions and related classes. Install `symfony/stimulus-bundle` instead. + ## [v1.16.0](https://github.com/symfony/webpack-encore-bundle/releases/tag/v1.16.0) *October 18th, 2022* diff --git a/doc/index.rst b/doc/index.rst index c696e67e..84879d2d 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -204,160 +204,11 @@ different ways: Stimulus / Symfony UX Helper ---------------------------- -stimulus_controller -~~~~~~~~~~~~~~~~~~~ - -This bundle also ships with a special ``stimulus_controller()`` Twig function -that can be used to render `Stimulus Controllers & Values`_ and `CSS Classes`_. -See `stimulus-bridge`_ for more details. - -For example: - -.. code-block:: html+twig - -
- Hello -
- - -
- Hello -
- -If you want to set CSS classes: - -.. code-block:: html+twig - -
- Hello -
- - -
- Hello -
- - -
- Hello -
- -Any non-scalar values (like ``data: [1, 2, 3, 4]``) are JSON-encoded. And all -values are properly escaped (the string ``[`` is an escaped -``[`` character, so the attribute is really ``[1,2,3,4]``). - -If you have multiple controllers on the same element, you can chain them as there's also a ``stimulus_controller`` filter: - -.. code-block:: html+twig - -
- Hello -
- -You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms: - -.. code-block:: twig - - {{ form_start(form, { attr: stimulus_controller('chart', { 'name': 'Likes' }).toArray() }) }} - -stimulus_action -~~~~~~~~~~~~~~~ - -The ``stimulus_action()`` Twig function can be used to render `Stimulus Actions`_. - -For example: - -.. code-block:: html+twig - -
Hello
-
Hello
- - -
Hello
-
Hello
- -If you have multiple actions and/or methods on the same element, you can chain them as there's also a -``stimulus_action`` filter: - -.. code-block:: html+twig - -
- Hello -
- - -
- Hello -
- -You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms: - -.. code-block:: twig - - {{ form_row(form.password, { attr: stimulus_action('hello-controller', 'checkPasswordStrength').toArray() }) }} - -You can also pass `parameters`_ to actions: - -.. code-block:: html+twig - -
Hello
- - -
Hello
- -stimulus_target -~~~~~~~~~~~~~~~ - -The ``stimulus_target()`` Twig function can be used to render `Stimulus Targets`_. - -For example: - -.. code-block:: html+twig - -
Hello
-
Hello
- - -
Hello
-
Hello
- -If you have multiple targets on the same element, you can chain them as there's also a `stimulus_target` filter: - -.. code-block:: html+twig - -
- Hello -
- - -
- Hello -
- -You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms: - -.. code-block:: twig - - {{ form_row(form.password, { attr: stimulus_target('hello-controller', 'a-target').toArray() }) }} - -Ok, have fun! - +The ``stimulus_controller()``, ``stimulus_action()`` and ``stimulus_target()`` +Twig functions are deprecated in WebpackEncoreBundle 1.17.0. Install and +use `symfony/stimulus-bundle`_ for that functionality. .. _`Webpack Encore`: https://symfony.com/doc/current/frontend.html .. _`enable the bundle manually`: https://symfony.com/doc/current/bundles.html .. _`"splits" your files`: https://webpack.js.org/plugins/split-chunks-plugin/ -.. _`Stimulus Controllers & Values`: https://stimulus.hotwired.dev/reference/values -.. _`CSS Classes`: https://stimulus.hotwired.dev/reference/css-classes -.. _`stimulus-bridge`: https://github.com/symfony/stimulus-bridge -.. _`Stimulus Actions`: https://stimulus.hotwired.dev/reference/actions -.. _`parameters`: https://stimulus.hotwired.dev/reference/actions#action-parameters -.. _`Stimulus Targets`: https://stimulus.hotwired.dev/reference/targets +.. _`symfony/stimulus-bundle`: https://symfony.com/bundles/StimulusBundle/current/index.html diff --git a/src/CacheWarmer/EntrypointCacheWarmer.php b/src/CacheWarmer/EntrypointCacheWarmer.php index 2762db93..9c5f9cb0 100644 --- a/src/CacheWarmer/EntrypointCacheWarmer.php +++ b/src/CacheWarmer/EntrypointCacheWarmer.php @@ -24,9 +24,6 @@ public function __construct(array $cacheKeys, string $phpArrayFile) parent::__construct($phpArrayFile); } - /** - * {@inheritdoc} - */ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter): bool { foreach ($this->cacheKeys as $cacheKey => $path) { diff --git a/src/DependencyInjection/Compiler/RemoveStimulusServicesPass.php b/src/DependencyInjection/Compiler/RemoveStimulusServicesPass.php new file mode 100644 index 00000000..02db3c51 --- /dev/null +++ b/src/DependencyInjection/Compiler/RemoveStimulusServicesPass.php @@ -0,0 +1,24 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\WebpackEncoreBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class RemoveStimulusServicesPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if ($container->hasDefinition('stimulus.helper')) { + // remove the Stimulus integration if StimulusBundle is installed + $container->removeDefinition('webpack_encore.twig_stimulus_extension'); + } + } +} diff --git a/src/Dto/AbstractStimulusDto.php b/src/Dto/AbstractStimulusDto.php index 2f696cd1..b968246b 100644 --- a/src/Dto/AbstractStimulusDto.php +++ b/src/Dto/AbstractStimulusDto.php @@ -15,6 +15,8 @@ /** * @internal + * + * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead. */ abstract class AbstractStimulusDto implements \Stringable { diff --git a/src/Dto/StimulusActionsDto.php b/src/Dto/StimulusActionsDto.php index e0d83a38..d2ad92fd 100644 --- a/src/Dto/StimulusActionsDto.php +++ b/src/Dto/StimulusActionsDto.php @@ -11,6 +11,9 @@ namespace Symfony\WebpackEncoreBundle\Dto; +/** + * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead. + */ final class StimulusActionsDto extends AbstractStimulusDto { private $actions = []; diff --git a/src/Dto/StimulusControllersDto.php b/src/Dto/StimulusControllersDto.php index 973aa19a..483a6bc3 100644 --- a/src/Dto/StimulusControllersDto.php +++ b/src/Dto/StimulusControllersDto.php @@ -11,6 +11,9 @@ namespace Symfony\WebpackEncoreBundle\Dto; +/** + * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead. + */ final class StimulusControllersDto extends AbstractStimulusDto { private $controllers = []; diff --git a/src/Dto/StimulusTargetsDto.php b/src/Dto/StimulusTargetsDto.php index 2a0f79b4..a2691127 100644 --- a/src/Dto/StimulusTargetsDto.php +++ b/src/Dto/StimulusTargetsDto.php @@ -11,6 +11,9 @@ namespace Symfony\WebpackEncoreBundle\Dto; +/** + * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead. + */ final class StimulusTargetsDto extends AbstractStimulusDto { private $targets = []; diff --git a/src/Twig/StimulusTwigExtension.php b/src/Twig/StimulusTwigExtension.php index 68509867..41837173 100644 --- a/src/Twig/StimulusTwigExtension.php +++ b/src/Twig/StimulusTwigExtension.php @@ -17,6 +17,9 @@ use Twig\TwigFilter; use Twig\TwigFunction; +/** + * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead. + */ final class StimulusTwigExtension extends AbstractExtension { public function getFunctions(): array diff --git a/src/WebpackEncoreBundle.php b/src/WebpackEncoreBundle.php index b4fcfbae..3a6be80a 100644 --- a/src/WebpackEncoreBundle.php +++ b/src/WebpackEncoreBundle.php @@ -9,8 +9,14 @@ namespace Symfony\WebpackEncoreBundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\WebpackEncoreBundle\DependencyInjection\Compiler\RemoveStimulusServicesPass; final class WebpackEncoreBundle extends Bundle { + public function build(ContainerBuilder $container) + { + $container->addCompilerPass(new RemoveStimulusServicesPass()); + } }