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


PHP ManagerRegistry::getManagerForClass方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\ManagerRegistry::getManagerForClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getManagerForClass方法的具体用法?PHP ManagerRegistry::getManagerForClass怎么用?PHP ManagerRegistry::getManagerForClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\ManagerRegistry的用法示例。


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

示例1: getFilterParts

 /**
  * @param OrmFilterDatasourceAdapter $ds
  * @param string                     $fieldName
  *
  * @return array [entity, alias, field]
  *
  * @throws \RuntimeException
  */
 protected function getFilterParts(OrmFilterDatasourceAdapter $ds, $fieldName)
 {
     $fieldParts = explode('.', $fieldName);
     if (count($fieldParts) !== 2) {
         throw new \RuntimeException(sprintf('It is expected that $fieldName is in "alias.name" format, but "%s" given.', $fieldName));
     }
     $qb = $ds->getQueryBuilder();
     $entity = $this->getRootEntity($qb, $fieldParts[0]);
     if (empty($entity)) {
         $associations = [];
         $entity = $this->findEntityByAlias($qb, $fieldParts[0]);
         while (!empty($entity) && strpos($entity, ':') === false && strpos($entity, '\\') === false) {
             $parts = explode('.', $entity);
             array_unshift($associations, $parts[1]);
             $entity = $this->findEntityByAlias($qb, $parts[0]);
         }
         if (empty($entity)) {
             throw new \RuntimeException(sprintf('Cannot find root entity for "$s". It seems that a query is not valid.', $fieldName));
         }
         foreach ($associations as $assoc) {
             $entity = $this->doctrine->getManagerForClass($entity)->getClassMetadata($entity)->getAssociationTargetClass($assoc);
         }
     }
     if (empty($entity)) {
         throw new \RuntimeException(sprintf('Cannot find entity for "$s". It seems that a query is not valid.', $fieldName));
     }
     return [$entity, $fieldParts[0], $fieldParts[1]];
 }
开发者ID:xamin123,项目名称:platform,代码行数:36,代码来源:OrmManyRelationBuilder.php

示例2: getMarketingListBySegment

 /**
  * @param int $segmentId
  *
  * @return MarketingList
  */
 public function getMarketingListBySegment($segmentId)
 {
     if (empty($this->marketingListsBySegment[$segmentId])) {
         $this->marketingListsBySegment[$segmentId] = $this->managerRegistry->getManagerForClass(self::MARKETING_LIST)->getRepository(self::MARKETING_LIST)->findOneBy(['segment' => $segmentId]);
     }
     return $this->marketingListsBySegment[$segmentId];
 }
开发者ID:dairdr,项目名称:crm,代码行数:12,代码来源:MarketingListSegmentHelper.php

示例3: getLoginPageRepository

 /**
  * @return ObjectRepository
  */
 protected function getLoginPageRepository()
 {
     if (!$this->loginPageRepository) {
         $this->loginPageRepository = $this->doctrine->getManagerForClass('OroB2BCMSBundle:LoginPage')->getRepository('OroB2BCMSBundle:LoginPage');
     }
     return $this->loginPageRepository;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:10,代码来源:LoginPageExtension.php

示例4: getClassMetadata

 /**
  * Returns class metadata for a defined entity parameter
  *
  * @param string $entityParameter
  *
  * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
  */
 protected function getClassMetadata($entityParameter)
 {
     $entityClassName = $this->container->getParameter($entityParameter);
     $manager = $this->managerRegistry->getManagerForClass($entityClassName);
     $classMetadata = $manager->getClassMetadata($entityClassName);
     return $classMetadata;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:14,代码来源:TableNameBuilder.php

示例5: runCrons

 public function runCrons()
 {
     $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTask');
     $cronTaskRepo = $entityManager->getRepository('DspSoftsCronManagerBundle:CronTask');
     $cronTasks = $cronTaskRepo->findCronsToLaunch();
     foreach ($cronTasks as $cronTask) {
         $run = true;
         if (!$cronTask->getRelaunch()) {
             $run = $this->planificationChecker->isExecutionDue($cronTask->getPlanification());
         }
         if ($run) {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Running Cron Task <info>%s</info>', $cronTask->getName()));
             }
             $cli = 'exec ' . $this->kernelRootDir . DIRECTORY_SEPARATOR . 'console dsp:cron:runjob -c ' . $cronTask->getId() . ' &';
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Command line : <info>%s</info>', $cli));
             }
             $process = new Process($cli);
             $process->setTimeout(0);
             $process->start();
         } else {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Skipping Cron Task <info>%s</info>', $cronTask->getName()));
             }
         }
     }
 }
开发者ID:dspsofts,项目名称:cronmanager-bundle,代码行数:28,代码来源:CronManipulator.php

