当前位置: 首页>>代码示例>>PHP>>正文


PHP Mapping\ClassMetadataInfo类代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataInfo的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo类的具体用法?PHP ClassMetadataInfo怎么用?PHP ClassMetadataInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClassMetadataInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * @param BundleInterface $bundle         The bundle
  * @param string          $entity         The entity name
  * @param string          $format         The format
  * @param array           $fields         The fields
  * @param boolean         $withRepository With repository
  * @param string          $prefix         A prefix
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $entity, $format, array $fields, $withRepository, $prefix)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager(null)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
     $entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
     }
     $class = new ClassMetadataInfo($entityClass);
     if ($withRepository) {
         $entityClass = preg_replace('/\\\\Entity\\\\/', '\\Repository\\', $entityClass, 1);
         $class->customRepositoryClassName = $entityClass . 'Repository';
     }
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $class->setPrimaryTable(array('name' => $prefix . $this->getTableNameFromEntityName($entity)));
     $entityGenerator = $this->getEntityGenerator();
     $entityCode = $entityGenerator->generateEntityClass($class);
     $mappingPath = $mappingCode = false;
     $this->filesystem->mkdir(dirname($entityPath));
     file_put_contents($entityPath, $entityCode);
     if ($mappingPath) {
         $this->filesystem->mkdir(dirname($mappingPath));
         file_put_contents($mappingPath, $mappingCode);
     }
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeEntityRepositoryClass($class->customRepositoryClassName, $path);
     }
     $this->addGeneratedEntityClassLoader($entityClass, $entityPath);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:44,代码来源:DoctrineEntityGenerator.php

