|
@@ -22,6 +22,7 @@ use JMS\SerializerBundle\Exception\RuntimeException;
|
|
|
use JMS\SerializerBundle\Annotation\ExclusionPolicy;
|
|
|
use Metadata\MethodMetadata;
|
|
|
use JMS\SerializerBundle\Metadata\PropertyMetadata;
|
|
|
+use JMS\SerializerBundle\Metadata\VirtualPropertyMetadata;
|
|
|
use JMS\SerializerBundle\Metadata\ClassMetadata;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
use Metadata\Driver\AbstractFileDriver;
|
|
@@ -44,6 +45,8 @@ class YamlDriver extends AbstractFileDriver
|
|
|
$excludeAll = isset($config['exclude']) ? (Boolean) $config['exclude'] : false;
|
|
|
$classAccessType = isset($config['access_type']) ? $config['access_type'] : PropertyMetadata::ACCESS_TYPE_PROPERTY;
|
|
|
|
|
|
+ $propertiesMetadata = array();
|
|
|
+
|
|
|
if (isset($config['accessor_order'])) {
|
|
|
$metadata->setAccessorOrder($config['accessor_order'], isset($config['custom_accessor_order']) ? $config['custom_accessor_order'] : array());
|
|
|
}
|
|
@@ -52,13 +55,37 @@ class YamlDriver extends AbstractFileDriver
|
|
|
$metadata->xmlRootName = (string) $config['xml_root_name'];
|
|
|
}
|
|
|
|
|
|
+ if (array_key_exists('virtual_properties', $config) ) {
|
|
|
+
|
|
|
+ foreach ( $config['virtual_properties'] as $propertyName => $propertySettings ) {
|
|
|
+
|
|
|
+ if (!array_key_exists('method', $propertySettings)) {
|
|
|
+ throw new RuntimeException('The method must be set for all virtual_property elements');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( !$class->hasMethod( $propertySettings['method'] ) ) {
|
|
|
+ throw new RuntimeException('The method '.$propertySettings['method'].' not found in class ' . $class->name);
|
|
|
+ }
|
|
|
+
|
|
|
+ $virtualPropertyMetadata = new VirtualPropertyMetadata( $name, $propertyName );
|
|
|
+ $virtualPropertyMetadata->getter = (string) $propertySettings['method'];
|
|
|
+
|
|
|
+ $propertiesMetadata[$propertyName] = $virtualPropertyMetadata;
|
|
|
+ $config['properties'][$propertyName] = $propertySettings;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (!$excludeAll) {
|
|
|
foreach ($class->getProperties() as $property) {
|
|
|
if ($name !== $property->getDeclaringClass()->getName()) {
|
|
|
continue;
|
|
|
}
|
|
|
+ $pName = $property->getName();
|
|
|
+ $propertiesMetadata[$pName] = new PropertyMetadata($name, $pName);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($propertiesMetadata as $pName => $pMetadata) {
|
|
|
|
|
|
- $pMetadata = new PropertyMetadata($name, $pName = $property->getName());
|
|
|
$isExclude = $isExpose = false;
|
|
|
if (isset($config['properties'][$pName])) {
|
|
|
$pConfig = $config['properties'][$pName];
|