コード例 #1
0
 /**
  * Event triggered during metadata loading
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $this->classMetadata = $eventArgs->getClassMetadata();
     $reflectionClass = $this->classMetadata->getReflectionClass();
     if (null === $reflectionClass) {
         return;
     }
     if ($this->hasMethod($reflectionClass, 'updateTimestamps')) {
         $this->addLifecycleCallbacks();
         $this->mapFields();
     }
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         if ($timestampable = $this->reader->getPropertyAnnotation($property, self::TIMESTAMPABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
             }
             if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
                 throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
             }
             if ($timestampable->on == 'change') {
                 if (!isset($timestampable->field) || !isset($timestampable->value)) {
                     throw new InvalidMappingException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$meta->name}");
                 }
                 $field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
             }
             // properties are unique and mapper checks that, no risk here
             $config[$timestampable->on][] = $field;
         }
     }
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // position
         if ($position = $this->reader->getPropertyAnnotation($property, self::POSITION)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'position' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['position'] = $field;
         }
         // group
         if ($group = $this->reader->getPropertyAnnotation($property, self::GROUP)) {
             $field = $property->getName();
             if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
                 throw new InvalidMappingException("Unable to find 'group' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!isset($config['groups'])) {
                 $config['groups'] = array();
             }
             $config['groups'][] = $field;
         }
     }
 }
コード例 #4
0
 /**
  * @param ClassMetadata $metadata
  *
  * @return bool
  */
 protected function isResource(ClassMetadata $metadata)
 {
     if (!($reflClass = $metadata->getReflectionClass())) {
         return false;
     }
     return $reflClass->implementsInterface(PersistableInterface::class);
 }
コード例 #5
0
ファイル: ProxyLogicTest.php プロジェクト: sanborino/clinica
 public function testInitializedProxyUnserialization()
 {
     // persister will retrieve the lazy object itself, so that we don't have to re-define all field values
     $this->proxyLoader->expects($this->once())->method('load')->will($this->returnValue($this->lazyObject));
     $this->lazyObject->__setInitializer($this->getSuggestedInitializerImplementation());
     $this->lazyObject->__load();
     $serialized = serialize($this->lazyObject);
     $reflClass = $this->lazyLoadableObjectMetadata->getReflectionClass();
     /* @var $unserialized LazyLoadableObject|Proxy */
     $unserialized = unserialize($serialized);
     $this->assertTrue($unserialized->__isInitialized(), 'serialization didn\'t cause intialization');
     // Checking transient fields
     $this->assertSame('publicTransientFieldValue', $unserialized->publicTransientField, 'transient fields are kept');
     $protectedTransientField = $reflClass->getProperty('protectedTransientField');
     $protectedTransientField->setAccessible(true);
     $this->assertSame('protectedTransientFieldValue', $protectedTransientField->getValue($unserialized), 'transient fields are kept');
     // Checking persistent fields
     $this->assertSame('publicPersistentFieldValue', $unserialized->publicPersistentField, 'persistent fields are kept');
     $protectedPersistentField = $reflClass->getProperty('protectedPersistentField');
     $protectedPersistentField->setAccessible(true);
     $this->assertSame('protectedPersistentFieldValue', $protectedPersistentField->getValue($unserialized), 'persistent fields are kept');
     // Checking identifiers
     $this->assertSame('publicIdentifierFieldValue', $unserialized->publicIdentifierField, 'identifiers are kept');
     $protectedIdentifierField = $reflClass->getProperty('protectedIdentifierField');
     $protectedIdentifierField->setAccessible(true);
     $this->assertSame('protectedIdentifierFieldValue', $protectedIdentifierField->getValue($unserialized), 'identifiers are kept');
     // Checking associations
     $this->assertSame('publicAssociationValue', $unserialized->publicAssociation, 'associations are kept');
     $protectedAssociationField = $reflClass->getProperty('protectedAssociation');
     $protectedAssociationField->setAccessible(true);
     $this->assertSame('protectedAssociationValue', $protectedAssociationField->getValue($unserialized), 'associations are kept');
 }
