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


PHP Event\LoadClassMetadataEventArgs类代码示例

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


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

示例1: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $classMetadata = $eventArgs->getClassMetadata();
     // add subclasses to node
     $subclasses = array_flip($this->contentTypes);
     if ($classMetadata->name == $subclasses['node']) {
         unset($subclasses['node']);
         $classMetadata->subClasses = $subclasses;
         switch ($this->inheritanceType) {
             case 'single_table':
                 $classMetadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE);
                 break;
             case 'table_per_class':
                 $classMetadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS);
                 break;
             default:
                 $classMetadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_JOINED);
                 break;
         }
         $classMetadata->setDiscriminatorColumn(array('name' => $this->discriminatorColumn, 'type' => 'string', 'length' => 50));
     }
     // check if class is defined in config
     if (isset($this->contentTypes[$classMetadata->name])) {
         // set discriminator
         $classMetadata->discriminatorMap = array_flip($this->contentTypes);
         $classMetadata->discriminatorValue = $this->contentTypes[$classMetadata->name];
     }
 }
开发者ID:hatimeria,项目名称:ZenstruckCMSBundle,代码行数:28,代码来源:DiscriminatorListener.php

示例2: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $classMetadata = $eventArgs->getClassMetadata();
     $reflectionClass = $classMetadata->getReflectionClass();
     if (null === $reflectionClass) {
         return;
     }
     if (ClassUtil::classUsesTrait($reflectionClass->getName(), __NAMESPACE__ . '\\Translatable')) {
         if (!$classMetadata->hasAssociation('translations')) {
             $classMetadata->mapOneToMany(['fieldName' => 'translations', 'mappedBy' => 'translatable', 'indexBy' => 'locale', 'cascade' => ['persist', 'merge', 'remove'], 'orphanRemoval' => true, 'targetEntity' => $classMetadata->getName() . 'Translation']);
         }
     }
     if (ClassUtil::classUsesTrait($reflectionClass->getName(), __NAMESPACE__ . '\\Translation')) {
         if (!$classMetadata->hasAssociation('translatable')) {
             $classMetadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($classMetadata->getName(), 0, -11)]);
         }
         if (!$classMetadata->hasField('locale')) {
             $classMetadata->mapField(['fieldName' => 'locale', 'type' => 'string']);
         }
         $translationConstraint = $classMetadata->getTableName() . '_unique_translation';
         if (!ClassMetadataUtil::hasUniqueConstraint($classMetadata, $translationConstraint)) {
             $classMetadata->setPrimaryTable(['uniqueConstraints' => [['name' => $translationConstraint, 'columns' => ['translatable_id', 'locale']]]]);
         }
     }
 }
开发者ID:v3labs,项目名称:doctrine-extensions,代码行数:25,代码来源:TranslatableListener.php

示例3: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     /** @var ClassMetadata $metadata */
     $metadata = $eventArgs->getClassMetadata();
     // Transform Librinfo entities only
     if (strpos($metadata->getName(), "Librinfo\\") !== 0) {
         return;
     }
     $this->logger->debug("[NamingListener] Entering NamingListener for « loadClassMetadata » event");
     $namingStrategy = $eventArgs->getEntityManager()->getConfiguration()->getNamingStrategy();
     // create a FQDN for the representing table
     if ($namingStrategy->classToTableName($metadata->getName()) == $metadata->table['name']) {
         $metadata->table['name'] = $this->buildTableName($metadata->name);
     }
     // create a FQDN for the ManyToMany induced tables
     foreach ($metadata->associationMappings as $field => $mapping) {
         if ($mapping['type'] == ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) {
             if ($namingStrategy->classToTableName($mapping['joinTable']['name']) == $mapping['joinTable']['name']) {
                 $rc = new \ReflectionClass($mapping['targetEntity']);
                 $fqdn = $mapping['sourceEntity'] . '__' . $rc->getShortName();
                 $metadata->associationMappings[$field]['joinTable']['name'] = $this->buildTableName($fqdn);
             }
         }
     }
     $this->logger->debug("[NamingListener] Added table naming strategy to Entity", ['class' => $metadata->getName()]);
 }
