Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function collect(MvcEvent $mvcEvent)
 {
     if (!$this->classMetadataFactory) {
         return;
     }
     /* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata[] */
     $metadata = $this->classMetadataFactory->getAllMetadata();
     $this->classes = array();
     foreach ($metadata as $class) {
         $this->classes[$class->getName()] = $class;
     }
 }
 public function process(ClassMetadataFactory $factory, $data)
 {
     foreach ($factory->getAllMetadata() as $classMetadata) {
         $class = $classMetadata->getName();
         $data['entities'][$class] = array('associations' => array(), 'fields' => array());
         foreach ($classMetadata->fieldMappings as $name => $config) {
             $data['entities'][$class]['fields'][$name] = $config['type'];
         }
         // associations
         foreach ($classMetadata->getAssociationMappings() as $name => $mapping) {
             $field = $mapping['fieldName'];
             $targetEntity = $mapping['targetEntity'];
             $type = '';
             switch ($mapping['type']) {
                 case ClassMetadataInfo::ONE_TO_MANY:
                     $type = 'one_to_many';
                     break;
                 case ClassMetadataInfo::ONE_TO_ONE:
                     $type = 'one_to_one';
                     break;
                 case ClassMetadataInfo::MANY_TO_ONE:
                     $type = 'many_to_one';
                     break;
                 case ClassMetadataInfo::MANY_TO_MANY:
                     $type = 'many_to_many';
                     break;
                 default:
                     throw new \RuntimeException('Unkown association type ' . $mapping['type']);
             }
             $label = $targetEntity;
             if ($type == 'one_to_many' || $type == 'many_to_many') {
                 $label .= '[]';
             }
             $data['entities'][$class]['associations'][$field] = $label;
             if ($mapping['sourceEntity'] === $mapping['targetEntity']) {
                 continue;
             }
             $from = array($mapping['sourceEntity'], $field);
             $to = array($mapping['targetEntity'], '__class__');
             foreach ($data['relations'] as $relation) {
                 if ($relation['from'] === $from) {
                     continue 2;
                 }
             }
             $data['relations'][] = array('from' => $from, 'to' => $to, 'type' => $type);
         }
     }
     return $data;
 }
 /**
  * Builds a Hierarchy of every entity in the Class metadata.
  * @param ClassMetadataFactory $metadataFactory
  * @return MetadataNode[]
  */
 protected function buildHierarchy(ClassMetadataFactory $metadataFactory)
 {
     $this->hierarchy = array();
     $stack = new SplStack();
     foreach ($metadataFactory->getAllMetadata() as $metadata) {
         $stack->push($metadata->getName());
     }
     while (!$stack->isEmpty()) {
         $meta = $metadataFactory->getMetadataFor($stack->pop());
         $name = $meta->getName();
         $node = $this->getNode($name);
         $parent = $meta->getReflectionClass()->getParentClass();
         if ($parent != null && $metadataFactory->hasMetadataFor($parent->getName())) {
             $parentNode = $this->getNode($metadataFactory->getMetadataFor($parent->getName())->getName());
             $node->setParent($parentNode);
             $parentNode->addChild($node);
         }
     }
     return $this->hierarchy;
 }
 public function process(ClassMetadataFactory $factory, $data)
 {
     foreach ($factory->getAllMetadata() as $classMetadata) {
         $actual = $classMetadata->getName();
         $current = $classMetadata->getReflectionClass();
         while (false !== ($current = $current->getParentClass())) {
             $name = $current->getName();
             if (isset($data['entities'][$name])) {
                 $data['relations'][] = array('from' => array($actual, '__class__'), 'to' => array($name, '__class__'), 'type' => 'extends');
                 break;
             }
         }
         // Inherited properties
         foreach ($classMetadata->getReflectionProperties() as $property) {
             $class = $property->getDeclaringClass()->getName();
             $name = $property->getName();
             if ($class !== $actual && isset($data['entities'][$class]['fields'][$name])) {
                 unset($data['entities'][$actual]['fields'][$name]);
             }
         }
     }
     return $data;
 }
Exemplo n.º 5
0
 /**
  * @inheritDoc
  */
 public function getAllMetadata()
 {
     return $this->wrapped->getAllMetadata();
 }