-
-
Notifications
You must be signed in to change notification settings - Fork 867
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
fix(laravel): allow serializer attributes through ApiProperty #6680
base: 4.0
Are you sure you want to change the base?
Conversation
soyuka
commented
Sep 27, 2024
Q | A |
---|---|
Branch? | 4.0 (new metadata feature but a bug fix for laravel) |
License | MIT |
Doc PR | required? |
ed1ed40
to
6d39500
Compare
...Laravel/Eloquent/Metadata/Factory/Property/EloquentPropertyNameCollectionMetadataFactory.php
Show resolved
Hide resolved
src/Metadata/ApiProperty.php
Outdated
* @param Type[] $builtinTypes | ||
* @param string|null $uriTemplate (experimental) whether to return the subRessource collection IRI instead of an iterable of IRI | ||
* @param string|null $property The property name | ||
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize |
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.
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize | |
* @param array<int, Context|DiscriminatorMap|Groups|Ignore|MaxDepth|SerializedName|SerializedPath> $serialize |
(Context
and DiscriminatorMap
are missing, and sort in alphabetical order)
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.
DiscriminatorMap
is a class
attribute only
src/Metadata/ApiProperty.php
Outdated
} | ||
|
||
/** | ||
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize |
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.
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize | |
* @param array<int, Context|DiscriminatorMap|Groups|Ignore|MaxDepth|SerializedName|SerializedPath> $serialize |
@@ -47,7 +47,8 @@ final class XmlPropertyAdapter implements PropertyAdapterInterface | |||
'property', | |||
]; | |||
|
|||
private const EXCLUDE = ['policy']; | |||
# Laravel only, we don't need xml support |
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.
# Laravel only, we don't need xml support | |
# Laravel only, we don't need XML support |
$classGroups = []; | ||
$classContextAnnotation = null; | ||
|
||
// It's very weird to grab an eloquent's properties in that case as they're never serialized |
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.
// It's very weird to grab an eloquent's properties in that case as they're never serialized | |
// It's very weird to grab Eloquent's properties in that case as they're never serialized |
if ($attr instanceof Groups) { | ||
foreach ($attr->getGroups() as $group) { | ||
$attributesMetadata[$propertyName]->addGroup($group); | ||
} | ||
} elseif ($attr instanceof MaxDepth) { | ||
$attributesMetadata[$propertyName]->setMaxDepth($attr->getMaxDepth()); | ||
} elseif ($attr instanceof SerializedName) { | ||
$attributesMetadata[$propertyName]->setSerializedName($attr->getSerializedName()); | ||
} elseif ($attr instanceof SerializedPath) { | ||
$attributesMetadata[$propertyName]->setSerializedPath($attr->getSerializedPath()); | ||
} elseif ($attr instanceof Ignore) { | ||
$attributesMetadata[$propertyName]->setIgnore(true); | ||
} elseif ($attr instanceof Context) { | ||
$this->setAttributeContextsForGroups($attr, $attributesMetadata[$propertyName]); | ||
} |
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.
match
?
(I guess this comes from Symfony, if you want to keep the code as-is to facilitate backporting the code if it changes upstream it's ok too, but please add a comment linking to the original source in this case)