开发者ID:libre-informatique,项目名称:SymfonyLibrinfoDoctrineBundle,代码行数:26,代码来源:NamingListener.php

示例4: loadClassMetadata

 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $this->em = $args->getEntityManager();
     $this->meta = $args->getClassMetadata();
     if (!$this->em->getConnection()->getWrappedConnection() instanceof AbstractConnection) {
         return;
     }
     if ($this->meta->customPersisterClassName === null) {
         $this->meta->setCustomPersisterClass(EntityPersister::class);
     }
     $this->markIndex();
     foreach ($this->meta->fieldMappings as $property => &$mapping) {
         $this->remapIdentifier($property, $mapping);
         $this->remapVersion($property, $mapping);
         $this->markField($property, $mapping);
     }
     foreach ($this->meta->associationMappings as $property => &$mapping) {
         $this->remapAnyToOneAssociation($property, $mapping);
         $this->remapAnyToManyAssociation($property, $mapping);
         $this->remapManyToManyAssociation($property, $mapping);
     }
     if ($cache = $this->em->getMetadataFactory()->getCacheDriver()) {
         $cache->save($this->meta->name . '$CLASSMETADATA', $this->meta, null);
     }
 }
开发者ID:mihai-stancu,项目名称:orientdb-orm,代码行数:28,代码来源:OrientDBListener.php

示例5: loadClassMetadata

 /**
  * define Addressable mapping at runtime
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     /** @var ClassMetadata $metadata */
     $metadata = $eventArgs->getClassMetadata();
     $reflectionClass = $metadata->getReflectionClass();
     if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Addressable')) {
         return;
     }
     // return if current entity doesn't use Addressable trait
     // Check if parents already have the Addressable trait
     foreach ($metadata->parentClasses as $parent) {
         if ($this->classAnalyzer->hasTrait($parent, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Addressable')) {
             return;
         }
     }
     $this->logger->debug("[AddressableListener] Entering AddressableListener for « loadClassMetadata » event");
     // setting default mapping configuration for Traceable
     // address
     $metadata->mapField(['fieldName' => 'address', 'type' => 'string', 'nullable' => true]);
     // zip
     $metadata->mapField(['fieldName' => 'zip', 'type' => 'string', 'length' => 20, 'nullable' => true]);
     // city
     $metadata->mapField(['fieldName' => 'city', 'type' => 'string', 'nullable' => true]);
     // country
     $metadata->mapField(['fieldName' => 'country', 'type' => 'string', 'nullable' => true]);
     // npai
     $metadata->mapField(['fieldName' => 'npai', 'type' => 'boolean', 'nullable' => true]);
     // vcardUid
     $metadata->mapField(['fieldName' => 'vcardUid', 'type' => 'string', 'nullable' => true]);
     // confirmed
     $metadata->mapField(['fieldName' => 'confirmed', 'type' => 'boolean', 'default' => true]);
     $this->logger->debug("[AddressableListener] Added Addressable mapping metadata to Entity", ['class' => $metadata->getName()]);
 }
开发者ID:libre-informatique,项目名称:SymfonyLibrinfoDoctrineBundle,代码行数:38,代码来源:AddressableListener.php

