本文整理汇总了PHP中Doctrine\ORM\Event\LoadClassMetadataEventArgs::getEntityManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LoadClassMetadataEventArgs::getEntityManager方法的具体用法?PHP LoadClassMetadataEventArgs::getEntityManager怎么用?PHP LoadClassMetadataEventArgs::getEntityManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Event\LoadClassMetadataEventArgs
的用法示例。
在下文中一共展示了LoadClassMetadataEventArgs::getEntityManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
if ($this->userClass !== false) {
// the $metadata is the whole mapping info for this class
$metadata = $eventArgs->getClassMetadata();
if ($metadata->getName() != self::ENTITY_CLASS) {
return;
}
$em = $eventArgs->getEntityManager();
$userMetadata = $em->getClassMetadata($this->userClass);
$namingStrategy = $eventArgs->getEntityManager()->getConfiguration()->getNamingStrategy();
$metadata->mapManyToOne(array('targetEntity' => $userMetadata->getName(), 'fieldName' => 'userLogged', 'joinColumns' => array(array('name' => 'user_id'))));
}
}
示例2: testLoadClassMetadataWithoutParent
public function testLoadClassMetadataWithoutParent()
{
$this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
$this->classMetadata->getName()->willReturn(get_class($this->object->reveal()));
$this->classMetadata->setCustomRepositoryClass('Sulu\\Bundle\\ContactBundle\\Entity\\ContactRepository')->shouldNotBeCalled();
$this->loadClassMetadataEvent->getEntityManager()->willReturn($this->entityManager->reveal());
$this->entityManager->getConfiguration()->willReturn($this->configuration->reveal());
$this->configuration->getNamingStrategy()->willReturn(null);
/** @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $mappingDriver */
$mappingDriver = $this->prophesize('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
$this->configuration->getMetadataDriverImpl()->willReturn($mappingDriver->reveal());
$mappingDriver->getAllClassNames()->willReturn([get_class($this->parentObject->reveal())]);
$mappingDriver->loadMetadataForClass(get_class($this->parentObject->reveal()), Argument::type('Doctrine\\ORM\\Mapping\\ClassMetadata'))->shouldBeCalled();
$this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
}
示例3: 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);
}
}
示例4: loadClassMetadata
/**
* Adds doctrine point type
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
$classMetadata = $eventArgs->getClassMetadata();
if (null === $classMetadata->reflClass) {
return;
}
if ($this->isGeocodable($classMetadata)) {
if (!Type::hasType('point')) {
Type::addType('point', 'Knp\\DoctrineBehaviors\\DBAL\\Types\\PointType');
}
$em = $eventArgs->getEntityManager();
$con = $em->getConnection();
// skip non-postgres platforms
if (!$con->getDatabasePlatform() instanceof PostgreSqlPlatform && !$con->getDatabasePlatform() instanceof MySqlPlatform) {
return;
}
// skip platforms with registerd stuff
if (!$con->getDatabasePlatform()->hasDoctrineTypeMappingFor('point')) {
$con->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
if ($con->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$em->getConfiguration()->addCustomNumericFunction('DISTANCE', 'Knp\\DoctrineBehaviors\\ORM\\Geocodable\\Query\\AST\\Functions\\DistanceFunction');
}
}
$classMetadata->mapField(['fieldName' => 'location', 'type' => 'point', 'nullable' => true]);
}
}
示例5: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $args
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
$evm = $args->getEntityManager()->getEventManager();
$this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\CoreBundle\\Model\\TemplateInterface", "Bigfish\\Bundle\\CoreBundle\\Entity\\Template", array());
$this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\CoreBundle\\Model\\RouteInterface", "Bigfish\\Bundle\\CoreBundle\\Entity\\Route", array());
$evm->addEventListener(Events::loadClassMetadata, $this->resolveTargetEntities);
}
示例6: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
$em = $eventArgs->getEntityManager();
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
$wasMappedSuperclass = $metadata->isMappedSuperclass;
$this->setIsMappedSuperclass($metadata);
if (!$metadata->isMappedSuperclass) {
$this->setCustomRepositoryClasses($metadata, $eventArgs->getEntityManager()->getConfiguration());
$this->setAssociationMappings($metadata, $eventArgs->getEntityManager()->getConfiguration());
$this->setFieldMappings($metadata, $eventArgs->getEntityManager()->getConfiguration(), $em);
} else {
$this->unsetAssociationMappings($metadata);
$this->unsetFieldMappings($metadata, $wasMappedSuperclass);
}
}
示例7: 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);
}
}
}
示例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'];
}
}
}
示例9: 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;
}
}
}
示例10: 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'))));
}
}
示例11: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $event
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $event)
{
// HOT FIX for PIM-3683, when using MongoDB with PIM some queries are executed before that the schema is created
return;
/** @var OroEntityManager $em */
$em = $event->getEntityManager();
$configProvider = $em->getExtendManager()->getConfigProvider();
$className = $event->getClassMetadata()->getName();
if ($configProvider->hasConfig($className)) {
$config = $configProvider->getConfig($className);
if ($config->is('is_extend')) {
$cmBuilder = new ClassMetadataBuilder($event->getClassMetadata());
if ($config->is('index')) {
foreach ($config->get('index') as $columnName => $enabled) {
$fieldConfig = $configProvider->getConfig($className, $columnName);
if ($enabled && !$fieldConfig->is('state', ExtendManager::STATE_NEW)) {
$cmBuilder->addIndex(array(ExtendConfigDumper::FIELD_PREFIX . $columnName), 'oro_idx_' . $columnName);
}
}
}
$this->prepareRelations($config, $cmBuilder);
}
$em->getMetadataFactory()->setMetadataFor($className, $event->getClassMetadata());
}
}
示例12: loadClassMetadata
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
$em = $args->getEntityManager();
$meta = $args->getClassMetadata();
$class = $meta->name;
$rootClass = $meta->rootEntityName;
$info = Chalk::info($class);
$parentClasses = array_merge([$class], $meta->parentClasses);
$repositoryClasses = [];
foreach ($parentClasses as $parentClass) {
$parentInfo = Chalk::info($parentClass);
$repositoryClasses[] = $parentInfo->module->class . '\\Repository\\' . $parentInfo->local->class;
}
$repositoryClasses[] = 'Chalk\\Repository';
foreach ($repositoryClasses as $repositoryClass) {
if (class_exists($repositoryClass)) {
$meta->setCustomRepositoryClass($repositoryClass);
break;
}
}
if ($meta->discriminatorMap) {
$meta->discriminatorMap = [Chalk::info($rootClass)->name => $rootClass];
$allClasses = $em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
foreach ($allClasses as $allClass) {
if (is_subclass_of($allClass, $rootClass)) {
$meta->discriminatorMap[Chalk::info($allClass)->name] = $allClass;
}
if (is_subclass_of($allClass, $class) && !in_array($allClass, $meta->subClasses)) {
$meta->subClasses[] = $allClass;
}
}
}
}
示例13: 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()]);
}
示例14: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $args
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
$evm = $args->getEntityManager()->getEventManager();
$this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\ModuleInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Module", array());
$this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\ContainerInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Container", array());
$this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\FieldInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Field", array());
$evm->addEventListener(Events::loadClassMetadata, $this->resolveTargetEntities);
}
示例15: loadClassMetadata
/**
* @param LoadClassMetadataEventArgs $args
*
* @return void
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
//in the installer
if (!defined('MAUTIC_TABLE_PREFIX')) {
return;
}
/** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata */
$classMetadata = $args->getClassMetadata();
// Do not re-apply the prefix in an inheritance hierarchy.
if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
return;
}
if (FALSE !== strpos($classMetadata->namespace, 'Mautic')) {
//if in the installer, use the prefix set by it rather than what is cached
$prefix = MAUTIC_TABLE_PREFIX;
// Prefix indexes
$uniqueConstraints = array();
if (isset($classMetadata->table['uniqueConstraints'])) {
foreach ($classMetadata->table['uniqueConstraints'] as $name => $uc) {
$uniqueConstraints[$prefix . $name] = $uc;
}
}
$indexes = array();
if (isset($classMetadata->table['indexes'])) {
foreach ($classMetadata->table['indexes'] as $name => $uc) {
$indexes[$prefix . $name] = $uc;
}
}
// Prefix the table
$classMetadata->setPrimaryTable(array('name' => $prefix . $classMetadata->getTableName(), 'indexes' => $indexes, 'uniqueConstraints' => $uniqueConstraints));
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $prefix . $mappedTableName;
}
}
// Prefix sequences if supported by the DB platform
if ($classMetadata->isIdGeneratorSequence()) {
$newDefinition = $classMetadata->sequenceGeneratorDefinition;
$newDefinition['sequenceName'] = $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);
}
}
$reader = new AnnotationReader();
$class = $classMetadata->getReflectionClass();
$annotation = $reader->getClassAnnotation($class, 'Mautic\\CoreBundle\\Doctrine\\Annotation\\LoadClassMetadataCallback');
if (null !== $annotation) {
if (method_exists($class->getName(), $annotation->functionName['value'])) {
$func = $class->getName() . '::' . $annotation->functionName['value'];
call_user_func($func, $args);
}
}
}
}