Skip to content

Commit 6312b6f

Browse files
committed
rename attributes
1 parent be5dd55 commit 6312b6f

13 files changed

+61
-95
lines changed

src/Symfony/Component/SerDes/Attribute/Formatter.php renamed to src/Symfony/Component/SerDes/Attribute/DeserializeFormatter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
* @experimental in 7.0
1818
*/
1919
#[\Attribute(\Attribute::TARGET_PROPERTY)]
20-
final class Formatter
20+
final class DeserializeFormatter
2121
{
2222
/**
23-
* @param callable(mixed, array<string, mixed>=): mixed|null $onSerialize
24-
* @param callable(mixed, array<string, mixed>=): mixed|null $onDeserialize
23+
* @param callable(mixed, array<string, mixed>=): mixed|null $formatter
2524
*/
2625
public function __construct(
27-
public readonly mixed $onSerialize = null,
28-
public readonly mixed $onDeserialize = null,
26+
public readonly mixed $formatter,
2927
) {
3028
}
3129
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\SerDes\Attribute;
13+
14+
/**
15+
* @author Mathias Arlaud <[email protected]>
16+
*
17+
* @experimental in 7.0
18+
*/
19+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
20+
final class SerializeFormatter
21+
{
22+
/**
23+
* @param callable(mixed, array<string, mixed>=): mixed|null $formatter
24+
*/
25+
public function __construct(
26+
public readonly mixed $formatter,
27+
) {
28+
}
29+
}

src/Symfony/Component/SerDes/Attribute/Name.php renamed to src/Symfony/Component/SerDes/Attribute/SerializedName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @experimental in 7.0
1818
*/
1919
#[\Attribute(\Attribute::TARGET_PROPERTY)]
20-
final class Name
20+
final class SerializedName
2121
{
2222
public function __construct(
2323
public readonly string $name,

src/Symfony/Component/SerDes/Context/ContextBuilder/Deserialize/DeserializeFormatterAttributeContextBuilder.php

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

1212
namespace Symfony\Component\SerDes\Context\ContextBuilder\Deserialize;
1313

14-
use Symfony\Component\SerDes\Attribute\Formatter;
14+
use Symfony\Component\SerDes\Attribute\DeserializeFormatter;
1515
use Symfony\Component\SerDes\Context\ContextBuilder\DeserializeContextBuilderInterface;
1616
use Symfony\Component\SerDes\SerializableResolver\SerializableResolverInterface;
1717

@@ -60,18 +60,14 @@ private function propertyFormatters(string $className): array
6060

6161
foreach ((new \ReflectionClass($className))->getProperties() as $property) {
6262
foreach ($property->getAttributes() as $attribute) {
63-
if (Formatter::class !== $attribute->getName()) {
63+
if (DeserializeFormatter::class !== $attribute->getName()) {
6464
continue;
6565
}
6666

67-
/** @var Formatter $attributeInstance */
67+
/** @var DeserializeFormatter $attributeInstance */
6868
$attributeInstance = $attribute->newInstance();
6969

70-
if (null === $attributeInstance->onDeserialize) {
71-
break;
72-
}
73-
74-
$propertyFormatters[$property->getDeclaringClass()->getName()][$property->getName()] = $attributeInstance->onDeserialize;
70+
$propertyFormatters[$property->getDeclaringClass()->getName()][$property->getName()] = $attributeInstance->formatter;
7571

7672
break;
7773
}

src/Symfony/Component/SerDes/Context/ContextBuilder/Deserialize/DeserializeNameAttributeContextBuilder.php

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

1212
namespace Symfony\Component\SerDes\Context\ContextBuilder\Deserialize;
1313

14-
use Symfony\Component\SerDes\Attribute\Name;
14+
use Symfony\Component\SerDes\Attribute\SerializedName;
1515
use Symfony\Component\SerDes\Context\ContextBuilder\DeserializeContextBuilderInterface;
1616
use Symfony\Component\SerDes\SerializableResolver\SerializableResolverInterface;
1717

@@ -60,11 +60,11 @@ private function propertyNames(string $className): array
6060

6161
foreach ((new \ReflectionClass($className))->getProperties() as $property) {
6262
foreach ($property->getAttributes() as $attribute) {
63-
if (Name::class !== $attribute->getName()) {
63+
if (SerializedName::class !== $attribute->getName()) {
6464
continue;
6565
}
6666

67-
/** @var Name $attributeInstance */
67+
/** @var SerializedName $attributeInstance */
6868
$attributeInstance = $attribute->newInstance();
6969

7070
$propertyNames[$property->getDeclaringClass()->getName()][$attributeInstance->name] = $property->getName();

src/Symfony/Component/SerDes/Context/ContextBuilder/Serialize/SerializeFormatterAttributeContextBuilder.php

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

1212
namespace Symfony\Component\SerDes\Context\ContextBuilder\Serialize;
1313

14-
use Symfony\Component\SerDes\Attribute\Formatter;
14+
use Symfony\Component\SerDes\Attribute\SerializeFormatter;
1515
use Symfony\Component\SerDes\Context\ContextBuilder\SerializeContextBuilderInterface;
1616
use Symfony\Component\SerDes\SerializableResolver\SerializableResolverInterface;
1717

@@ -64,18 +64,14 @@ private function propertyFormatters(string $className): array
6464

6565
foreach ((new \ReflectionClass($className))->getProperties() as $property) {
6666
foreach ($property->getAttributes() as $attribute) {
67-
if (Formatter::class !== $attribute->getName()) {
67+
if (SerializeFormatter::class !== $attribute->getName()) {
6868
continue;
6969
}
7070

71-
/** @var Formatter $attributeInstance */
71+
/** @var SerializeFormatter $attributeInstance */
7272
$attributeInstance = $attribute->newInstance();
7373

74-
if (null === $attributeInstance->onSerialize) {
75-
break;
76-
}
77-
78-
$propertyFormatters[$property->getDeclaringClass()->getName()][$property->getName()] = $attributeInstance->onSerialize;
74+
$propertyFormatters[$property->getDeclaringClass()->getName()][$property->getName()] = $attributeInstance->formatter;
7975

8076
break;
8177
}

src/Symfony/Component/SerDes/Context/ContextBuilder/Serialize/SerializeNameAttributeContextBuilder.php

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

1212
namespace Symfony\Component\SerDes\Context\ContextBuilder\Serialize;
1313

14-
use Symfony\Component\SerDes\Attribute\Name;
14+
use Symfony\Component\SerDes\Attribute\SerializedName;
1515
use Symfony\Component\SerDes\Context\ContextBuilder\SerializeContextBuilderInterface;
1616
use Symfony\Component\SerDes\SerializableResolver\SerializableResolverInterface;
1717

@@ -64,11 +64,11 @@ private function propertyNames(string $className): array
6464

6565
foreach ((new \ReflectionClass($className))->getProperties() as $property) {
6666
foreach ($property->getAttributes() as $attribute) {
67-
if (Name::class !== $attribute->getName()) {
67+
if (SerializedName::class !== $attribute->getName()) {
6868
continue;
6969
}
7070

71-
/** @var Name $attributeInstance */
71+
/** @var SerializedName $attributeInstance */
7272
$attributeInstance = $attribute->newInstance();
7373

7474
$propertyNames[$property->getDeclaringClass()->getName()][$property->getName()] = $attributeInstance->name;

src/Symfony/Component/SerDes/Tests/Attribute/FormatterTest.php

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

src/Symfony/Component/SerDes/Tests/Fixtures/Dto/AnotherDummyWithFormatterAttributes.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Symfony\Component\SerDes\Tests\Fixtures\Dto;
44

5-
use Symfony\Component\SerDes\Attribute\Formatter;
5+
use Symfony\Component\SerDes\Attribute\DeserializeFormatter;
6+
use Symfony\Component\SerDes\Attribute\SerializeFormatter;
67

78
class AnotherDummyWithFormatterAttributes
89
{
910
public int $id = 1;
1011

11-
#[Formatter(
12-
onSerialize: [self::class, 'uppercase'],
13-
onDeserialize: [self::class, 'lowercase'],
14-
)]
12+
#[SerializeFormatter([self::class, 'uppercase'])]
13+
#[DeserializeFormatter([self::class, 'lowercase'])]
1514
public string $name = 'dummy';
1615

1716
public static function uppercase(string $value): string

src/Symfony/Component/SerDes/Tests/Fixtures/Dto/AnotherDummyWithNameAttributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Symfony\Component\SerDes\Tests\Fixtures\Dto;
44

5-
use Symfony\Component\SerDes\Attribute\Name;
5+
use Symfony\Component\SerDes\Attribute\SerializedName;
66

77
class AnotherDummyWithNameAttributes
88
{
99
public int $id = 1;
1010

11-
#[Name('call_me_with')]
11+
#[SerializedName('call_me_with')]
1212
public string $name = 'dummy';
1313
}

src/Symfony/Component/SerDes/Tests/Fixtures/Dto/DummyWithFormatterAttributes.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Symfony\Component\SerDes\Tests\Fixtures\Dto;
44

5-
use Symfony\Component\SerDes\Attribute\Formatter;
5+
use Symfony\Component\SerDes\Attribute\DeserializeFormatter;
6+
use Symfony\Component\SerDes\Attribute\SerializeFormatter;
67

78
class DummyWithFormatterAttributes
89
{
9-
#[Formatter(
10-
onSerialize: [self::class, 'doubleAndCastToString'],
11-
onDeserialize: [self::class, 'divideAndCastToInt'],
12-
)]
10+
#[SerializeFormatter([self::class, 'doubleAndCastToString'])]
11+
#[DeserializeFormatter([self::class, 'divideAndCastToInt'])]
1312
public int $id = 1;
1413

1514
public string $name = 'dummy';

src/Symfony/Component/SerDes/Tests/Fixtures/Dto/DummyWithNameAttributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Symfony\Component\SerDes\Tests\Fixtures\Dto;
44

5-
use Symfony\Component\SerDes\Attribute\Name;
5+
use Symfony\Component\SerDes\Attribute\SerializedName;
66

77
class DummyWithNameAttributes
88
{
9-
#[Name('@id')]
9+
#[SerializedName('@id')]
1010
public int $id = 1;
1111

1212
public string $name = 'dummy';

src/Symfony/Component/SerDes/Tests/Fixtures/Dto/DummyWithQuotes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Symfony\Component\SerDes\Tests\Fixtures\Dto;
44

5-
use Symfony\Component\SerDes\Attribute\Name;
5+
use Symfony\Component\SerDes\Attribute\SerializedName;
66

77
class DummyWithQuotes
88
{
9-
#[Name('"name"')]
9+
#[SerializedName('"name"')]
1010
public string $name = '"quoted" dummy';
1111
}

0 commit comments

Comments
 (0)