示例6: onConsoleTerminate

 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if (!$this->isExceptionOccurred) {
         if ($event->getCommand() instanceof UpdateSchemaDoctrineCommand) {
             $output = $event->getOutput();
             $input = $event->getInput();
             if ($input->getOption('force')) {
                 $result = $this->fulltextIndexManager->createIndexes();
                 $output->writeln('Schema update and create index completed.');
                 if ($result) {
                     $output->writeln('Indexes were created.');
                 }
             }
         }
         if ($event->getCommand() instanceof UpdateSchemaCommand) {
             /** @var EntityManager $searchEntityManager */
             $searchEntityManager = $this->registry->getManagerForClass('OroSearchBundle:UpdateEntity');
             $entities = $searchEntityManager->getRepository('OroSearchBundle:UpdateEntity')->findAll();
             if (count($entities)) {
                 /** @var EntityManager $em */
                 $em = $this->registry->getManagerForClass('JMS\\JobQueueBundle\\Entity\\Job');
                 foreach ($entities as $entity) {
                     $job = new Job(ReindexCommand::COMMAND_NAME, ['class' => $entity->getEntity()]);
                     $em->persist($job);
                     $searchEntityManager->remove($entity);
                 }
                 $em->flush();
                 $searchEntityManager->flush();
             }
         }
     }
     $this->isExceptionOccurred = null;
 }
开发者ID:Maksold,项目名称:platform,代码行数:36,代码来源:UpdateSchemaDoctrineListener.php

示例7: getSerializationConfig

 /**
  * {@inheritdoc}
  */
 public function getSerializationConfig($className)
 {
     /** @var EntityManager $em */
     $em = $this->doctrine->getManagerForClass($className);
     $metadata = $em->getClassMetadata($className);
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $fields = [];
     foreach ($metadata->getFieldNames() as $fieldName) {
         $extendFieldConfig = $extendConfigProvider->getConfig($className, $fieldName);
         if ($extendFieldConfig->is('is_extend')) {
             // skip extended fields
             continue;
         }
         $fields[$fieldName] = null;
     }
     foreach ($metadata->getAssociationNames() as $fieldName) {
         $extendFieldConfig = $extendConfigProvider->getConfig($className, $fieldName);
         if ($extendFieldConfig->is('is_extend')) {
             // skip extended fields
             continue;
         }
         $mapping = $metadata->getAssociationMapping($fieldName);
         if ($mapping['type'] & ClassMetadata::TO_ONE && $mapping['isOwningSide']) {
             $targetMetadata = $em->getClassMetadata($mapping['targetEntity']);
             $idFieldNames = $targetMetadata->getIdentifierFieldNames();
             if (count($idFieldNames) === 1) {
                 $fields[$fieldName] = ['fields' => $idFieldNames[0]];
             }
         }
     }
     return ['exclusion_policy' => 'all', 'hints' => ['HINT_TRANSLATABLE'], 'fields' => $fields];
 }
开发者ID:ramunasd,项目名称:platform,代码行数:35,代码来源:DictionaryValueListProvider.php

示例8: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$this->installed) {
         return;
     }
     $request = $event->getRequest();
     if ($request->attributes->has('_controller') || $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $slugUrl = $request->getPathInfo();
     if ($slugUrl !== '/') {
         $slugUrl = rtrim($slugUrl, '/');
     }
     /** @var EntityManager $em */
     $em = $this->registry->getManagerForClass('OroB2BRedirectBundle:Slug');
     $slug = $em->getRepository('OroB2BRedirectBundle:Slug')->findOneBy(['url' => $slugUrl]);
     if ($slug) {
         $routeName = $slug->getRouteName();
         $controller = $this->router->getRouteCollection()->get($routeName)->getDefault('_controller');
         $parameters = [];
         $parameters['_route'] = $routeName;
         $parameters['_controller'] = $controller;
         $redirectRouteParameters = $slug->getRouteParameters();
         $parameters = array_merge($parameters, $redirectRouteParameters);
         $parameters['_route_params'] = $redirectRouteParameters;
         $request->attributes->add($parameters);
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:31,代码来源:ForwardListener.php

示例9: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadataInterface $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null)
 {
     $className = $classMetadata->getReflectionClass()->name;
     $manager = $this->managerRegistry->getManagerForClass($className);
     if (!$manager) {
         return $classMetadata;
     }
     $doctrineClassMetadata = $manager->getClassMetadata($className);
     if (!$doctrineClassMetadata) {
         return $classMetadata;
     }
     $identifiers = $doctrineClassMetadata->getIdentifier();
     if (1 !== count($identifiers)) {
         return $classMetadata;
     }
     $identifierName = $identifiers[0];
     if (!$classMetadata->hasAttributeMetadata($identifierName)) {
         $attributeMetadata = $this->attributeMetadataFactory->getAttributeMetadataFor($classMetadata, $identifierName, $normalizationGroups, $denormalizationGroups);
         if ($doctrineClassMetadata->isIdentifierNatural()) {
             $attributeMetadata = $attributeMetadata->withWritable(false);
         }
         $classMetadata = $classMetadata->withAttributeMetadata($identifierName, $attributeMetadata);
     }
     $classMetadata = $classMetadata->withIdentifierName($identifierName);
     return $classMetadata;
 }
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:29,代码来源:DoctrineIdentifierLoader.php

示例10: initForEntity

 /**
  * @param string $entityName  Entity name to prepare search handler for
  * @param string $targetField Entity field to search by and include to search results
  */
 public function initForEntity($entityName, $targetField)
 {
     $this->entityName = str_replace('_', '\\', $entityName);
     $this->initDoctrinePropertiesByEntityManager($this->registry->getManagerForClass($this->entityName));
     $this->properties = array_unique(array_merge($this->defaultPropertySet, [$targetField]));
     $this->currentField = $targetField;
 }
开发者ID:ramunasd,项目名称:platform,代码行数:11,代码来源:EntitySelectHandler.php

示例11: create

 /**
  * @param string $type
  *
  * @return FilterIn|null
  */
 private function create($type)
 {
     $manager = $this->managerRegistry->getManagerForClass($type);
     if ($manager) {
         return new FilterIn($manager->getRepository($type));
     }
 }
开发者ID:arachne,项目名称:doctrine,代码行数:12,代码来源:FilterInResolver.php

示例12: construct

 /**
  * {@inheritdoc}
  * @throws RuntimeException
  */
 public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context)
 {
     // Locate possible ObjectManager
     $objectManager = $this->managerRegistry->getManagerForClass($metadata->name);
     if (!$objectManager) {
         // No ObjectManager found, proceed with normal deserialization
         return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
     }
     // Locate possible ClassMetadata
     $classMetadataFactory = $objectManager->getMetadataFactory();
     if ($classMetadataFactory->isTransient($metadata->name)) {
         // No ClassMetadata found, proceed with normal deserialization
         return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
     }
     try {
         $id = $this->resolveIdentifier($metadata, $data, $objectManager);
     } catch (\Exception $e) {
         $id = null;
     }
     if ($id && ($entity = $objectManager->find($metadata->name, $id))) {
         /* @var $objectManager EntityManager */
         if ($this->isNewIdRegistered($metadata->name, $id)) {
             throw new RuntimeException("Not a unique entity '{$metadata->name}' with identifier '{$id}''");
         }
         $this->registerNewId($metadata->name, $id);
         return $entity;
     }
     // No ClassMetadata found, proceed with normal deserialization
     return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
 }
