Skip to content

Commit c1b1f43

Browse files
committed
QueryStringPropsExtractor, renamed to UrlPropsExtractor shall get props from path also
1 parent 3cb2de1 commit c1b1f43

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

Diff for: src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
use Symfony\UX\LiveComponent\Util\FingerprintCalculator;
5252
use Symfony\UX\LiveComponent\Util\LiveComponentStack;
5353
use Symfony\UX\LiveComponent\Util\LiveControllerAttributesCreator;
54-
use Symfony\UX\LiveComponent\Util\QueryStringPropsExtractor;
5554
use Symfony\UX\LiveComponent\Util\TwigAttributeHelperFactory;
55+
use Symfony\UX\LiveComponent\Util\UrlPropsExtractor;
5656
use Symfony\UX\TwigComponent\ComponentFactory;
5757
use Symfony\UX\TwigComponent\ComponentRenderer;
5858

@@ -231,7 +231,7 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
231231
->addTag('container.service_subscriber', ['key' => LiveControllerAttributesCreator::class, 'id' => 'ux.live_component.live_controller_attributes_creator'])
232232
;
233233

234-
$container->register('ux.live_component.query_string_props_extractor', QueryStringPropsExtractor::class)
234+
$container->register('ux.live_component.query_string_props_extractor', UrlPropsExtractor::class)
235235
->setArguments([
236236
new Reference('ux.live_component.component_hydrator'),
237237
]);

Diff for: src/LiveComponent/src/EventListener/QueryStringInitializeSubscriber.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\PropertyAccess\Exception\ExceptionInterface as PropertyAccessExceptionInterface;
1717
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1818
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
19-
use Symfony\UX\LiveComponent\Util\QueryStringPropsExtractor;
19+
use Symfony\UX\LiveComponent\Util\UrlPropsExtractor;
2020
use Symfony\UX\TwigComponent\Event\PostMountEvent;
2121

2222
/**
@@ -29,7 +29,7 @@ class QueryStringInitializeSubscriber implements EventSubscriberInterface
2929
public function __construct(
3030
private readonly RequestStack $requestStack,
3131
private readonly LiveComponentMetadataFactory $metadataFactory,
32-
private readonly QueryStringPropsExtractor $queryStringPropsExtractor,
32+
private readonly UrlPropsExtractor $queryStringPropsExtractor,
3333
private readonly PropertyAccessorInterface $propertyAccessor,
3434
) {
3535
}

Diff for: src/LiveComponent/src/Util/QueryStringPropsExtractor.php renamed to src/LiveComponent/src/Util/UrlPropsExtractor.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,29 @@
2222
*
2323
* @internal
2424
*/
25-
final class QueryStringPropsExtractor
25+
final class UrlPropsExtractor
2626
{
2727
public function __construct(private readonly LiveComponentHydrator $hydrator)
2828
{
2929
}
3030

3131
/**
32-
* Extracts relevant query parameters from the current URL and hydrates them.
32+
* Extracts relevant props parameters from the current URL and hydrates them.
3333
*/
3434
public function extract(Request $request, LiveComponentMetadata $metadata, object $component): array
3535
{
36-
$query = $request->query->all();
36+
$parameters = array_merge($request->attributes->all(), $request->query->all());
3737

38-
if (empty($query)) {
38+
// @todo never empty because custom values prefixed with _ ... do something ?
39+
if (empty($parameters)) {
3940
return [];
4041
}
4142
$data = [];
4243

4344
foreach ($metadata->getAllLivePropsMetadata($component) as $livePropMetadata) {
4445
if ($queryMapping = $livePropMetadata->urlMapping()) {
4546
$frontendName = $livePropMetadata->calculateFieldName($component, $livePropMetadata->getName());
46-
if (null !== ($value = $query[$queryMapping->as ?? $frontendName] ?? null)) {
47+
if (null !== ($value = $parameters[$queryMapping->as ?? $frontendName] ?? null)) {
4748
if ('' === $value && null !== $livePropMetadata->getType() && (!$livePropMetadata->isBuiltIn() || 'array' === $livePropMetadata->getType())) {
4849
// Cast empty string to empty array for objects and arrays
4950
$value = [];

Diff for: src/LiveComponent/tests/Functional/Util/QueryStringPropsExtractorTest.php renamed to src/LiveComponent/tests/Functional/Util/UrlPropsExtractorTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
1717
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Address;
1818
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
19-
use Symfony\UX\LiveComponent\Util\QueryStringPropsExtractor;
19+
use Symfony\UX\LiveComponent\Util\UrlPropsExtractor;
2020

21-
class QueryStringPropsExtractorTest extends KernelTestCase
21+
class UrlPropsExtractorTest extends KernelTestCase
2222
{
2323
use LiveComponentTestHelper;
2424

@@ -27,7 +27,7 @@ class QueryStringPropsExtractorTest extends KernelTestCase
2727
*/
2828
public function testExtract(string $queryString, array $expected)
2929
{
30-
$extractor = new QueryStringPropsExtractor($this->hydrator());
30+
$extractor = new UrlPropsExtractor($this->hydrator());
3131

3232
$request = Request::create('/'.!empty($queryString) ? '?'.$queryString : '');
3333

0 commit comments

Comments
 (0)