コード例 #6
0
ファイル: Annotation.php プロジェクト: GrifiS/Symfony2CMS
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     $config['fields'] = array();
     $config['fields_delete'] = array();
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         $field = null;
         if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
             $field['name'] = $property->getName();
             $field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
             if (!$meta->hasField($field['name'])) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
         }
         // if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
         //
         // $config['fields_delete'][] = $property->getName();
         //
         // }
         if ($field) {
             $config['fields'][] = $field;
         }
     }
 }
コード例 #7
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
         $config['loggable'] = true;
         if ($annot->logEntryClass) {
             if (!class_exists($annot->logEntryClass)) {
                 throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
             }
             $config['logEntryClass'] = $annot->logEntryClass;
         }
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // versioned property
         if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
             $field = $property->getName();
             if ($meta->isCollectionValuedAssociation($field)) {
                 throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['versioned'][] = $field;
         }
     }
 }
コード例 #8
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Entity');
     if (!$entityAnnot) {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     $metadata->storageName = $entityAnnot->storageName;
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         $idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Id');
         $transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Transient');
         if ($idAnnot) {
             $metadata->mapIdentifier($property->getName());
         } elseif ($transientAnnot) {
             $metadata->skipTransientField($property->getName());
         } else {
             $metadata->mapField(['fieldName' => $property->getName()]);
         }
     }
 }
コード例 #9
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  * @throws \Doctrine\ORM\ODMAdapter\Exception\MappingException
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $class \Doctrine\ORM\ODMAdapter\Mapping\ClassMetadata */
     $reflClass = $metadata->getReflectionClass();
     $documentAnnots = array();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
         foreach ($this->entityAnnotationClasses as $annotClass => $i) {
             if ($annot instanceof $annotClass) {
                 $documentAnnots[$i] = $annot;
             }
         }
     }
     if (!$documentAnnots) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     $metadata->className = $className;
     foreach ($reflClass->getProperties() as $property) {
         if ($metadata->className !== $property->getDeclaringClass()->getName()) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         foreach ($this->reader->getPropertyAnnotations($property) as $propertyAnnotation) {
             if ($propertyAnnotation instanceof Adapter\ReferencePhpcr) {
                 $mapping['type'] = Reference::PHPCR;
                 $this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
             }
             if ($propertyAnnotation instanceof Adapter\ReferenceDbalOrm) {
                 $mapping['type'] = Reference::DBAL_ORM;
                 $this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
             }
         }
     }
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $class ClassMetadataInfo */
     $reflClass = $metadata->getReflectionClass();
     if ($entityAnnot = $this->reader->getClassAnnotation($reflClass, 'Pasinter\\OHM\\Mapping\\Annotations\\Entity')) {
         $metadata->database = $entityAnnot->database;
     }
     // Evaluate annotations on properties/fields
     foreach ($reflClass->getProperties() as $property) {
         if ($fieldAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Field')) {
             $mapping = $this->fieldToArray($property->getName(), $fieldAnnot);
             if ($this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Id')) {
                 $mapping['id'] = true;
             }
             $metadata->mapField($mapping);
         } elseif ($referenceOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceOne')) {
             $mapping = $this->referenceOneToArray($property->getName(), $referenceOneAnnot);
             $metadata->mapOneReference($mapping);
         } elseif ($referenceManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceMany')) {
             $mapping = $this->referenceManyToArray($property->getName(), $referenceManyAnnot);
             $metadata->mapManyReference($mapping);
         } elseif ($embedOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedOne')) {
             $mapping = $this->embedOneToArray($property->getName(), $embedOneAnnot);
             $metadata->mapOneEmbed($mapping);
         } elseif ($embedManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedMany')) {
             $mapping = $this->embedManyToArray($property->getName(), $embedManyAnnot);
             $metadata->mapManyEmbed($mapping);
         }
     }
 }
