當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Mapping\ClassMetadata類代碼示例

本文整理匯總了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata類的具體用法?PHP ClassMetadata怎麽用?PHP ClassMetadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ClassMetadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
         $config['loggable'] = true;
         if ($annot->logEntryClass) {
             if (!class_exists($annot->logEntryClass)) {
                 throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
             }
             $config['logEntryClass'] = $annot->logEntryClass;
         }
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // versioned property
         if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
             $field = $property->getName();
             if ($meta->isCollectionValuedAssociation($field)) {
                 throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['versioned'][] = $field;
         }
     }
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:32,代碼來源:Annotation.php

示例2: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     $config['fields'] = array();
     $config['fields_delete'] = array();
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         $field = null;
         if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
             $field['name'] = $property->getName();
             $field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
             if (!$meta->hasField($field['name'])) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
         }
         // if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
         //
         // $config['fields_delete'][] = $property->getName();
         //
         // }
         if ($field) {
             $config['fields'][] = $field;
         }
     }
 }
開發者ID:GrifiS,項目名稱:Symfony2CMS,代碼行數:31,代碼來源:Annotation.php

示例3: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if ($this->class !== $metadata->getName() || !$columnInfo->getAttribute() || $this->backendType !== $columnInfo->getAttribute()->getBackendType()) {
         return;
     }
     return array($this->transformer, array());
 }
開發者ID:javiersantos,項目名稱:pim-community-dev,代碼行數:10,代碼來源:AttributeGuesser.php

示例4: unserialize

 public function unserialize($value, ClassMetadata $metadata, $field)
 {
     $array = array();
     $serializerMetadata = $metadata->getSerializer();
     //reset value to array
     if (!is_array($value)) {
         if ($value instanceof ArrayCollection) {
             $value = $value->toArray();
         } elseif ($value instanceof ArrayObject) {
             $value = $value->getArrayCopy();
         }
     }
     if (isset($serializerMetadata['fields'][$field]['collectionType'])) {
         switch ($serializerMetadata['fields'][$field]['collectionType']) {
             case 'ArrayObject':
                 $array = new ArrayObject($value);
                 break;
             case 'ArrayCollection':
                 $array = new ArrayCollection($value);
                 break;
             case 'Array':
             case 'array':
             default:
                 $array = $value;
                 break;
         }
     } else {
         $array = (array) $value;
     }
     return $array;
 }
開發者ID:zoopcommerce,項目名稱:shard,代碼行數:31,代碼來源:Collection.php

示例5: loadMetadataForClass

 /**
  * 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()]);
         }
     }
 }
開發者ID:nicktacular,項目名稱:KeyValueStore,代碼行數:32,代碼來源:AnnotationDriver.php

示例6: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if (!$metadata->hasField($columnInfo->getPropertyPath()) || $this->type != $metadata->getTypeOfField($columnInfo->getPropertyPath())) {
         return;
     }
     return array($this->transformer, array());
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:10,代碼來源:TypeGuesser.php

示例7: let

 /**
  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrine
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  * @param \Behat\Behat\Hook\Scope\ScenarioScope $event
  * @param \Behat\Gherkin\Node\FeatureNode $feature
  * @param \Behat\Gherkin\Node\ScenarioNode $scenario
  * @param \Knp\FriendlyContexts\Alice\Loader\Yaml $loader
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory $metadataFactory
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $userMetadata
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $placeMetadata
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $productMetadata
  */
 function let($container, $doctrine, $manager, $event, $loader, $feature, $scenario, $metadataFactory, $userMetadata, $placeMetadata, $productMetadata)
 {
     $doctrine->getManager()->willReturn($manager);
     $feature->getTags()->willReturn(['alice(Place)', 'admin']);
     $scenario->getTags()->willReturn(['alice(User)']);
     $event->getFeature()->willReturn($feature);
     $event->getScenario()->willReturn($scenario);
     $loader->load('user.yml')->willReturn([]);
     $loader->load('product.yml')->willReturn([]);
     $loader->load('place.yml')->willReturn([]);
     $loader->getCache()->willReturn([]);
     $loader->clearCache()->willReturn(null);
     $fixtures = ['User' => 'user.yml', 'Product' => 'product.yml', 'Place' => 'place.yml'];
     $config = ['alice' => ['fixtures' => $fixtures, 'dependencies' => []]];
     $container->has(Argument::any())->willReturn(true);
     $container->hasParameter(Argument::any())->willReturn(true);
     $container->get('friendly.alice.loader.yaml')->willReturn($loader);
     $container->get('doctrine')->willReturn($doctrine);
     $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures);
     $container->getParameter('friendly.alice.dependencies')->willReturn([]);
     $manager->getMetadataFactory()->willReturn($metadataFactory);
     $metadataFactory->getAllMetadata()->willReturn([$userMetadata, $placeMetadata, $productMetadata]);
     $userMetadata->getName()->willReturn('User');
     $placeMetadata->getName()->willReturn('Place');
     $productMetadata->getName()->willReturn('Product');
     $this->initialize($config, $container);
 }