示例2: validateField

 public static function validateField(ClassMetadataInfo $meta, $field)
 {
     $fieldMapping = $meta->getFieldMapping($field);
     if (!in_array($fieldMapping['type'], self::$validTypes)) {
         throw new InvalidMappingException(sprintf('Field "%s" must be of one of the following types: "%s"', $fieldMapping['type'], implode(', ', self::$validTypes)));
     }
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:7,代码来源:Validator.php

示例3: execute

 /**
  * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle")
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
     $entity = str_replace('/', '\\', $input->getArgument('entity'));
     $fullEntityClassName = $bundle->getNamespace() . '\\Entity\\' . $entity;
     $mappingType = $input->getOption('mapping-type');
     $class = new ClassMetadataInfo($fullEntityClassName);
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     // Map the specified fields
     $fields = $input->getOption('fields');
     if ($fields) {
         $e = explode(' ', $fields);
         foreach ($e as $value) {
             $e = explode(':', $value);
             $name = $e[0];
             if (strlen($name)) {
                 $type = isset($e[1]) ? $e[1] : 'string';
                 preg_match_all('/(.*)\\((.*)\\)/', $type, $matches);
                 $type = isset($matches[1][0]) ? $matches[1][0] : $type;
                 $length = isset($matches[2][0]) ? $matches[2][0] : null;
                 $class->mapField(array('fieldName' => $name, 'type' => $type, 'length' => $length));
             }
         }
     }
     // Setup a new exporter for the mapping type specified
     $cme = new ClassMetadataExporter();
     $exporter = $cme->getExporter($mappingType);
     $entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf("Entity %s already exists.", $class->name));
     }
     if ('annotation' === $mappingType) {
         $exporter->setEntityGenerator($this->getEntityGenerator());
         $entityCode = $exporter->exportClassMetadata($class);
         $mappingPath = $mappingCode = false;
     } else {
         $mappingType = 'yaml' == $mappingType ? 'yml' : $mappingType;
         $mappingPath = $bundle->getPath() . '/Resources/config/doctrine/' . str_replace('\\', '.', $fullEntityClassName) . '.orm.' . $mappingType;
         $mappingCode = $exporter->exportClassMetadata($class);
         $entityGenerator = $this->getEntityGenerator();
         $entityCode = $entityGenerator->generateEntityClass($class);
         if (file_exists($mappingPath)) {
             throw new \RuntimeException(sprintf("Cannot generate entity when mapping <info>%s</info> already exists", $mappingPath));
         }
     }
     $output->writeln(sprintf('Generating entity for "<info>%s</info>"', $bundle->getName()));
     $output->writeln(sprintf('  > entity <comment>%s</comment> into <info>%s</info>', $fullEntityClassName, $entityPath));
     if (!is_dir($dir = dirname($entityPath))) {
         mkdir($dir, 0777, true);
     }
     file_put_contents($entityPath, $entityCode);
     if ($mappingPath) {
         $output->writeln(sprintf('  > mapping into <info>%s</info>', $mappingPath));
         if (!is_dir($dir = dirname($mappingPath))) {
             mkdir($dir, 0777, true);
         }
         file_put_contents($mappingPath, $mappingCode);
     }
 }
开发者ID:rfc1483,项目名称:blog,代码行数:63,代码来源:GenerateEntityDoctrineCommand.php

示例4: let

 function let(PropertyTransformerInterface $transformer, ColumnInfoInterface $columnInfo, ClassMetadataInfo $metadata)
 {
     $this->beConstructedWith($transformer, 'array');
     $columnInfo->getPropertyPath()->willReturn('property_path');
     $metadata->hasField('property_path')->willReturn(true);
     $metadata->getTypeOfField('property_path')->willReturn('array');
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:7,代码来源:ArrayGuesserSpec.php

示例5: unsetAssociationMappings

 /**
  * Unset the association mappings of a metadata.
  *
  * @param ClassMetadataInfo $metadata
  */
 protected function unsetAssociationMappings(ClassMetadataInfo $metadata)
 {
     foreach ($metadata->getAssociationMappings() as $key => $value) {
         if ($this->hasRelation($value['type'])) {
             unset($metadata->associationMappings[$key]);
         }
     }
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:13,代码来源:MappingsOverrideConfigurator.php

示例6: loadMetadata

 public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
 {
     $metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id'));
     $metadata->mapField(array('fieldName' => 'value', 'type' => 'float'));
     $metadata->isMappedSuperclass = true;
     $metadata->setCustomRepositoryClass("Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository");
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO);
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:8,代码来源:DDC869Payment.php

示例7: extendClassMetadata

 /**
  * Extends the mapping
  *
  * @param ClassMetadataInfo           $metadata
  * @param MappingDefinitionCollection $collection
  */
 private function extendClassMetadata(ClassMetadataInfo $metadata, MappingDefinitionCollection $collection)
 {
     $collection->forAll(function (MappingDefinitionInterface $definition) use($metadata) {
         $reflectionClass = $metadata->getReflectionClass();
         if (true === $reflectionClass->hasProperty($definition->getPropertyName())) {
             $metadata->{$definition->getClassMetadataMethod()}($definition->getOptions());
         }
     });
 }
开发者ID:WellCommerce,项目名称:DoctrineBundle,代码行数:15,代码来源:AbstractMappingEnhancer.php

示例8: traverse

 /**
  * {@inheritdoc}
  */
 public function traverse(ClassMetadataInfo $metadata)
 {
     $class = $metadata->getName();
     if (true === $this->collection->has($class)) {
         foreach ($this->collection->get($class) as $enhancer) {
             $enhancer->visitClassMetadata($metadata);
         }
     }
 }
开发者ID:WellCommerce,项目名称:DoctrineBundle,代码行数:12,代码来源:ClassMetadataEnhancerTraverser.php

示例9: getTableName

 /**
  * @param ClassMetadataInfo $metadata
  *
  * @return string
  */
 public function getTableName(ClassMetadataInfo $metadata)
 {
     $tableName = $metadata->getTableName();
     //## Fix for doctrine/orm >= 2.5
     if (method_exists($metadata, 'getSchemaName') && $metadata->getSchemaName()) {
         $tableName = $metadata->getSchemaName() . '.' . $tableName;
     }
     return $this->getTablePrefix() . $tableName . $this->getTableSuffix();
 }
开发者ID:greentopsecret,项目名称:EntityAudit,代码行数:14,代码来源:AuditConfiguration.php

示例10: generate

 /**
  * @param ClassMetadataInfo $metadata
  * @param string $outputDir
  * @param Closure $collectionNameBuilder
  */
 public function generate(ClassMetadataInfo $metadata, $outputDir, Closure $collectionNameBuilder)
 {
     $tpl = file_get_contents(CodeGeneratorHelper::absPath(EntityCollectionTemplate::class, RootPath::path()));
     $tplNs = CodeGeneratorHelper::ns(EntityCollectionTemplate::class);
     $tplSimpleName = CodeGeneratorHelper::simpleName(EntityCollectionTemplate::class);
     $entityFqcn = CodeGeneratorHelper::simpleName(EntityFqcn::class);
     $collectionClassName = $collectionNameBuilder($metadata->getName());
     $code = CodeGeneratorHelper::render($tpl, array($tplNs => CodeGeneratorHelper::ns($collectionClassName), $tplSimpleName => CodeGeneratorHelper::simpleName($collectionClassName), $entityFqcn => CodeGeneratorHelper::fqn($metadata->getName())));
     CodeGeneratorHelper::save($collectionClassName, $code, $outputDir);
 }
开发者ID:zorji,项目名称:doctrine-query-collection,代码行数:15,代码来源:EntityCollectionCodeGenerator.php

示例11: getClassAnnotations

 /**
  * Returns class annotations.
  *
  * @param ClassMetadataInfo $metadata
  *
  * @return array
  */
 protected function getClassAnnotations($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);
     }
     return $this->readAnnotations($class);
 }
开发者ID:pjarmalavicius,项目名称:PjEntityExtendBundle,代码行数:17,代码来源:AnnotationDriver.php