コード例 #11
0
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     // load our available annotations
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     // set annotation namespace and alias
     //$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
     $class = $meta->getReflectionClass();
     // check only property annotations
     foreach ($class->getProperties() as $property) {
         // skip inherited properties
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // now lets check if property has our annotation
         if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
             $field = $property->getName();
             // check if field is mapped
             if (!$meta->hasField($field)) {
                 throw new \Exception("Field is not mapped as object property");
             }
             // allow encoding only strings
             if (!in_array($encode->type, array('sha1', 'md5'))) {
                 throw new \Exception("Invalid encoding type supplied");
             }
             // validate encoding type
             $mapping = $meta->getFieldMapping($field);
             if ($mapping['type'] != 'string') {
                 throw new \Exception("Only strings can be encoded");
             }
             // store the metadata
             $config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
         }
     }
 }
コード例 #12
0
 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array  $data
  * @param  object $object
  * @throws \Exception
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $this->metadata = $this->objectManager->getClassMetadata(get_class($object));
     $object = $this->tryConvertArrayToObject($data, $object);
     foreach ($data as $field => &$value) {
         $value = $this->hydrateValue($field, $value);
         if ($value === null) {
             continue;
         }
         // @todo DateTime (and other types) conversion should be handled by doctrine itself in future
         if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
             if (is_int($value)) {
                 $dt = new DateTime();
                 $dt->setTimestamp($value);
                 $value = $dt;
             } elseif (is_string($value)) {
                 $value = new DateTime($value);
             }
         }
         if ($this->metadata->hasAssociation($field)) {
             $target = $this->metadata->getAssociationTargetClass($field);
             if ($this->metadata->isSingleValuedAssociation($field)) {
                 $value = $this->toOne($value, $target);
             } elseif ($this->metadata->isCollectionValuedAssociation($field)) {
                 $value = $this->toMany($value, $target);
                 // Automatically merge collections using helper utility
                 $propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
                 $propertyRefl->setAccessible(true);
                 $previousValue = $propertyRefl->getValue($object);
                 $value = CollectionUtils::intersectUnion($previousValue, $value);
             }
         }
     }
     return $this->hydrator->hydrate($data, $object);
 }
コード例 #13
0
 protected function appendConfigurationFromMetadata(ClassMetadata $metadata, &$configuration)
 {
     $serializationFilePath = $this->resolvePath($metadata->getReflectionClass());
     if ($this->filesystem->exists($serializationFilePath)) {
         $content = file_get_contents($serializationFilePath);
         $configuration = array_replace_recursive($configuration, $this->parseContent($content));
     }
 }
コード例 #14
0
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // slug property
         if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
             }
             // process slug handlers
             $handlers = array();
             if (is_array($slug->handlers) && $slug->handlers) {
                 foreach ($slug->handlers as $handler) {
                     if (!$handler instanceof SlugHandler) {
                         throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
                     }
                     if (!strlen($handler->class)) {
                         throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
                     }
                     $class = $handler->class;
                     $handlers[$class] = array();
                     foreach ((array) $handler->options as $option) {
                         if (!$option instanceof SlugHandlerOption) {
                             throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
                         }
                         if (!strlen($option->name)) {
                             throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
                         }
                         $handlers[$class][$option->name] = $option->value;
                     }
                     $class::validate($handlers[$class], $meta);
                 }
             }
             // process slug fields
             if (empty($slug->fields) || !is_array($slug->fields)) {
                 throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
             }
             foreach ($slug->fields as $slugField) {
                 if (!$meta->hasField($slugField)) {
                     throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->isValidField($meta, $slugField)) {
                     throw new InvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
                 }
             }
             // set all options
             $config['slugs'][$field] = array('fields' => $slug->fields, 'slug' => $field, 'style' => $slug->style, 'updatable' => $slug->updatable, 'unique' => $slug->unique, 'separator' => $slug->separator, 'handlers' => $handlers);
         }
     }
 }
コード例 #15
0
ファイル: ORM.php プロジェクト: coolms/doctrine
 /**
  * {@inheritDoc}
  */
 public function mapTranslation(ClassMetadata $meta, $translatableClassName)
 {
     $rc = $meta->getReflectionClass();
     if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
         return;
     }
     $namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
     $meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
 }
