Skip to content

Commit 5a0976a

Browse files
committed
Rename QueryMapping to UrlMapping and alias to as
1 parent 977df51 commit 5a0976a

15 files changed

+111
-106
lines changed

src/LiveComponent/src/Attribute/LiveProp.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

14-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
14+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1515

1616
/**
1717
* An attribute to mark a property as a "LiveProp".
@@ -103,16 +103,16 @@ public function __construct(
103103
/**
104104
* Whether to synchronize this property with a query parameter
105105
* in the URL. Pass true to configure the mapping automatically, or a
106-
* {@see QueryMapping} instance to configure the mapping.
106+
* {@see UrlMapping} instance to configure the mapping.
107107
*/
108-
private bool|QueryMapping $url = false,
108+
private bool|UrlMapping $url = false,
109109
) {
110110
if ($this->useSerializerForHydration && ($this->hydrateWith || $this->dehydrateWith)) {
111111
throw new \InvalidArgumentException('Cannot use useSerializerForHydration with hydrateWith or dehydrateWith.');
112112
}
113113

114114
if (true === $url) {
115-
$this->url = new QueryMapping();
115+
$this->url = new UrlMapping();
116116
}
117117
}
118118

@@ -205,7 +205,7 @@ public function onUpdated(): null|string|array
205205
return $this->onUpdated;
206206
}
207207

208-
public function url(): QueryMapping|false
208+
public function url(): UrlMapping|false
209209
{
210210
return $this->url;
211211
}

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Contracts\Service\ServiceSubscriberInterface;
1717
use Symfony\UX\LiveComponent\Twig\TemplateMap;
1818
use Symfony\UX\LiveComponent\Util\LiveControllerAttributesCreator;
19-
use Symfony\UX\LiveComponent\Util\QueryMappingAttributeUtils;
19+
use Symfony\UX\LiveComponent\Util\UrlMappingAttributeUtils;
2020
use Symfony\UX\TwigComponent\ComponentAttributes;
2121
use Symfony\UX\TwigComponent\ComponentMetadata;
2222
use Symfony\UX\TwigComponent\ComponentStack;
@@ -80,7 +80,7 @@ public function onPreRender(PreRenderEvent $event): void
8080
// this is used inside LiveControllerAttributesCreator
8181
$attributes = $attributes->without(LiveControllerAttributesCreator::KEY_PROP_NAME);
8282

83-
$attributes = QueryMappingAttributeUtils::removeAttributesForRendering($attributes);
83+
$attributes = UrlMappingAttributeUtils::removeAttributesForRendering($attributes);
8484

8585
$variables[$attributesKey] = $attributes;
8686

src/LiveComponent/src/EventListener/QueryStringInitializeSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\HttpFoundation\RequestStack;
1616
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
17-
use Symfony\UX\LiveComponent\Util\QueryMappingAttributeUtils;
17+
use Symfony\UX\LiveComponent\Util\UrlMappingAttributeUtils;
1818
use Symfony\UX\LiveComponent\Util\QueryStringPropsExtractor;
1919
use Symfony\UX\TwigComponent\Event\PreMountEvent;
2020

@@ -61,7 +61,7 @@ public function onPreMount(PreMountEvent $event): void
6161
}
6262

6363
$data = $event->getData();
64-
$mappingDefaults = QueryMappingAttributeUtils::getMappingFromAttributes($data);
64+
$mappingDefaults = UrlMappingAttributeUtils::getMappingFromAttributes($data);
6565

6666
$queryStringData = $this->queryStringPropsExtractor->extract($request, $metadata, $event->getComponent(), $mappingDefaults);
6767

