Once populated, ClassMetadata instances are usually cached in a serialized form. IMPORTANT NOTE: The fields of this class are only public for 2 reasons: 1) To allow fast READ access. 2) To drastically reduce the size of a serialized instance (private/protected members get the whole class name, namespace inclusive, prepended to every property in the serialized representation).
Since: 2.0
Author: Jonathan H. Wage (jonwage@gmail.com)
Author: Richard Fullmer (richard.fullmer@opensoftdev.com)
Inheritance: extends ClassMetadataInfo
 /**
  * @depends testEntityXmlName
  * @param \Doctrine\OXM\Mapping\ClassMetadata $class
  */
 public function testNamespaces($class)
 {
     $this->assertEquals(2, count($class->getXmlNamespaces()));
     $this->assertContains(array('url' => 'http://www.schema.com/foo', 'prefix' => 'foo'), $class->getXmlNamespaces());
     $this->assertContains(array('url' => 'http://www.schema.com/bar', 'prefix' => 'bar'), $class->getXmlNamespaces());
     return $class;
 }
Example #2
0
 /**
  * Generates the code for the __sleep method for a proxy class.
  *
  * @param $class
  * @return string
  */
 private function generateSleep(ClassMetadata $class)
 {
     $sleepImpl = '';
     if ($class->reflClass->hasMethod('__sleep')) {
         $sleepImpl .= 'return parent::__sleep();';
     } else {
         $sleepImpl .= 'return array(';
         $first = true;
         foreach ($class->getReflectionProperties() as $name => $prop) {
             if ($first) {
                 $first = false;
             } else {
                 $sleepImpl .= ', ';
             }
             $sleepImpl .= "'" . $name . "'";
         }
         $sleepImpl .= ');';
     }
     return $sleepImpl;
 }
 /**
  * Adds inherited fields to the subclass mapping.
  *
  * @param ClassMetadata $subClass
  * @param ClassMetadata $parentClass
  */
 private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass)
 {
     foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
         if (!isset($mapping['inherited']) && !$parentClass->isMappedSuperclass) {
             $mapping['inherited'] = $parentClass->name;
         }
         if (!isset($mapping['declared'])) {
             $mapping['declared'] = $parentClass->name;
         }
         $subClass->addInheritedFieldMapping($mapping);
     }
     foreach ($parentClass->reflFields as $name => $field) {
         $subClass->reflFields[$name] = $field;
     }
 }
Example #4
0
 /**
  * @param WriterHelper $writer
  * @param ClassMetadata $classMetadata
  * @param string $fieldName
  * @param mixed $fieldValue
  */
 private function _writeElement(WriterHelper $writer, ClassMetadata $classMetadata, $fieldName, $fieldValue)
 {
     $fieldType = $classMetadata->getTypeOfField($fieldName);
     if ($this->classMetadataFactory->hasMetadataFor($fieldType)) {
         if ($classMetadata->isCollection($fieldName)) {
             foreach ($fieldValue as $value) {
                 $this->doMarshal($value, $writer);
             }
         } else {
             $this->doMarshal($fieldValue, $writer);
         }
     }
 }
Example #5
0
 /**
  * @param \Doctrine\OXM\Mapping\ClassMetadata $class
  * @param  $xmlEntity
  * @return void
  */
 private function persistNew($class, $xmlEntity)
 {
     $oid = spl_object_hash($xmlEntity);
     if (isset($class->lifecycleCallbacks[Events::prePersist])) {
         $class->invokeLifecycleCallbacks(Events::prePersist, $xmlEntity);
     }
     if ($this->evm->hasListeners(Events::prePersist)) {
         $this->evm->dispatchEvent(Events::prePersist, new Event\LifecycleEventArgs($xmlEntity, $this->xem));
     }
     $idGen = $class->idGenerator;
     if (!$idGen->isPostInsertGenerator()) {
         $idValue = $idGen->generate($this->xem, $xmlEntity);
         if (!$idGen instanceof \Doctrine\OXM\Id\AssignedGenerator) {
             $this->entityIdentifiers[$oid] = array($class->identifier => $idValue);
             $class->setIdentifierValue($xmlEntity, $this->entityIdentifiers[$oid]);
         } else {
             $this->entityIdentifiers[$oid] = $idValue;
         }
     }
     $this->entityStates[$oid] = self::STATE_MANAGED;
     $this->scheduleForInsert($xmlEntity);
 }
Example #6
0
 /**
  * @param WriterHelper $writer
  * @param ClassMetadata $classMetadata
  * @param string $fieldName
  * @param mixed $fieldValue
  */
 private function writeElement(WriterHelper $writer, ClassMetadata $classMetadata, $fieldName, $fieldValue)
 {
     $fieldType = $classMetadata->getTypeOfField($fieldName);
     $mapping = $classMetadata->getFieldMapping($fieldName);
     $prefix = isset($mapping['prefix']) ? $mapping['prefix'] : null;
     if ($this->classMetadataFactory->hasMetadataFor($fieldType)) {
         if ($classMetadata->isCollection($fieldName)) {
             if ($classMetadata->hasFieldWrapping($fieldName)) {
                 $writer->startElement($mapping['wrapper'], $prefix);
             }
             foreach ($fieldValue as $value) {
                 $this->doMarshal($value, $writer);
             }
             if ($classMetadata->hasFieldWrapping($fieldName)) {
                 $writer->endElement();
             }
         } else {
             $this->doMarshal($fieldValue, $writer);
         }
     }
 }
Example #7
0
 public function delete($xmlEntity, array $options = array())
 {
     return $this->storage->delete($this->metadata, $this->metadata->getIdentifierValue($xmlEntity));
 }
Example #8
0
 /**
  * Returns the class name of the object managed by the repository
  *
  * @return string
  */
 function getClassName()
 {
     return $this->class->getName();
 }