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
 /**
  * {@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);
 }