src/LiveComponent/src/Metadata/LiveComponentMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getOnlyPropsThatAcceptUpdatesFromParent(array $inputProps): arra
6565
public function hasQueryStringBindings(): bool
6666
{
6767
foreach ($this->getAllLivePropsMetadata() as $livePropMetadata) {
68-
if ($livePropMetadata->queryStringMapping()) {
68+
if ($livePropMetadata->urlMapping()) {
6969
return true;
7070
}
7171
}

src/LiveComponent/src/Metadata/LivePropMetadata.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
final class LivePropMetadata
2525
{
2626
public function __construct(
27-
private string $name,
28-
private LiveProp $liveProp,
29-
private ?string $typeName,
30-
private bool $isBuiltIn,
31-
private bool $allowsNull,
32-
private ?Type $collectionValueType,
33-
private ?QueryMapping $queryStringMapping,
27+
private string $name,
28+
private LiveProp $liveProp,
29+
private ?string $typeName,
30+
private bool $isBuiltIn,
31+
private bool $allowsNull,
32+
private ?Type $collectionValueType,
33+
private ?UrlMapping $urlMapping,
3434
) {
3535
}
3636

@@ -54,9 +54,9 @@ public function allowsNull(): bool
5454
return $this->allowsNull;
5555
}
5656

57-
public function queryStringMapping(): ?QueryMapping
57+
public function urlMapping(): ?UrlMapping
5858
{
59-
return $this->queryStringMapping;
59+
return $this->urlMapping;
6060
}
6161

6262
public function calculateFieldName(object $component, string $fallback): string

src/LiveComponent/src/Metadata/QueryMapping.php renamed to src/LiveComponent/src/Metadata/UrlMapping.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,31 @@
1111

1212
namespace Symfony\UX\LiveComponent\Metadata;
1313

14-
final class QueryMapping
14+
/**
15+
* Mapping configuration to bind a LiveProp to a URL query parameter.
16+
*
17+
* @author Nicolas Rigaud <[email protected]>
18+
*/
19+
final class UrlMapping
1520
{
1621
public function __construct(
1722
/**
1823
* The name of the prop that appears in the URL. If null, the LiveProp's field name is used.
1924
*/
20-
private ?string $alias = null,
25+
private ?string $as = null,
2126
) {
2227
}
2328

24-
public function getAlias(): ?string
29+
public function getAs(): ?string
2530
{
26-
return $this->alias;
31+
return $this->as;
2732
}
2833

29-
public function withAlias(?string $alias): self
34+
public function withAs(?string $alias): self
3035
{
3136
$clone = clone $this;
3237

33-
$clone->alias = $alias;
38+
$clone->as = $alias;
3439

3540
return $clone;
3641
}
@@ -39,7 +44,7 @@ public function merge(self $mapping): self
3944
{
4045
$clone = clone $this;
4146

42-
$clone->alias = $mapping->alias;
47+
$clone->as = $mapping->as;
4348

4449
return $clone;
4550
}

src/LiveComponent/src/Util/LiveControllerAttributesCreator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ public function attributesForRendering(MountedComponent $mounted, ComponentMetad
101101
$liveMetadata = $this->metadataFactory->getMetadata($mounted->getName());
102102

103103
if ($liveMetadata->hasQueryStringBindings()) {
104-
$defaultBindings = QueryMappingAttributeUtils::getMappingFromAttributes($mountedAttributes->all());
104+
$defaultBindings = UrlMappingAttributeUtils::getMappingFromAttributes($mountedAttributes->all());
105105
$mappings = [];
106106
foreach ($liveMetadata->getAllLivePropsMetadata() as $livePropMetadata) {
107-
if ($queryMapping = $livePropMetadata->queryStringMapping()) {
107+
if ($urlMapping = $livePropMetadata->urlMapping()) {
108108
if (isset($defaultBindings[$livePropMetadata->getName()])) {
109-
$queryMapping = $queryMapping->merge($defaultBindings[$livePropMetadata->getName()]);
109+
$urlMapping = $urlMapping->merge($defaultBindings[$livePropMetadata->getName()]);
110110
}
111111

112112
$frontendName = $livePropMetadata->calculateFieldName($mounted, $livePropMetadata->getName());
113-
$mappings[$frontendName] = ['name' => $queryMapping->getAlias() ?? $frontendName];
113+
$mappings[$frontendName] = ['name' => $urlMapping->getAs() ?? $frontendName];
114114
}
115115
}
116116
$attributesCollection->setQueryUrlMapping($mappings);

src/LiveComponent/src/Util/QueryStringPropsExtractor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\UX\LiveComponent\LiveComponentHydrator;
1717
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadata;
1818
use Symfony\UX\LiveComponent\Metadata\LivePropMetadata;
19-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
19+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
2020

2121
/**
2222
* @author Nicolas Rigaud <[email protected]>
@@ -34,7 +34,7 @@ public function __construct(private readonly LiveComponentHydrator $hydrator)
3434
/**
3535
* Extracts relevant query parameters from the current URL and hydrates them.
3636
*
37-
* @param QueryMapping[] $mappingDefaults
37+
* @param array<string, UrlMapping> $mappingDefaults
3838
*/
3939
public function extract(Request $request, LiveComponentMetadata $metadata, object $component, array $mappingDefaults = []): array
4040
{
@@ -46,12 +46,12 @@ public function extract(Request $request, LiveComponentMetadata $metadata, objec
4646
$data = [];
4747

4848
foreach ($metadata->getAllLivePropsMetadata() as $livePropMetadata) {
49-
if ($queryMapping = $livePropMetadata->queryStringMapping()) {
49+
if ($queryMapping = $livePropMetadata->urlMapping()) {
5050
if (isset($mappingDefaults[$livePropMetadata->getName()])) {
5151
$queryMapping = $queryMapping->merge($mappingDefaults[$livePropMetadata->getName()]);
5252
}
5353
$frontendName = $livePropMetadata->calculateFieldName($component, $livePropMetadata->getName());
54-
if (null !== ($value = $query[$queryMapping->getAlias() ?? $frontendName] ?? null)) {
54+
if (null !== ($value = $query[$queryMapping->getAs() ?? $frontendName] ?? null)) {
5555
if ('' === $value && null !== $livePropMetadata->getType() && (!$livePropMetadata->isBuiltIn() || 'array' === $livePropMetadata->getType())) {
5656
// Cast empty string to empty array for objects and arrays
5757
$value = [];

src/LiveComponent/src/Util/QueryMappingAttributeUtils.php renamed to src/LiveComponent/src/Util/UrlMappingAttributeUtils.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace Symfony\UX\LiveComponent\Util;
1313

14-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
14+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1515
use Symfony\UX\TwigComponent\ComponentAttributes;
1616

17-
class QueryMappingAttributeUtils
17+
class UrlMappingAttributeUtils
1818
{
1919
public const ATTRIBUTE_PREFIX = 'data-live-url-mapping-';
2020

2121
/**
22-
* @return QueryMapping[]
22+
* @return UrlMapping[]
2323
*/
2424
public static function getMappingFromAttributes(array $data): array
2525
{
@@ -30,11 +30,11 @@ public static function getMappingFromAttributes(array $data): array
3030
$parts = explode('-', $propMapping, 2);
3131
if (1 === \count($parts)) {
3232
$propName = $parts[0];
33-
$mapping[$propName] ??= new QueryMapping();
34-
$mapping[$propName] = $mapping[$propName]->merge(new QueryMapping(...$value));
33+
$mapping[$propName] ??= new UrlMapping();
34+
$mapping[$propName] = $mapping[$propName]->merge(new UrlMapping(...$value));
3535
} else {
3636
[$propName, $option] = $parts;
37-
$mapping[$propName] ??= new QueryMapping();
37+
$mapping[$propName] ??= new UrlMapping();
3838
$mapping[$propName] = $mapping[$propName]->{'with'.ucfirst($option)}(self::castOptionValue($option, $value));
3939
}
4040
}
@@ -57,7 +57,7 @@ public static function removeAttributesForRendering(ComponentAttributes $attribu
5757
private static function castOptionValue(string $option, mixed $value): mixed
5858
{
5959
return match ($option) {
60-
'alias' => (string) $value,
60+
'as' => (string) $value,
6161
default => null,
6262
};
6363
}

src/LiveComponent/tests/Fixtures/Component/ComponentWithUrlBoundProps.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
1515
use Symfony\UX\LiveComponent\Attribute\LiveProp;
1616
use Symfony\UX\LiveComponent\DefaultActionTrait;
17-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
17+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1818
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Address;
1919

2020
#[AsLiveComponent('component_with_url_bound_props')]
@@ -40,10 +40,10 @@ class ComponentWithUrlBoundProps
4040
#[LiveProp(fieldName: 'field6', url: true)]
4141
public ?string $prop6 = null;
4242

43-
#[LiveProp(url: new QueryMapping('q'))]
43+
#[LiveProp(url: new UrlMapping('q'))]
4444
public ?string $prop7 = null;
4545

46-
#[LiveProp(url: new QueryMapping('originalAlias'))]
46+
#[LiveProp(url: new UrlMapping('originalAlias'))]
4747
public ?string $prop8 = null;
4848

4949
use DefaultActionTrait;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ component('component_with_url_bound_props', {
22
'data-live-url-mapping-prop8': {
3-
'alias': 'customAlias'
3+
'as': 'customAlias'
44
}
55
}) }}

src/LiveComponent/tests/Functional/Metadata/LiveComponentMetadataFactoryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1515
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
16-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
16+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1717
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\ComponentWithUrlBoundProps;
1818

1919
class LiveComponentMetadataFactoryTest extends KernelTestCase
@@ -31,18 +31,18 @@ public function testQueryStringMapping()
3131
$propsMetadataByName[$propMetadata->getName()] = $propMetadata;
3232
}
3333

34-
$this->assertNotNull($propsMetadataByName['prop1']->queryStringMapping());
34+
$this->assertNotNull($propsMetadataByName['prop1']->urlMapping());
3535

36-
$this->assertNotNull($propsMetadataByName['prop2']->queryStringMapping());
36+
$this->assertNotNull($propsMetadataByName['prop2']->urlMapping());
3737

38-
$this->assertNotNull($propsMetadataByName['prop3']->queryStringMapping());
38+
$this->assertNotNull($propsMetadataByName['prop3']->urlMapping());
3939

40-
$this->assertNull($propsMetadataByName['prop4']->queryStringMapping());
40+
$this->assertNull($propsMetadataByName['prop4']->urlMapping());
4141

42-
$this->assertNotNull($propsMetadataByName['prop5']->queryStringMapping());
42+
$this->assertNotNull($propsMetadataByName['prop5']->urlMapping());
4343

44-
$this->assertNotNull($propsMetadataByName['prop6']->queryStringMapping());
44+
$this->assertNotNull($propsMetadataByName['prop6']->urlMapping());
4545

46-
$this->assertEquals(new QueryMapping(alias: 'q'), $propsMetadataByName['prop7']->queryStringMapping());
46+
$this->assertEquals(new UrlMapping(as: 'q'), $propsMetadataByName['prop7']->urlMapping());
4747
}
4848
}

src/LiveComponent/tests/Unit/Metadata/QueryMappingTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace Symfony\UX\LiveComponent\Tests\Unit\Metadata;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\UX\LiveComponent\Metadata\QueryMapping;
15+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1616

1717
class QueryMappingTest extends TestCase
1818
{
1919
public function testMerge()
2020
{
21-
$mapping = new QueryMapping();
21+
$mapping = new UrlMapping();
2222

23-
$merged = $mapping->merge(new QueryMapping('foo'));
23+
$merged = $mapping->merge(new UrlMapping('foo'));
2424

25-
$this->assertEquals('foo', $merged->getAlias());
25+
$this->assertEquals('foo', $merged->getAs());
2626
}
2727
}

src/LiveComponent/tests/Unit/Util/QueryMappingAttributeUtilsTest.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)