예제 #1
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param CommonClassMetadata $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, CommonClassMetadata $metadata)
 {
     /** @var \Doctrine\KeyValueStore\Mapping\ClassMetadata $metadata */
     try {
         $element = $this->getElement($className);
     } catch (MappingException $exception) {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     $class = new \ReflectionClass($className);
     if (isset($element['storageName'])) {
         $metadata->storageName = $element['storageName'];
     }
     $ids = [];
     if (isset($element['id'])) {
         $ids = $element['id'];
     }
     $transients = [];
     if (isset($element['transient'])) {
         $transients = $element['transient'];
     }
     foreach ($class->getProperties() as $property) {
         if (in_array($property->getName(), $ids)) {
             $metadata->mapIdentifier($property->getName());
             continue;
         }
         if (in_array($property->getName(), $transients)) {
             $metadata->skipTransientField($property->getName());
             continue;
         }
         $metadata->mapField(array('fieldName' => $property->getName()));
     }
 }
 /**
  * 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()]);
         }
     }
 }
예제 #3
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param CommonClassMetadata $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, CommonClassMetadata $metadata)
 {
     try {
         $xmlRoot = $this->getElement($className);
     } catch (MappingException $exception) {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     if ($xmlRoot->getName() != 'entity') {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     $class = new \ReflectionClass($className);
     if (isset($xmlRoot['storage-name'])) {
         $metadata->storageName = $xmlRoot['storage-name'];
     }
     $ids = [];
     if (isset($xmlRoot->id)) {
         foreach ($xmlRoot->id as $id) {
             $ids[] = (string) $id;
         }
     }
     $transients = [];
     if (isset($xmlRoot->transient)) {
         foreach ($xmlRoot->transient as $transient) {
             $transients[] = (string) $transient;
         }
     }
     foreach ($class->getProperties() as $property) {
         if (in_array($property->getName(), $ids)) {
             $metadata->mapIdentifier($property->getName());
             continue;
         }
         if (in_array($property->getName(), $transients)) {
             $metadata->skipTransientField($property->getName());
             continue;
         }
         $metadata->mapField(array('fieldName' => $property->getName()));
     }
 }