Skip to content

Commit 9b1812a

Browse files
committed
general cleanup
1 parent 2ff380a commit 9b1812a

File tree

8 files changed

+34
-63
lines changed

8 files changed

+34
-63
lines changed

src/LiveComponent/src/ComponentValidator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\UX\LiveComponent;
1313

1414
use Psr\Container\ContainerInterface;
15-
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1615
use Symfony\Component\Validator\ConstraintViolation;
1716
use Symfony\Component\Validator\Validator\ValidatorInterface;
1817
use Symfony\Contracts\Service\ServiceSubscriberInterface;
@@ -26,8 +25,7 @@
2625
*/
2726
class ComponentValidator implements ComponentValidatorInterface, ServiceSubscriberInterface
2827
{
29-
/** @var ContainerInterface */
30-
private $container;
28+
private ContainerInterface $container;
3129

3230
public function __construct(ContainerInterface $container)
3331
{
@@ -88,16 +86,10 @@ private function getValidator(): ValidatorInterface
8886
return $this->container->get('validator');
8987
}
9088

91-
private function getPropertyAccessor(): PropertyAccessorInterface
92-
{
93-
return $this->container->get('property_accessor');
94-
}
95-
9689
public static function getSubscribedServices(): array
9790
{
9891
return [
9992
'validator' => ValidatorInterface::class,
100-
'property_accessor' => PropertyAccessorInterface::class,
10193
];
10294
}
10395
}

src/LiveComponent/src/ComponentWithFormTrait.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,33 @@ trait ComponentWithFormTrait
3030

3131
/**
3232
* Holds the name prefix the form uses.
33-
*
34-
* @LiveProp()
3533
*/
34+
#[LiveProp]
3635
public ?string $formName = null;
3736

3837
/**
3938
* Holds the raw form values.
40-
*
41-
* @LiveProp(writable=true, fieldName="getFormName()")
4239
*/
40+
#[LiveProp(writable: true, fieldName: 'getFormName()')]
4341
public ?array $formValues = null;
4442

4543
/**
4644
* Tracks whether this entire component has been validated.
4745
*
4846
* This is used to know if validation should be automatically applied
4947
* when rendering.
50-
*
51-
* @LiveProp(writable=true)
52-
*
53-
* @var bool
5448
*/
55-
public $isValidated = false;
49+
#[LiveProp(writable: true)]
50+
public bool $isValidated = false;
5651

5752
/**
5853
* Tracks which specific fields have been validated.
5954
*
6055
* Instead of validating the entire object (isValidated),
6156
* the component can be validated, field-by-field.
62-
*
63-
* @LiveProp(writable=true)
64-
*
65-
* @var array
6657
*/
67-
public $validatedFields = [];
58+
#[LiveProp(writable: true)]
59+
public array $validatedFields = [];
6860

6961
/**
7062
* Return the full, top-level, Form object that this component uses.
@@ -90,10 +82,9 @@ public function mount(?FormView $form = null)
9082
* This primarily applies to a re-render where $actionName is null.
9183
* But, in the event that there is an action and the form was
9284
* not submitted manually, it will be submitted here.
93-
*
94-
* @BeforeReRender()
9585
*/
96-
public function submitFormOnRender()
86+
#[BeforeReRender]
87+
public function submitFormOnRender(): void
9788
{
9889
if (!$this->getFormInstance()->isSubmitted()) {
9990
$this->submitForm(false);
@@ -119,7 +110,7 @@ public function getForm(): FormView
119110
* don't need to call this directly: the form will be set for
120111
* you from your instantiateForm() method.
121112
*/
122-
public function setForm(FormView $form)
113+
public function setForm(FormView $form): void
123114
{
124115
$this->formView = $form;
125116
}
@@ -142,7 +133,7 @@ public function getFormValues(): array
142133
return $this->formValues;
143134
}
144135

145-
private function submitForm(bool $validateAll = true)
136+
private function submitForm(bool $validateAll = true): void
146137
{
147138
$this->getFormInstance()->submit($this->formValues);
148139

@@ -201,7 +192,7 @@ private function getFormInstance(): FormInterface
201192
return $this->formInstance;
202193
}
203194

204-
private function clearErrorsForNonValidatedFields(Form $form, $currentPath = '')
195+
private function clearErrorsForNonValidatedFields(Form $form, $currentPath = ''): void
205196
{
206197
if (!$currentPath || !\in_array($currentPath, $this->validatedFields, true)) {
207198
$form->clearErrors();

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function load(array $configs, ContainerBuilder $container): void
8989

9090
$container->register(ComponentValidator::class)
9191
->addTag('container.service_subscriber', ['key' => 'validator', 'id' => 'validator'])
92-
->addTag('container.service_subscriber', ['key' => 'property_accessor', 'id' => 'property_accessor'])
9392
;
9493

9594
$container->setAlias(ComponentValidatorInterface::class, ComponentValidator::class);

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public static function getSubscribedServices(): array
6565
];
6666
}
6767

68-
public function onKernelRequest(RequestEvent $event)
68+
public function onKernelRequest(RequestEvent $event): void
6969
{
7070
$request = $event->getRequest();
71+
7172
if (!$this->isLiveComponentRequest($request)) {
7273
return;
7374
}
@@ -105,7 +106,7 @@ public function onKernelRequest(RequestEvent $event)
105106
$request->attributes->set('_controller', sprintf('%s::%s', $this->componentServiceMap[$componentName], $action));
106107
}
107108

108-
public function onKernelController(ControllerEvent $event)
109+
public function onKernelController(ControllerEvent $event): void
109110
{
110111
$request = $event->getRequest();
111112

@@ -144,7 +145,7 @@ public function onKernelController(ControllerEvent $event)
144145
$request->attributes->set('_component', $component);
145146
}
146147

147-
public function onKernelView(ViewEvent $event)
148+
public function onKernelView(ViewEvent $event): void
148149
{
149150
$request = $event->getRequest();
150151
if (!$this->isLiveComponentRequest($request)) {
@@ -156,9 +157,10 @@ public function onKernelView(ViewEvent $event)
156157
$event->setResponse($response);
157158
}
158159

159-
public function onKernelException(ExceptionEvent $event)
160+
public function onKernelException(ExceptionEvent $event): void
160161
{
161162
$request = $event->getRequest();
163+
162164
if (!$this->isLiveComponentRequest($request)) {
163165
return;
164166
}
@@ -200,7 +202,7 @@ public function onKernelResponse(ResponseEvent $event): void
200202
]));
201203
}
202204

