-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Allow custom methods on property accesses #18016
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
Changes from 1 commit
af3a824
5b82237
00a26eb
e4aaac9
e46df98
5f206e6
94e6157
09707ad
d02d93a
748b894
688cbda
003efdb
dc5cacb
1a35d45
1e29523
7c6a79c
d0bd777
6b7eeff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -940,7 +940,7 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui | |
$serializerLoaders = array(); | ||
if (isset($config['enable_annotations']) && $config['enable_annotations']) { | ||
$annotationLoader = new Definition( | ||
'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader', | ||
\Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader::class, | ||
array(new Reference('annotation_reader')) | ||
); | ||
$annotationLoader->setPublic(false); | ||
|
@@ -954,15 +954,15 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui | |
$dirname = dirname($reflection->getFileName()); | ||
|
||
if (is_file($file = $dirname.'/Resources/config/property_access.xml')) { | ||
$definition = new Definition('Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader', array(realpath($file))); | ||
$definition = new Definition(\Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader::class, array(realpath($file))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a use statement to avoid having the FQCN here (same below). |
||
$definition->setPublic(false); | ||
|
||
$serializerLoaders[] = $definition; | ||
$container->addResource(new FileResource($file)); | ||
} | ||
|
||
if (is_file($file = $dirname.'/Resources/config/property_access.yml')) { | ||
$definition = new Definition('Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader', array(realpath($file))); | ||
$definition = new Definition(\Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader::class, array(realpath($file))); | ||
$definition->setPublic(false); | ||
|
||
$serializerLoaders[] = $definition; | ||
|
@@ -971,13 +971,13 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui | |
|
||
if (is_dir($dir = $dirname.'/Resources/config/property_access')) { | ||
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) { | ||
$definition = new Definition('Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader', array($file->getRealpath())); | ||
$definition = new Definition(\Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader::class, array($file->getRealpath())); | ||
$definition->setPublic(false); | ||
|
||
$serializerLoaders[] = $definition; | ||
} | ||
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) { | ||
$definition = new Definition('Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader', array($file->getRealpath())); | ||
$definition = new Definition(\Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader::class, array($file->getRealpath())); | ||
$definition->setPublic(false); | ||
|
||
$serializerLoaders[] = $definition; | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ | |
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class ClassMetadata implements ClassMetadataInterface | ||
class ClassMetadata | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -28,13 +28,13 @@ class ClassMetadata implements ClassMetadataInterface | |
public $name; | ||
|
||
/** | ||
* @var AttributeMetadataInterface[] | ||
* @var PropertyMetadata[] | ||
* | ||
* @internal This property is public in order to reduce the size of the | ||
* class' serialized representation. Do not access it. Use | ||
* {@link getAttributesMetadata()} instead. | ||
* {@link getPropertiesMetadata()} instead. | ||
*/ | ||
public $attributesMetadata = array(); | ||
public $propertiesMetadata = array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the name of this property and its getter is a bit weird. We have a collection of "property metadata". The plural of that shouldn't be "properties metadata". Unfortunately, the plural of "metadata" is still "metadata". Ideas? We could solve this like in the Validator component by adding two methods: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* @var \ReflectionClass | ||
|
@@ -52,45 +52,55 @@ public function __construct($class) | |
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Returns the name of the backing PHP class. | ||
* | ||
* @return string The name of the backing class. | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Adds an {@link AttributeMetadataInterface}. | ||
* | ||
* @param PropertyMetadata $propertyMetadata | ||
*/ | ||
public function addAttributeMetadata(AttributeMetadataInterface $attributeMetadata) | ||
public function addPropertyMetadata(PropertyMetadata $propertyMetadata) | ||
{ | ||
$this->attributesMetadata[$attributeMetadata->getName()] = $attributeMetadata; | ||
$this->propertiesMetadata[$propertyMetadata->getName()] = $propertyMetadata; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Gets the list of {@link PropertyMetadata}. | ||
* | ||
* @return PropertyMetadata[] | ||
*/ | ||
public function getAttributesMetadata() | ||
public function getPropertiesMetadata() | ||
{ | ||
return $this->attributesMetadata; | ||
return $this->propertiesMetadata; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Merges a {@link ClassMetadata} into the current one. | ||
* | ||
* @param ClassMetadata $classMetadata | ||
*/ | ||
public function merge(ClassMetadataInterface $classMetadata) | ||
public function merge(ClassMetadata $classMetadata) | ||
{ | ||
foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) { | ||
if (isset($this->attributesMetadata[$attributeMetadata->getName()])) { | ||
$this->attributesMetadata[$attributeMetadata->getName()]->merge($attributeMetadata); | ||
foreach ($classMetadata->getPropertiesMetadata() as $attributeMetadata) { | ||
if (isset($this->propertiesMetadata[$attributeMetadata->getName()])) { | ||
$this->propertiesMetadata[$attributeMetadata->getName()]->merge($attributeMetadata); | ||
} else { | ||
$this->addAttributeMetadata($attributeMetadata); | ||
$this->addPropertyMetadata($attributeMetadata); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Returns a {@link \ReflectionClass} instance for this class. | ||
* | ||
* @return \ReflectionClass | ||
*/ | ||
public function getReflectionClass() | ||
{ | ||
|
@@ -110,7 +120,7 @@ public function __sleep() | |
{ | ||
return array( | ||
'name', | ||
'attributesMetadata', | ||
'propertiesMetadata', | ||
); | ||
} | ||
} |
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.
please add a
use
statement for this class