コード例 #16
0
 public function testLoadClassMetadata()
 {
     $this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
     $this->classMetadata->getReflectionClass()->willReturn($this->refl->reveal());
     $this->refl->implementsInterface('Sulu\\Component\\Persistence\\Model\\UserBlameInterface')->willReturn(true);
     $this->classMetadata->hasAssociation('creator')->shouldBeCalled();
     $this->classMetadata->hasAssociation('changer')->shouldBeCalled();
     $this->classMetadata->mapManyToOne(Argument::any())->shouldBeCalled();
     $this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
 }
コード例 #17
0
ファイル: DoctrineObject.php プロジェクト: eltondias/Relogio
 /**
  * Extract values from an object using a by-reference logic (this means that values are
  * directly fetched without using the public API of the entity, in this case, getters)
  *
  * @param  object $object
  * @return array
  */
 protected function extractByReference($object)
 {
     $fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     $refl = $this->metadata->getReflectionClass();
     $data = array();
     foreach ($fieldNames as $fieldName) {
         $reflProperty = $refl->getProperty($fieldName);
         $reflProperty->setAccessible(true);
         $data[$fieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object));
     }
     return $data;
 }
コード例 #18
0
 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     if (!isset($meta['defaultValues'])) {
         $meta['defaultValues'] = [];
     }
     foreach ($doctrineMeta->getReflectionClass()->getProperties() as $reflectionProperty) {
         $defaultValueAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, DefaultValue::ANNOTATION);
         if ($defaultValueAnnotation instanceof DefaultValue) {
             $meta['defaultValues'][$reflectionProperty->getName()] = $defaultValueAnnotation->sourcePropertyPath;
         }
     }
 }