示例12: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
 {
     $element = $this->getElement($className, true);
     // Customizing for Cloudrexx: YamlEntity extension
     if ($element['type'] == 'YamlEntity') {
         $metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
         $metadata->isMappedSuperclass = true;
     }
     parent::loadMetadataForClass($className, $metadata);
 }
开发者ID:Cloudrexx,项目名称:cloudrexx,代码行数:13,代码来源:YamlDriver.class.php

示例13: execute

 /**
  * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle")
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!preg_match('/Bundle$/', $bundle = $input->getArgument('bundle'))) {
         throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\\MySampleBundle".');
     }
     $dirs = $this->container->get('kernel')->getBundleDirs();
     $tmp = str_replace('\\', '/', $bundle);
     $namespace = str_replace('/', '\\', dirname($tmp));
     $bundle = basename($tmp);
     if (!isset($dirs[$namespace])) {
         throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace));
     }
     $entity = $input->getArgument('entity');
     $entityNamespace = $namespace . '\\' . $bundle . '\\Entity';
     $fullEntityClassName = $entityNamespace . '\\' . $entity;
     $tmp = str_replace('\\', '/', $fullEntityClassName);
     $tmp = str_replace('/', '\\', dirname($tmp));
     $className = basename($tmp);
     $mappingType = $input->getOption('mapping-type');
     $mappingType = $mappingType ? $mappingType : 'xml';
     $class = new ClassMetadataInfo($fullEntityClassName);
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     // Map the specified fields
     $fields = $input->getOption('fields');
     if ($fields) {
         $e = explode(' ', $fields);
         foreach ($e as $value) {
             $e = explode(':', $value);
             $name = $e[0];
             $type = isset($e[1]) ? $e[1] : 'string';
             preg_match_all('/(.*)\\((.*)\\)/', $type, $matches);
             $type = isset($matches[1][0]) ? $matches[1][0] : $type;
             $length = isset($matches[2][0]) ? $matches[2][0] : null;
             $class->mapField(array('fieldName' => $name, 'type' => $type, 'length' => $length));
         }
     }
     // Setup a new exporter for the mapping type specified
     $cme = new ClassMetadataExporter();
     $exporter = $cme->getExporter($mappingType);
     if ('annotation' === $mappingType) {
         $path = $dirs[$namespace] . '/' . $bundle . '/Entity/' . str_replace($entityNamespace . '\\', null, $fullEntityClassName) . '.php';
         $exporter->setEntityGenerator($this->getEntityGenerator());
     } else {
         $mappingType = 'yaml' == $mappingType ? 'yml' : $mappingType;
         $path = $dirs[$namespace] . '/' . $bundle . '/Resources/config/doctrine/metadata/orm/' . str_replace('\\', '.', $fullEntityClassName) . '.dcm.' . $mappingType;
     }
     $code = $exporter->exportClassMetadata($class);
     if (!is_dir($dir = dirname($path))) {
         mkdir($dir, 0777, true);
     }
     $output->writeln(sprintf('Generating entity for "<info>%s</info>"', $bundle));
     $output->writeln(sprintf('  > generating <comment>%s</comment>', $fullEntityClassName));
     file_put_contents($path, $code);
 }
开发者ID:notbrain,项目名称:symfony,代码行数:58,代码来源:GenerateEntityDoctrineCommand.php

示例14: getORMTransformerInfo

 /**
  * @param ColumnInfoInterface  $columnInfo
  * @param ORMClassMetadataInfo $metadata
  *
  * @return array
  */
 private function getORMTransformerInfo(ColumnInfoInterface $columnInfo, ORMClassMetadataInfo $metadata)
 {
     if (!$metadata->hasAssociation($columnInfo->getPropertyPath())) {
         return;
     }
     $mapping = $metadata->getAssociationMapping($columnInfo->getPropertyPath());
     if (!$this->doctrine->getRepository($mapping['targetEntity']) instanceof ReferableEntityRepositoryInterface) {
         return;
     }
     return array($this->transformer, array('class' => $mapping['targetEntity'], 'multiple' => ORMClassMetadataInfo::MANY_TO_MANY === $mapping['type']));
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:17,代码来源:RelationGuesser.php

示例15: loadMetadata

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
  */
 public static function loadMetadata(ORM\ClassMetadataInfo $metadata)
 {
     $metadata->setTableName('album');
     $metadata->setIdGeneratorType(ORM\ClassMetadataInfo::GENERATOR_TYPE_NONE);
     $metadata->setCustomRepositoryClass('Orm\\Repository\\AlbumRepository');
     $metadata->addLifecycleCallback('setLastupdateToNow', 'prePersist');
     $metadata->addLifecycleCallback('setLastupdateToNow', 'preUpdate');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'string', 'length' => 100));
     $metadata->mapField(array('id' => true, 'fieldName' => 'websiteid', 'type' => 'string', 'length' => 100));
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 255));
     $metadata->mapField(array('fieldName' => 'lastupdate', 'type' => 'bigint', 'default' => 0));
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:15,代码来源:Album.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadataInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。