当前位置: 首页>>代码示例>>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;未经允许,请勿转载。