コード例 #19
0
ファイル: AnnotationDriver.php プロジェクト: doctrine/search
 /**
  * @param string $className
  * @param ClassMetadata|\Doctrine\Search\Mapping\ClassMetadata $metadata
  *
  * @throws \ReflectionException
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         $class = new \ReflectionClass((string) $className);
     }
     $classAnnotations = $this->reader->getClassAnnotations($class);
     $classMapping = array();
     $validMapping = false;
     foreach ($classAnnotations as $annotation) {
         switch (get_class($annotation)) {
             case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticSearchable':
                 $classMapping = (array) $annotation;
                 $classMapping['class'] = 'ElasticSearchable';
                 $validMapping = true;
                 break;
             case 'Doctrine\\Search\\Mapping\\Annotations\\Searchable':
                 $classMapping = (array) $annotation;
                 $classMapping['class'] = 'Searchable';
                 $validMapping = true;
                 break;
             case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticRoot':
                 $rootMapping = (array) $annotation;
                 $metadata->mapRoot($this->rootToArray($rootMapping));
                 break;
         }
     }
     if (!$validMapping) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     $this->annotateClassMetadata($classMapping, $metadata);
     $properties = $class->getProperties();
     foreach ($properties as $property) {
         $propertyAnnotations = $this->reader->getPropertyAnnotations($property);
         foreach ($propertyAnnotations as $annotation) {
             switch (get_class($annotation)) {
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Id':
                     $metadata->identifier = $property->getName();
                     break;
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Parameter':
                     $mapping = $this->parameterToArray($property->getName(), (array) $annotation);
                     $metadata->mapParameter($mapping);
                     break;
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Field':
                 case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticField':
                 case 'Doctrine\\Search\\Mapping\\Annotations\\SolrField':
                     $mapping = $this->fieldToArray($property->getName(), (array) $annotation);
                     $metadata->mapField($mapping);
                     break;
             }
         }
     }
 }
コード例 #20
0
 /**
  * @param string $className
  * @param ClassMetadata|\Revinate\SearchBundle\Lib\Search\Mapping\ClassMetadata $metadata
  *
  * @throws \ReflectionException
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     if (!$reflClass) {
         $reflClass = new \ReflectionClass((string) $className);
     }
     $reflProperties = $reflClass->getProperties();
     $reflMethods = $reflClass->getMethods();
     $this->extractClassAnnotations($reflClass, $metadata);
     $this->extractPropertiesAnnotations($reflProperties, $metadata);
     $this->extractMethodsAnnotations($reflMethods, $metadata);
 }
コード例 #21
0
ファイル: ORM.php プロジェクト: coolms/doctrine
 /**
  * {@inheritDoc}
  */
 public function mapHierarchy(ClassMetadata $meta)
 {
     if ($meta->isMappedSuperclass || !$meta->isRootEntity()) {
         return;
     }
     $rc = $meta->getReflectionClass();
     if ($rc->hasProperty('parent') && !$meta->hasAssociation('parent')) {
         $meta->mapManyToOne(['targetEntity' => $meta->getName(), 'fieldName' => 'parent', 'inversedBy' => 'children', 'cascade' => ['persist']]);
     }
     if ($rc->hasProperty('children') && !$meta->hasAssociation('children')) {
         $meta->mapOneToMany(['targetEntity' => $meta->getName(), 'fieldName' => 'children', 'mappedBy' => 'parent', 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY']);
     }
 }
コード例 #22
0
ファイル: MainSubscriber.php プロジェクト: zoopcommerce/shard
 protected function processMethodAnnotations(ClassMetadata $source, ClassMetadata $target, $annotationReader, $eventManager)
 {
     $sourceReflClass = $source->getReflectionClass();
     //Method annotations
     foreach ($sourceReflClass->getMethods() as $reflMethod) {
         foreach ($annotationReader->getMethodAnnotations($reflMethod) as $annotation) {
             if (defined(get_class($annotation) . '::EVENT')) {
                 // Raise annotation event
                 $eventManager->dispatchEvent($annotation::EVENT, new AnnotationEventArgs($target, EventType::METHOD, $annotation, $reflMethod, $eventManager));
             }
         }
     }
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     if (!isset($meta['customObjects'])) {
         $meta['customObjects'] = [];
     }
     foreach ($doctrineMeta->getReflectionClass()->getProperties() as $reflectionProperty) {
         $customObjectAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, CustomObject::ANNOTATION);
         if (!$customObjectAnnotation instanceof CustomObject) {
             continue;
         }
         $this->validateAnnotation($customObjectAnnotation, $doctrineMeta->getName(), $reflectionProperty->getName());
         $meta['customObjects'][$reflectionProperty->getName()] = get_object_vars($customObjectAnnotation);
     }
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     if (!isset($meta['transliteratable'])) {
         $meta['transliteratable'] = [];
     }
     foreach ($doctrineMeta->getReflectionClass()->getProperties() as $reflectionProperty) {
         $transliteratableAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Transliteratable::ANNOTATION);
         if ($transliteratableAnnotation instanceof Transliteratable) {
             if (!$doctrineMeta->hasField($reflectionProperty->getName())) {
                 throw $this->createPropertyAnnotationInvalidException(Transliteratable::ANNOTATION, $doctrineMeta->getName(), $reflectionProperty->getName(), 'property must be mapped field');
             }
             $meta['transliteratable'][$reflectionProperty->getName()] = get_object_vars($transliteratableAnnotation);
         }
     }
 }
コード例 #25
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $metadata->hasEncryptedProperties = false;
     $metadata->encryptedProperties = array();
     $class = $metadata->getReflectionClass();
     foreach ($class->getProperties() as $name => $property) {
         /** @var \Giftcards\Encryption\Doctrine\Configuration\Annotation\Encrypted $annotation */
         $annotation = $this->reader->getPropertyAnnotation($property, 'Giftcards\\Encryption\\Doctrine\\Configuration\\Annotation\\Encrypted');
         if (!$annotation) {
             continue;
         }
         $metadata->hasEncryptedProperties = true;
         $metadata->encryptedProperties[$property->getName()] = array('profile' => $annotation->profile);
     }
 }