203-
public static function getSubscribedEvents()
205+
public static function getSubscribedEvents(): array
204206
{
205207
return [
206208
RequestEvent::class => 'onKernelRequest',

src/LiveComponent/src/Hydrator/DoctrineEntityPropertyHydrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
final class DoctrineEntityPropertyHydrator implements PropertyHydratorInterface
2525
{
2626
/** @var ManagerRegistry[] */
27-
private $managerRegistries;
27+
private iterable $managerRegistries;
2828

2929
/**
3030
* @param ManagerRegistry[] $managerRegistries

src/LiveComponent/src/Hydrator/NormalizerBridgePropertyHydrator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
final class NormalizerBridgePropertyHydrator implements PropertyHydratorInterface
2525
{
2626
/** @var NormalizerInterface|DenormalizerInterface */
27-
private $normalizer;
27+
private NormalizerInterface $normalizer;
2828

29+
/**
30+
* @param NormalizerInterface|DenormalizerInterface $normalizer
31+
*/
2932
public function __construct(NormalizerInterface $normalizer)
3033
{
3134
if (!$normalizer instanceof DenormalizerInterface) {

src/LiveComponent/src/Twig/LiveComponentRuntime.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
*/
2525
final class LiveComponentRuntime
2626
{
27-
/** @var LiveComponentHydrator */
28-
private $hydrator;
29-
30-
/** @var UrlGeneratorInterface */
31-
private $urlGenerator;
32-
33-
/** @var CsrfTokenManagerInterface|null */
34-
private $csrfTokenManager;
27+
private LiveComponentHydrator $hydrator;
28+
private UrlGeneratorInterface $urlGenerator;
29+
private ?CsrfTokenManagerInterface $csrfTokenManager;
3530

3631
public function __construct(LiveComponentHydrator $hydrator, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager = null)
3732
{

src/LiveComponent/src/ValidatableComponentTrait.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,26 @@
2323
*/
2424
trait ValidatableComponentTrait
2525
{
26-
/** @var ComponentValidatorInterface|null */
27-
private $componentValidator;
28-
29-
/** @var array */
30-
private $validationErrors = [];
26+
private ?ComponentValidatorInterface $componentValidator = null;
27+
private array $validationErrors = [];
3128

3229
/**
3330
* Tracks whether this entire component has been validated.
3431
*
3532
* This is used to know if validation should be automatically applied
3633
* when rendering.
37-
*
38-
* @LiveProp(writable=true)
39-
*
40-
* @var bool
4134
*/
42-
public $isValidated = false;
35+
#[LiveProp(writable: true)]
36+
public bool $isValidated = false;
4337

4438
/**
4539
* Tracks which specific fields have been validated.
4640
*
4741
* Instead of validating the entire object (isValidated),
4842
* the component can be validated, field-by-field.
49-
*
50-
* @LiveProp(writable=true)
51-
*
52-
* @var array
5343
*/
54-
public $validatedFields = [];
44+
#[LiveProp(writable: true)]
45+
public array $validatedFields = [];
5546

5647
/**
5748
* Validate the entire component.
@@ -123,9 +114,7 @@ public function clearValidation(): void
123114
$this->validationErrors = [];
124115
}
125116

126-
/**
127-
* @PostHydrate()
128-
*/
117+
#[PostHydrate]
129118
public function validateAfterHydration()
130119
{
131120
if ($this->isValidated) {

0 commit comments

Comments
 (0)