示例6: loadClassMetadata

 /**
  * Sets the discriminator maps on AbstractCharacteristics entity mappings.
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getClassMetadata();
     if ($metadata->getName() === self::ROOT_CHARACTERISTICS_CLASS) {
         $metadata->setDiscriminatorMap($this->characteristicsClassesMap);
     }
 }
开发者ID:ekyna,项目名称:characteristics,代码行数:12,代码来源:AbstractMapsSubscriber.php

示例7: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getClassMetadata();
     if ($metadata->getName() === $this->profile) {
         $this->setupProfileDiscriminator($metadata);
     }
 }
开发者ID:symedit,项目名称:symedit,代码行数:7,代码来源:MetadataSubscriber.php

示例8: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $classMetadata = $args->getClassMetadata();
     // Get class annotations
     $classAnnotations = $this->annotatonReader->getClassAnnotations($classMetadata->getReflectionClass());
     // Search for WordpressTable annotation
     $found = false;
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof WordpressTable) {
             $found = true;
             break;
         }
     }
     // Only apply to classes having WPTable annotation
     if (!$found) {
         return;
     }
     // set table prefix
     $prefix = $this->getPrefix($classMetadata->name, $args->getEntityManager());
     $classMetadata->setPrimaryTable(array('name' => $prefix . $classMetadata->getTableName()));
     // set table prefix to associated entity
     // TODO: make sure prefix won't apply to user table
     foreach ($classMetadata->associationMappings as &$mapping) {
         if (isset($mapping['joinTable']) && !empty($mapping['joinTable'])) {
             $mapping['joinTable']['name'] = $prefix . $mapping['joinTable']['name'];
         }
     }
 }
开发者ID:chiqui3d,项目名称:KayueWordpressBundle,代码行数:28,代码来源:TablePrefixSubscriber.php

示例9: loadClassMetadata

 /**
  * define Emailable mapping at runtime
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     /** @var ClassMetadata $metadata */
     $metadata = $eventArgs->getClassMetadata();
     $reflectionClass = $metadata->getReflectionClass();
     if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Emailable')) {
         return;
     }
     // return if current entity doesn't use Emailable trait
     // Check if parents already have the Emailable trait
     foreach ($metadata->parentClasses as $parent) {
         if ($this->classAnalyzer->hasTrait($parent, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Emailable')) {
             return;
         }
     }
     $this->logger->debug("[EmailableListener] Entering EmailableListener for « loadClassMetadata » event");
     // setting default mapping configuration for Traceable
     // email
     $metadata->mapField(['fieldName' => 'email', 'type' => 'string', 'nullable' => true]);
     // emailNpai
     $metadata->mapField(['fieldName' => 'emailNpai', 'type' => 'boolean', 'nullable' => true]);
     // emailNoNewsletter
     $metadata->mapField(['fieldName' => 'emailNoNewsletter', 'type' => 'boolean', 'nullable' => true]);
     $this->logger->debug("[EmailableListener] Added Emailable mapping metadata to Entity", ['class' => $metadata->getName()]);
 }
开发者ID:libre-informatique,项目名称:SymfonyLibrinfoDoctrineBundle,代码行数:30,代码来源:EmailableListener.php

示例10: loadClassMetadata

 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $meta = $args->getClassMetadata();
     if ($this->_l) {
         if (Strings::endsWith($meta->associationMappings[$this->_lName]['targetEntity'], '::dynamic')) {
             $meta->associationMappings[$this->_lName]['targetEntity'] = $this->getTargetEntity($meta->name, $this->_l);
         }
         return;
     }
     foreach ($meta->getAssociationNames() as $name) {
         if (!Strings::endsWith($meta->associationMappings[$name]['targetEntity'], '::dynamic')) {
             continue;
         }
         $em = $args->getEntityManager();
         $target = $this->getTargetEntity($meta, $name);
         $this->_l = $meta->name;
         $this->_lName = $meta->associationMappings[$name]['inversedBy'];
         if (!$this->_lName) {
             $this->_lName = $meta->associationMappings[$name]['mappedBy'];
         }
         if ($this->_lName) {
             $targetMeta = $em->getClassMetadata($target);
         }
         $this->_l = FALSE;
         $meta->associationMappings[$name]['targetEntity'] = $target;
         if ($this->_lName) {
             $targetMeta->associationMappings[$this->_lName]['targetEntity'] = $meta->name;
         }
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:33,代码来源:DynamicMapper.php

示例11: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $metadata = $args->getClassMetadata();
     $user = 'FOM\\UserBundle\\Entity\\User';
     $basicProfile = 'FOM\\UserBundle\\Entity\\BasicProfile';
     $profile = $this->container->getParameter('fom_user.profile_entity');
     if ($user == $metadata->getName()) {
         $metadata->mapOneToOne(array('fieldName' => 'profile', 'targetEntity' => $profile, 'mappedBy' => 'uid', 'cascade' => array('persist')));
     }
     $connection = $args->getEntityManager()->getConnection();
     $platform = $connection->getDatabasePlatform();
     $uidColname = $connection->quoteIdentifier('uid');
     if ($platform instanceof OraclePlatform) {
         $uidColname = strtoupper($uidColname);
     } elseif ($platform instanceof MySqlPlatform) {
         $uidColname = 'uid';
     }
     // need to add metadata for the basic profile, else doctrine
     // will whine in many situations
     if ($profile == $metadata->getName() || $basicProfile == $metadata->getName()) {
         $metadata->setIdentifier(array('uid'));
         $metadata->setIdGenerator(new AssignedGenerator());
         $metadata->mapOneToOne(array('fieldName' => 'uid', 'targetEntity' => $user, 'inversedBy' => 'profile', 'id' => true, 'joinColumns' => array(array('name' => $uidColname, 'referencedColumnName' => 'id'))));
     }
 }
