Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var MetadataContext $context */
     if ($context->hasResult()) {
         // metadata is already loaded
         return;
     }
     $entityClass = $context->getClassName();
     if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) {
         // only manageable entities are supported
         return;
     }
     // filter excluded fields on this stage though there is another processor doing the same
     // it is done due to performance reasons
     $allowedFields = $this->getAllowedFields($context->getConfig());
     $classMetadata = $this->doctrineHelper->getEntityMetadataForClass($entityClass);
     $entityMetadata = $this->entityMetadataFactory->createEntityMetadata($classMetadata);
     $fields = $classMetadata->getFieldNames();
     foreach ($fields as $fieldName) {
         if (!isset($allowedFields[$fieldName])) {
             continue;
         }
         $entityMetadata->addField($this->entityMetadataFactory->createFieldMetadata($classMetadata, $fieldName));
     }
     $associations = $classMetadata->getAssociationNames();
     foreach ($associations as $associationName) {
         if (!isset($allowedFields[$associationName])) {
             continue;
         }
         $entityMetadata->addAssociation($this->entityMetadataFactory->createAssociationMetadata($classMetadata, $associationName));
     }
     $context->setResult($entityMetadata);
 }
Ejemplo n.º 2
0
 /**
  * @param EntityMetadata $entityMetadata
  * @param string         $propertyName
  * @param string[]       $propertyPath
  */
 protected function addLinkedProperty(EntityMetadata $entityMetadata, $propertyName, array $propertyPath)
 {
     $linkedProperty = array_pop($propertyPath);
     $classMetadata = $this->doctrineHelper->findEntityMetadataByPath($entityMetadata->getClassName(), $propertyPath);
     if (null !== $classMetadata) {
         if ($classMetadata->hasAssociation($linkedProperty)) {
             $associationMetadata = $this->entityMetadataFactory->createAssociationMetadata($classMetadata, $linkedProperty);
             $associationMetadata->setName($propertyName);
             $entityMetadata->addAssociation($associationMetadata);
         } else {
             $fieldMetadata = $this->entityMetadataFactory->createFieldMetadata($classMetadata, $linkedProperty);
             $fieldMetadata->setName($propertyName);
             $entityMetadata->addField($fieldMetadata);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var MetadataContext $context */
     if ($context->hasResult()) {
         // metadata is already loaded
         return;
     }
     $entityClass = $context->getClassName();
     if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) {
         // only manageable entities are supported
         return;
     }
     $classMetadata = $this->doctrineHelper->getEntityMetadataForClass($entityClass);
     $entityMetadata = $this->entityMetadataFactory->createEntityMetadata($classMetadata);
     $fields = $classMetadata->getFieldNames();
     foreach ($fields as $fieldName) {
         $entityMetadata->addField($this->entityMetadataFactory->createFieldMetadata($classMetadata, $fieldName));
     }
     $associations = $classMetadata->getAssociationNames();
     foreach ($associations as $associationName) {
         $entityMetadata->addAssociation($this->entityMetadataFactory->createAssociationMetadata($classMetadata, $associationName));
     }
     $context->setResult($entityMetadata);
 }