開發者ID:benji07,項目名稱:FriendlyContexts,代碼行數:40,代碼來源:AliceContextSpec.php

示例8: loadMetadataForClass

 /**
  * 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()));
     }
 }
開發者ID:kevinyien,項目名稱:KeyValueStore,代碼行數:40,代碼來源:YamlDriver.php

示例9: getEntityFields

 protected function getEntityFields(ClassMetadata $metaData, array $data)
 {
     // change data keys to camelcase
     $result = array();
     foreach ($data as $key => $value) {
         // convert to camelcase if underscore is in name
         if (strpos($key, '_') !== false) {
             $key = implode('', array_map('ucfirst', explode('_', $key)));
         }
         $result[$key] = $value;
     }
     $data = $result;
     // get all fields
     $fieldNames = $metaData->getFieldNames();
     $fields = array();
     foreach ($fieldNames as $fieldName) {
         if (!isset($data[$fieldName])) {
             continue;
         }
         $type = $metaData->getTypeOfField($fieldName);
         $value = $this->getColumnTypeValue($type, $data[$fieldName]);
         $fields[$fieldName] = $value;
     }
     return $fields;
 }
開發者ID:seytar,項目名稱:psx,代碼行數:25,代碼來源:Entity.php

示例10: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if (!$metadata->hasField($columnInfo->getPropertyPath())) {
         return;
     }
     return [$this->transformer, []];
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:10,代碼來源:DefaultGuesser.php

示例11: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if (!$columnInfo->getLocale() && !count($columnInfo->getSuffixes()) || !$metadata->hasAssociation('translations')) {
         return;
     }
     return array($this->transformer, array());
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:10,代碼來源:TranslationGuesser.php

示例12: isResource

 /**
  * @param ClassMetadata $metadata
  *
  * @return bool
  */
 protected function isResource(ClassMetadata $metadata)
 {
     if (!($reflClass = $metadata->getReflectionClass())) {
         return false;
     }
     return $reflClass->implementsInterface(PersistableInterface::class);
 }
開發者ID:superdesk,項目名稱:web-publisher,代碼行數:12,代碼來源:AbstractDoctrineSubscriber.php

示例13: readExtendedMetadata

 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     // load our available annotations
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     // set annotation namespace and alias
     //$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
     $class = $meta->getReflectionClass();
     // check only property annotations
     foreach ($class->getProperties() as $property) {
         // skip inherited properties
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // now lets check if property has our annotation
         if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
             $field = $property->getName();
             // check if field is mapped
             if (!$meta->hasField($field)) {
                 throw new \Exception("Field is not mapped as object property");
             }
             // allow encoding only strings
             if (!in_array($encode->type, array('sha1', 'md5'))) {
                 throw new \Exception("Invalid encoding type supplied");
             }
             // validate encoding type
             $mapping = $meta->getFieldMapping($field);
             if ($mapping['type'] != 'string') {
                 throw new \Exception("Only strings can be encoded");
             }
             // store the metadata
             $config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
         }
     }
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:35,代碼來源:Annotation.php

示例14: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $mapping = $this->_getMapping($meta->name);
     if (isset($mapping['gedmo'])) {
         $classMapping = $mapping['gedmo'];
         if (isset($classMapping['loggable'])) {
             $config['loggable'] = true;
             if (isset($classMapping['loggable']['logEntryClass'])) {
                 if (!class_exists($classMapping['loggable']['logEntryClass'])) {
                     throw new InvalidMappingException("LogEntry class: {$classMapping['loggable']['logEntryClass']} does not exist.");
                 }
                 $config['logEntryClass'] = $classMapping['loggable']['logEntryClass'];
             }
         }
     }
     if (isset($mapping['fields'])) {
         foreach ($mapping['fields'] as $field => $fieldMapping) {
             if (isset($fieldMapping['gedmo'])) {
                 if (in_array('versioned', $fieldMapping['gedmo'])) {
                     if ($meta->isCollectionValuedAssociation($field)) {
                         throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
                     }
                     // fields cannot be overrided and throws mapping exception
                     $config['versioned'][] = $field;
                 }
             }
         }
     }
 }
開發者ID:rdohms,項目名稱:DoctrineExtensions,代碼行數:32,代碼來源:Yaml.php

示例15: isIgnoredInWorkflow

 /**
  * Checks if the given relation should be ignored in workflows
  *
  * @param ClassMetadata $metadata
  * @param string        $associationName
  *
  * @return bool
  */
 protected function isIgnoredInWorkflow(ClassMetadata $metadata, $associationName)
 {
     if ($this->isWorkflowField($associationName)) {
         return true;
     }
     return !$metadata->isSingleValuedAssociation($associationName);
 }
開發者ID:northdakota,項目名稱:platform,代碼行數:15,代碼來源:FieldProvider.php


注:本文中的Doctrine\Common\Persistence\Mapping\ClassMetadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。