开发者ID:mapbender,项目名称:fom,代码行数:25,代码来源:UserProfileListener.php

示例12: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $classMetadata = $args->getClassMetadata();
     if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
         // if we are in an inheritance hierarchy, only apply this once
         return;
     }
     $classMetadata->setTableName($this->prefix . $classMetadata->getTableName());
     foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
         if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY) {
             $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
             $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
         }
     }
     if ($classMetadata->isIdGeneratorSequence()) {
         $newDefinition = $classMetadata->sequenceGeneratorDefinition;
         $newDefinition['sequenceName'] = $this->prefix . $newDefinition['sequenceName'];
         $classMetadata->setSequenceGeneratorDefinition($newDefinition);
         $em = $args->getEntityManager();
         if (isset($classMetadata->idGenerator)) {
             $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($em->getConfiguration()->getQuoteStrategy()->getSequenceName($newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform()), $newDefinition['allocationSize']);
             $classMetadata->setIdGenerator($sequenceGenerator);
         }
     }
 }
开发者ID:javierseixas,项目名称:openMarketAPI,代码行数:25,代码来源:TablePrefixSubscriber.php

示例13: loadClassMetadata

 /**
  * loadClassMetadata event
  *
  * Retrieves the discriminatorMap from the BlockManagar, so we can
  * add entities to the discriminatorMap without adjusting the annotations
  * in the Block entity.
  *
  * @param LoadClassMetadataEventArgs $args
  *
  * @return void
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $metadata = $args->getClassMetadata();
     if ($metadata->name == 'Opifer\\CmsBundle\\Entity\\Block') {
         $metadata->setDiscriminatorMap($this->getDiscriminatorMap());
     }
 }
开发者ID:Opifer,项目名称:Cms,代码行数:18,代码来源:BlockDiscriminatorListener.php

示例14: loadClassMetadata

 /**
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getClassMetadata();
     $this->mapManyToMany($metadata);
     $this->mapOneToMany($metadata);
     $this->mapManyToOne($metadata);
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:10,代码来源:LoadMetadataSubscriber.php

示例15: loadClassMetadata

 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     /** @var ClassMetadata $metadata */
     $metadata = $eventArgs->getClassMetadata();
     // Do not generate id mapping twice for entities that extend a MappedSuperclass
     if ($metadata->isMappedSuperclass) {
         return;
     }
     // Do not generate id mapping twice for entities that use the SINGLE_TABLE inheritance mapping strategy.
     if ($metadata->isInheritanceTypeSingleTable() && !$metadata->subClasses) {
         return;
     }
     // Check if parents already have the Guidable trait
     foreach ($metadata->parentClasses as $parent) {
         if ($this->classAnalyzer->hasTrait($parent, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Guidable')) {
             return;
         }
     }
     $this->logger->debug("[GuidableListener] Entering GuidableListener for « loadClassMetadata » event");
     $reflectionClass = $metadata->getReflectionClass();
     // return if the current entity doesn't use Guidable trait
     if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Librinfo\\DoctrineBundle\\Entity\\Traits\\Guidable')) {
         return;
     }
     $metadata->mapField(['id' => true, 'fieldName' => "id", 'type' => "guid", 'columnName' => "id"]);
     $metadata->setIdGenerator(new UuidGenerator());
     $this->logger->debug("[GuidableListener] Added Guidable mapping metadata to Entity", ['class' => $metadata->getName()]);
 }
开发者ID:libre-informatique,项目名称:SymfonyLibrinfoDoctrineBundle,代码行数:28,代码来源:GuidableListener.php


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