开发者ID:Rastusik,项目名称:ci-assignment,代码行数:34,代码来源:DoctrineObjectConstructor.php

示例13: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['em'] === null) {
         $em = $this->registry->getManagerForClass($options['class']);
     } else {
         $em = $this->registry->getManager($options['em']);
     }
     $repository = $em->getRepository($options['class']);
     $entities = $repository->findAll();
     /** @var ClassMetadataInfo $classMetadata */
     $classMetadata = $em->getClassMetadata($options['class']);
     $identifierField = $classMetadata->getSingleIdentifierFieldName();
     $choiceLabels = [];
     /** @var AddressType $entity */
     foreach ($entities as $entity) {
         $pkValue = $classMetadata->getReflectionProperty($identifierField)->getValue($entity);
         if ($options['property']) {
             $value = $classMetadata->getReflectionProperty($options['property'])->getValue($entity);
         } else {
             $value = (string) $entity;
         }
         $choiceLabels[$pkValue] = $this->translator->trans('orob2b.customer.customer_typed_address_with_default_type.choice.default_text', ['%type_name%' => $value]);
     }
     $builder->add('default', 'choice', ['choices' => $choiceLabels, 'multiple' => true, 'expanded' => true, 'label' => false])->addViewTransformer(new AddressTypeDefaultTransformer($em));
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:28,代码来源:CustomerTypedAddressWithDefaultType.php

示例14: postSetData

 /**
  * @param FormEvent $event
  */
 public function postSetData(FormEvent $event)
 {
     $form = $event->getForm();
     if ($form->getParent()) {
         return;
     }
     if (!$form->has($this->fieldName)) {
         return;
     }
     $isEntityExists = false;
     $entity = $event->getData();
     if ($entity) {
         if (!is_object($entity)) {
             return;
         }
         $entityClass = ClassUtils::getClass($entity);
         $entityManager = $this->managerRegistry->getManagerForClass($entityClass);
         if (!$entityManager) {
             return;
         }
         $entityIdentifier = $entityManager->getClassMetadata($entityClass)->getIdentifierValues($entity);
         $isEntityExists = !empty($entityIdentifier);
     }
     // if entity exists and assign is not granted - replace field with disabled text field,
     // otherwise - set default owner value
     if ($isEntityExists) {
         $this->replaceOwnerField($form);
     } else {
         $this->setPredefinedOwner($form);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:34,代码来源:OwnerFormSubscriber.php

示例15: getEntityManager

 /**
  * @param string $entityClass
  * @return EntityManager
  * @throws LogicException
  */
 protected function getEntityManager($entityClass)
 {
     $entityManager = $this->managerRegistry->getManagerForClass($entityClass);
     if (!$entityManager) {
         throw new LogicException(sprintf('Can\'t find entity manager for %s', $entityClass));
     }
     return $entityManager;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:13,代码来源:ImportStrategyHelper.php


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