/**
  * Get the object manager handling the specified class
  * Returns NULL if cannot be found
  *
  * @param ClassMetadata $metadata
  * @return null|ObjectManager
  */
 protected function getObjectManager(ClassMetadata $metadata)
 {
     foreach ($this->managerRegistryCollection as $managerRegistry) {
         if ($objectManager = $managerRegistry->getManagerForClass($metadata->getName())) {
             return $objectManager;
         }
     }
 }
Esempio n. 2
0
 protected function getClassAnnotations(ClassMetadata $classMetadata)
 {
     $config = $this->getClassConfig($classMetadata->getName());
     $annotations = [];
     foreach ($config as $key => $value) {
         if (in_array($key, ['properties', 'virtual_properties'])) {
             continue;
         }
         $annotations = array_merge($annotations, $this->createAnnotationsForArray($value, $key));
     }
     return $annotations;
 }
Esempio n. 3
0
 protected function getClassAnnotations(ClassMetadata $classMetadata)
 {
     $element = $this->getClassElement($classMetadata->getName());
     if (!$element) {
         return [];
     }
     $exclude = ['property', 'virtual-property', 'pre-serialize', 'post-serialize', 'post-deserialize', 'discriminator'];
     $annotations = $this->loadComplex($element, ['name'], $exclude);
     foreach ($element->xpath('./discriminator') as $discriminatorElement) {
         $discriminator = new Annotations\Discriminator();
         foreach ($this->loadAnnotationProperties($discriminatorElement) as $attrName => $value) {
             $discriminator->{$attrName} = $value;
         }
         $map = [];
         foreach ($discriminatorElement->xpath('./map') as $item) {
             $v = (string) $item->attributes()->value;
             $map[$v] = (string) $item;
         }
         $discriminator->map = $map;
         $annotations[] = $discriminator;
     }
     return $annotations;
 }
 public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, Type $type, DeserializationContext $context)
 {
     return $this->getInstantiator()->instantiate($metadata->getName());
 }
 /**
  * @param ClassMetadata $metadata
  * @param $properties
  */
 private function validateObjectProperties(ClassMetadata $metadata, $properties)
 {
     $has_xml_value = false;
     foreach ($properties as $property) {
         if ($property->xmlValue && !$has_xml_value) {
             $has_xml_value = true;
         } elseif ($property->xmlValue) {
             throw new RuntimeException(sprintf('Only one property can be target of @XmlValue attribute. Invalid usage detected in class %s', $metadata->getName()));
         }
     }
     if ($has_xml_value) {
         foreach ($properties as $property) {
             if (!$property->xmlValue && !$property->xmlAttribute) {
                 throw new RuntimeException(sprintf('If you make use of @XmlValue, all other properties in the class must have the @XmlAttribute annotation. Invalid usage detected in class %s.', $metadata->getName()));
             }
         }
     }
 }