diff --git a/src/LiveComponent/CHANGELOG.md b/src/LiveComponent/CHANGELOG.md index 39a47f8b337..4b6c1ad88d0 100644 --- a/src/LiveComponent/CHANGELOG.md +++ b/src/LiveComponent/CHANGELOG.md @@ -31,6 +31,8 @@ is a BC break if you've created custom hydrators. They'll need to be converted to normalizers. +- [BC BREAK] Rename `BeforeReRender` attribute to `PreReRender`. + ## 2.0.0 - Support for `stimulus` version 2 was removed and support for `@hotwired/stimulus` diff --git a/src/LiveComponent/src/Attribute/AsLiveComponent.php b/src/LiveComponent/src/Attribute/AsLiveComponent.php index 07b3a3937a3..05ebf21d0a0 100644 --- a/src/LiveComponent/src/Attribute/AsLiveComponent.php +++ b/src/LiveComponent/src/Attribute/AsLiveComponent.php @@ -86,9 +86,9 @@ public static function isActionAllowed(object $component, string $action): bool * * @return \ReflectionMethod[] */ - public static function beforeReRenderMethods(object $component): \Traversable + public static function preReRenderMethods(object $component): \Traversable { - yield from self::attributeMethodsFor(BeforeReRender::class, $component); + yield from self::attributeMethodsFor(PreReRender::class, $component); } /** diff --git a/src/LiveComponent/src/Attribute/BeforeReRender.php b/src/LiveComponent/src/Attribute/PreReRender.php similarity index 95% rename from src/LiveComponent/src/Attribute/BeforeReRender.php rename to src/LiveComponent/src/Attribute/PreReRender.php index 637e03e2744..831f8f58708 100644 --- a/src/LiveComponent/src/Attribute/BeforeReRender.php +++ b/src/LiveComponent/src/Attribute/PreReRender.php @@ -20,6 +20,6 @@ * @experimental */ #[\Attribute(\Attribute::TARGET_METHOD)] -final class BeforeReRender +final class PreReRender { } diff --git a/src/LiveComponent/src/ComponentWithFormTrait.php b/src/LiveComponent/src/ComponentWithFormTrait.php index 7dfd4d92b19..ac9d5626eaa 100644 --- a/src/LiveComponent/src/ComponentWithFormTrait.php +++ b/src/LiveComponent/src/ComponentWithFormTrait.php @@ -15,8 +15,8 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; -use Symfony\UX\LiveComponent\Attribute\BeforeReRender; use Symfony\UX\LiveComponent\Attribute\LiveProp; +use Symfony\UX\LiveComponent\Attribute\PreReRender; use Symfony\UX\LiveComponent\Util\LiveFormUtility; use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate; use Symfony\UX\TwigComponent\Attribute\PostMount; @@ -99,7 +99,7 @@ public function postMount(array $data): array * But, in the event that there is an action and the form was * not submitted manually, it will be submitted here. */ - #[BeforeReRender] + #[PreReRender] public function submitFormOnRender(): void { if (!$this->getFormInstance()->isSubmitted()) { diff --git a/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php b/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php index a89a7fcef69..6ca6db0f6bf 100644 --- a/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php +++ b/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php @@ -241,7 +241,7 @@ private function createResponse(MountedComponent $mounted, Request $request): Re { $component = $mounted->getComponent(); - foreach (AsLiveComponent::beforeReRenderMethods($component) as $method) { + foreach (AsLiveComponent::preReRenderMethods($component) as $method) { $component->{$method->name}(); } diff --git a/src/LiveComponent/tests/Fixtures/Component/Component2.php b/src/LiveComponent/tests/Fixtures/Component/Component2.php index 51ca3415a40..b495f950521 100644 --- a/src/LiveComponent/tests/Fixtures/Component/Component2.php +++ b/src/LiveComponent/tests/Fixtures/Component/Component2.php @@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; -use Symfony\UX\LiveComponent\Attribute\BeforeReRender; +use Symfony\UX\LiveComponent\Attribute\PreReRender; use Symfony\UX\LiveComponent\Attribute\LiveAction; use Symfony\UX\LiveComponent\Attribute\LiveProp; use Symfony\UX\LiveComponent\Attribute\PostHydrate; @@ -63,7 +63,7 @@ public function postHydrateMethod(): void $this->postHydrateCalled = true; } - #[BeforeReRender] + #[PreReRender] public function beforeReRenderMethod(): void { $this->beforeReRenderCalled = true; diff --git a/src/LiveComponent/tests/Fixtures/Component/Component4.php b/src/LiveComponent/tests/Fixtures/Component/Component4.php index 71719ba6304..37698dd0b5f 100644 --- a/src/LiveComponent/tests/Fixtures/Component/Component4.php +++ b/src/LiveComponent/tests/Fixtures/Component/Component4.php @@ -11,7 +11,7 @@ namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component; -use Symfony\UX\LiveComponent\Attribute\BeforeReRender; +use Symfony\UX\LiveComponent\Attribute\PreReRender; use Symfony\UX\LiveComponent\Attribute\LiveAction; use Symfony\UX\LiveComponent\Attribute\LiveProp; use Symfony\UX\LiveComponent\Attribute\PostHydrate; @@ -39,7 +39,7 @@ public function method2() { } - #[BeforeReRender] + #[PreReRender] public function method3() { } diff --git a/src/LiveComponent/tests/Unit/Attribute/AsLiveComponentTest.php b/src/LiveComponent/tests/Unit/Attribute/AsLiveComponentTest.php index 9b9c16e7140..2e73663a199 100644 --- a/src/LiveComponent/tests/Unit/Attribute/AsLiveComponentTest.php +++ b/src/LiveComponent/tests/Unit/Attribute/AsLiveComponentTest.php @@ -47,7 +47,7 @@ public function testCanGetPostHydrateMethods(): void public function testCanGetBeforeReRenderMethods(): void { - $methods = iterator_to_array(AsLiveComponent::beforeReRenderMethods(new Component5())); + $methods = iterator_to_array(AsLiveComponent::preReRenderMethods(new Component5())); $this->assertCount(1, $methods); $this->assertSame('method3', $methods[0]->getName());