コード例 #26
0
 /**
  * Extract values from an object using a by-reference logic (this means that values are
  * directly fetched without using the public API of the entity, in this case, getters)
  *
  * @param  object $object
  * @return array
  */
 protected function extractByReference($object)
 {
     $fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     $refl = $this->metadata->getReflectionClass();
     $filter = $object instanceof FilterProviderInterface ? $object->getFilter() : $this->filterComposite;
     $data = array();
     foreach ($fieldNames as $fieldName) {
         if ($filter && !$filter->filter($fieldName)) {
             continue;
         }
         $reflProperty = $refl->getProperty($fieldName);
         $reflProperty->setAccessible(true);
         $data[$fieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object), $object);
     }
     return $data;
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     if (!isset($meta['slugs'])) {
         $meta['slugs'] = [];
     }
     foreach ($doctrineMeta->getReflectionClass()->getProperties() as $reflectionProperty) {
         $slugAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Slug::ANNOTATION);
         if ($slugAnnotation instanceof Slug) {
             $this->validateAnnotation($slugAnnotation, $doctrineMeta->getName(), $reflectionProperty->getName());
             $meta['slugs'][$reflectionProperty->getName()] = get_object_vars($slugAnnotation);
             if (!empty($slugAnnotation->prefixProvider)) {
                 $meta['slugs'][$reflectionProperty->getName()]['prefixProvider'] = get_object_vars($slugAnnotation->prefixProvider);
             }
         }
     }
 }
コード例 #28
0
ファイル: Annotation.php プロジェクト: GrifiS/Symfony2CMS
 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         if ($demo = $this->reader->getPropertyAnnotation($property, self::DEMO)) {
             $field = $property->getName();
             $value = $demo->text;
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
             $config['text'][] = array('field' => $field, 'value' => $value);
         }
     }
 }
コード例 #29
0
    /**
     * {@inheritDoc}
     */
    public function readExtendedMetadata(ClassMetadata $meta, array &$config) {
        $class = $meta->getReflectionClass();
        // property annotations
        foreach ($class->getProperties() as $property) {
            if ($meta->isMappedSuperclass && !$property->isPrivate() ||
                $meta->isInheritedField($property->name) ||
                isset($meta->associationMappings[$property->name]['inherited'])
            ) {
                continue;
            }
            // sluggable property
            if ($sluggable = $this->reader->getPropertyAnnotation($property, self::SLUGGABLE)) {
                $field = $property->getName();
                if (!$meta->hasField($field)) {
                    throw new InvalidMappingException("Unable to find sluggable [{$field}] as mapped property in entity - {$meta->name}");
                }
                if (!$this->isValidField($meta, $field)) {
                    throw new InvalidMappingException("Cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
                }
                if (!is_null($sluggable->slugField) and !$meta->hasField($sluggable->slugField)) {

                    throw new InvalidMappingException(sprintf('The "%s" property - which is defined as the "slugField" for the "%s" property - does not exist or is not mapped to Doctrine in "%s"', $sluggable->slugField, $field, $meta->name));
                }
                $config['fields'][$sluggable->slugField][] = array('field' => $field, 'position' => $sluggable->position, 'slugField' => $sluggable->slugField);
            }
            // slug property
            if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
                $field = $property->getName();
                if (!$meta->hasField($field)) {
                    throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
                }
                if (!$this->isValidField($meta, $field)) {
                    throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' in class - {$meta->name}");
                }

                $config['slugFields'][$field]['slug'] = $field;
                $config['slugFields'][$field]['style'] = $slug->style;
                $config['slugFields'][$field]['updatable'] = $slug->updatable;
                $config['slugFields'][$field]['unique'] = $slug->unique;
                $config['slugFields'][$field]['separator'] = $slug->separator;
            }
        }
    }
コード例 #30
0
 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     $reflectionClass = $doctrineMeta->getReflectionClass();
     $copyingPolicy = null;
     if (isset($meta['clonable'])) {
         $copyingPolicy = $meta['clonable']['copyingPolicy'];
     }
     $clonableAnnotation = $this->reader->getClassAnnotation($reflectionClass, Clonable::ANNOTATION);
     if ($clonableAnnotation instanceof Clonable) {
         $copyingPolicy = $clonableAnnotation->copyingPolicy;
     }
     if (empty($copyingPolicy)) {
         return;
     }
     if (!isset($meta['clonable'])) {
         $meta['clonable'] = [];
     }
     $meta['clonable']['copyingPolicy'] = $copyingPolicy;
     $properties = $this->getPropertiesToCopy($reflectionClass, $copyingPolicy, $doctrineMeta->getIdentifier());
     $meta['clonable']['properties'] = isset($meta['clonable']['properties']) ? array_merge($meta['clonable']['properties'], $properties) : $properties;
 }