-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add support for auto generated custom normalizers #52905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nyholm
wants to merge
13
commits into
symfony:7.3
Choose a base branch
from
Nyholm:better-serializer
base: 7.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4e66fc1
[Serializer] Add support for auto generated custom normalizers
Nyholm fea6eeb
Fix some tests
Nyholm aaccb9d
fixed more tests
Nyholm a130539
cs
Nyholm 94ebc00
Use nikic/PHP-Parser
Nyholm d9be208
Generate new classes
Nyholm d10be79
cs
Nyholm 9475e96
CS
Nyholm 9ee662b
Only compare output on nikic/php-parser: 5
Nyholm 09f9bd4
Fix deps low
Nyholm 0d22403
Added some more tests
Nyholm 606e24e
Removed some tests
Nyholm 476baa0
CS
Nyholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorAggregate.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyInfo\Extractor; | ||
|
||
/** | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
class ConstructorArgumentTypeExtractorAggregate implements ConstructorArgumentTypeExtractorInterface | ||
{ | ||
/** | ||
* @param iterable<int, ConstructorArgumentTypeExtractorInterface> $extractors | ||
*/ | ||
public function __construct( | ||
private readonly iterable $extractors = [], | ||
) { | ||
} | ||
|
||
public function getTypesFromConstructor(string $class, string $property): ?array | ||
{ | ||
$output = []; | ||
foreach ($this->extractors as $extractor) { | ||
$value = $extractor->getTypesFromConstructor($class, $property); | ||
if (null !== $value) { | ||
$output[] = $value; | ||
} | ||
} | ||
|
||
if ([] === $output) { | ||
return null; | ||
} | ||
|
||
return array_merge([], ...$output); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore paths | ||
[Tests/CodeGenerator/Fixtures/**] | ||
trim_trailing_whitespace = false | ||
|
||
[Tests/Fixtures/CustomNormalizer/**/ExpectedNormalizer/**] | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false | ||
indent_size = unset | ||
indent_style = unset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml | ||
Tests/_output |
21 changes: 21 additions & 0 deletions
21
src/Symfony/Component/Serializer/Annotation/Serializable.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Annotation; | ||
|
||
class_exists(\Symfony\Component\Serializer\Attribute\Serializable::class); | ||
|
||
if (false) { | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class Serializable extends \Symfony\Component\Serializer\Attribute\Serializable | ||
{ | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Symfony/Component/Serializer/Attribute/Serializable.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Attribute; | ||
|
||
/** | ||
* Classes with this attribute will get a custom normalizer to improve speed when | ||
* serializing/deserializing. | ||
* | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class Serializable | ||
{ | ||
} | ||
|
||
if (!class_exists(\Symfony\Component\Serializer\Annotation\Serializable::class, false)) { | ||
class_alias(Serializable::class, \Symfony\Component\Serializer\Annotation\Serializable::class); | ||
} | ||
Nyholm marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Builder; | ||
|
||
/** | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
* | ||
* @experimental in 7.1 | ||
*/ | ||
class BuildResult | ||
{ | ||
public function __construct( | ||
// The full file location where the class is stored | ||
public readonly string $filePath, | ||
// Just the class name | ||
public readonly string $className, | ||
// Class name with namespace | ||
public readonly string $classNs, | ||
) { | ||
} | ||
|
||
public function loadClass(): void | ||
{ | ||
require_once $this->filePath; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan, you did this because it's used in another component? Just ignore the error for internal use between components it's fine no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is because I used it in another component.
Do you know the reason why it is internal in the first place?