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


PHP Registry::getManagerForClass方法代码示例

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


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

示例1: createSearchQueryBuilder

 /**
  * Creates the query builder used to get the results of the search query
  * performed by the user in the "search" view.
  *
  * @param array       $entityConfig
  * @param string      $searchQuery
  * @param string|null $sortField
  * @param string|null $sortDirection
  *
  * @return DoctrineQueryBuilder
  */
 public function createSearchQueryBuilder(array $entityConfig, $searchQuery, $sortField = null, $sortDirection = null)
 {
     /* @var EntityManager */
     $em = $this->doctrine->getManagerForClass($entityConfig['class']);
     /* @var DoctrineQueryBuilder */
     $queryBuilder = $em->createQueryBuilder()->select('entity')->from($entityConfig['class'], 'entity');
     $queryParameters = array();
     foreach ($entityConfig['search']['fields'] as $name => $metadata) {
         $isNumericField = in_array($metadata['dataType'], array('integer', 'number', 'smallint', 'bigint', 'decimal', 'float'));
         $isTextField = in_array($metadata['dataType'], array('string', 'text', 'guid'));
         if ($isNumericField && is_numeric($searchQuery)) {
             $queryBuilder->orWhere(sprintf('entity.%s = :exact_query', $name));
             // adding '0' turns the string into a numeric value
             $queryParameters['exact_query'] = 0 + $searchQuery;
         } elseif ($isTextField) {
             $searchQuery = strtolower($searchQuery);
             $queryBuilder->orWhere(sprintf('LOWER(entity.%s) LIKE :fuzzy_query', $name));
             $queryParameters['fuzzy_query'] = '%' . $searchQuery . '%';
             $queryBuilder->orWhere(sprintf('LOWER(entity.%s) IN (:words_query)', $name));
             $queryParameters['words_query'] = explode(' ', $searchQuery);
         }
     }
     if (0 !== count($queryParameters)) {
         $queryBuilder->setParameters($queryParameters);
     }
     if (null !== $sortField) {
         $queryBuilder->orderBy('entity.' . $sortField, $sortDirection ?: 'DESC');
     }
     return $queryBuilder;
 }
开发者ID:abdielcs,项目名称:EasyAdminBundle,代码行数:41,代码来源:QueryBuilder.php

示例2: process

 /**
  * @param LineItem $lineItem
  *
  * @return bool
  */
 public function process(LineItem $lineItem)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         /** @var EntityManagerInterface $manager */
         $manager = $this->registry->getManagerForClass('OroB2BShoppingListBundle:LineItem');
         $manager->beginTransaction();
         // handle case for new shopping list creation
         $formName = $this->form->getName();
         $formData = $this->request->request->get($formName, []);
         if (empty($formData['shoppingList']) && !empty($formData['shoppingListLabel'])) {
             $shoppingList = $this->shoppingListManager->createCurrent($formData['shoppingListLabel']);
             $formData['shoppingList'] = $shoppingList->getId();
             $this->request->request->set($formName, $formData);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /** @var LineItemRepository $lineItemRepository */
             $lineItemRepository = $manager->getRepository('OroB2BShoppingListBundle:LineItem');
             $existingLineItem = $lineItemRepository->findDuplicate($lineItem);
             if ($existingLineItem) {
                 $this->updateExistingLineItem($lineItem, $existingLineItem);
             } else {
                 $manager->persist($lineItem);
             }
             $manager->flush();
             $manager->commit();
             return true;
         } else {
             $manager->rollBack();
         }
     }
     return false;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:38,代码来源:LineItemHandler.php

示例3: onSuccess

 /**
  * @param GridView $entity
  */
 protected function onSuccess(GridView $entity)
 {
     $this->fixFilters($entity);
     $om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
     $om->persist($entity);
     $om->flush();
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:GridViewApiHandler.php

示例4: setUp

 protected function setUp()
 {
     $this->initClient();
     $this->registry = $this->getContainer()->get('doctrine');
     $this->entityManager = $this->registry->getManagerForClass('OroWorkflowBundle:ProcessJob');
     $this->repository = $this->registry->getRepository('OroWorkflowBundle:ProcessJob');
     $this->loadFixtures(array('Oro\\Bundle\\WorkflowBundle\\Tests\\Functional\\DataFixtures\\LoadProcessEntities'));
 }
开发者ID:xamin123,项目名称:platform,代码行数:8,代码来源:ProcessJobRepositoryTest.php

示例5: findCurrentItem

 /**
  * Looks for the object that corresponds to the selected 'id' of the current entity.
  *
  * @param array $entityConfig
  * @param mixed $itemId
  *
  * @return object The entity
  *
  * @throws EntityNotFoundException
  */
 private function findCurrentItem(array $entityConfig, $itemId)
 {
     $manager = $this->doctrine->getManagerForClass($entityConfig['class']);
     if (null === ($entity = $manager->getRepository($entityConfig['class'])->find($itemId))) {
         throw new EntityNotFoundException(array('entity' => $entityConfig, 'entity_id' => $itemId));
     }
     return $entity;
 }
开发者ID:amit0rana,项目名称:EasyAdminBundle,代码行数:18,代码来源:RequestPostInitializeListener.php

示例6: getActivity

 /**
  * @param object $entity
  * @param string $type
  *
  * @return string
  */
 protected function getActivity($entity, $type)
 {
     $em = $this->registry->getManagerForClass(ActivityList::ENTITY_NAME);
     /** @var ActivityListRepository $repository */
     $repository = $em->getRepository(ActivityList::ENTITY_NAME);
     $count = $repository->getRecordsCountForTargetClassAndId(ClassUtils::getClass($entity), $entity->getId(), [$type]);
     return $count;
 }
开发者ID:Maksold,项目名称:platform,代码行数:14,代码来源:ActivityAccessor.php

示例7: onSuccess

 /**
  * @param GridView $entity
  */
 protected function onSuccess(GridView $entity)
 {
     $default = $this->form->get('is_default')->getData();
     $this->setDefaultGridView($entity, $default);
     $this->fixFilters($entity);
     $om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
     $om->persist($entity);
     $om->flush();
 }
开发者ID:ramunasd,项目名称:platform,代码行数:12,代码来源:GridViewApiHandler.php

示例8: setUp

 protected function setUp()
 {
     $this->initClient();
     $this->getContainer()->get('akeneo_batch.job_repository')->getJobManager()->beginTransaction();
     $this->dropJobsRecords();
     $this->registry = $this->getContainer()->get('doctrine');
     $this->entityManager = $this->registry->getManagerForClass('OroWorkflowBundle:ProcessJob');
     $this->repository = $this->registry->getRepository('OroWorkflowBundle:ProcessJob');
     $this->loadFixtures(['Oro\\Bundle\\WorkflowBundle\\Tests\\Functional\\DataFixtures\\LoadProcessEntities']);
 }
开发者ID:ramunasd,项目名称:platform,代码行数:10,代码来源:ProcessJobRepositoryTest.php

示例9: getAuthorisedOrganizationIds

 /**
  * Returns a list of organization ids for which, current user has permission to update them.
  *
  * @return array
  */
 protected function getAuthorisedOrganizationIds()
 {
     /** @var EntityManager $manager */
     $manager = $this->doctrine->getManagerForClass('OroOrganizationBundle:Organization');
     $qb = $manager->createQueryBuilder();
     $qb->select('o.id')->from('OroOrganizationBundle:Organization', 'o');
     $query = $qb->getQuery();
     $query = $this->aclHelper->apply($query, 'EDIT');
     $result = $query->getArrayResult();
     $result = array_map('current', $result);
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:MailboxGridListener.php

示例10: onChangePassword

 public function onChangePassword(ChangePasswordEvent $event)
 {
     $user = $event->getUser();
     $objectManager = $this->registry->getManagerForClass(get_class($user));
     if (isset($objectManager)) {
         $encoder = $this->encoderFactory->getEncoder($user);
         $password = $encoder->encodePassword($event->getPlainPassword(), $user->getSalt());
         $accessor = new PropertyAccessor();
         $accessor->setValue($user, 'password', $password);
         $objectManager->persist($user);
         $objectManager->flush();
     }
 }
开发者ID:szymach,项目名称:admin-security-bundle,代码行数:13,代码来源:DoctrineChangePasswordListener.php

示例11: __construct

 /**
  * @param Registry $em
  * @param string $class
  */
 public function __construct(Registry $em, $class, Request $request)
 {
     $this->em = $em->getManagerForClass($class);
     $this->class = $class;
     $this->repository = $em->getRepository($class);
     $this->request = $request;
 }
开发者ID:profcab,项目名称:ilios,代码行数:11,代码来源:PublishEventManager.php

示例12: setDefaultGridView

 /**
  * @param User     $user
  * @param GridView $gridView
  * @param bool     $default
  */
 public function setDefaultGridView(User $user, GridView $gridView, $default)
 {
     $isGridViewDefault = $gridView->getUsers()->contains($user);
     // Checks if default grid view changed
     if ($isGridViewDefault !== $default) {
         $om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
         /** @var GridViewRepository $repository */
         $repository = $om->getRepository('OroDataGridBundle:GridView');
         $gridViews = $repository->findDefaultGridViews($this->aclHelper, $user, $gridView, false);
         foreach ($gridViews as $view) {
             $view->removeUser($user);
         }
         if ($default) {
             $gridView->addUser($user);
         }
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:22,代码来源:GridViewManager.php

示例13: load

 public function load($key, array $options, DefinitionRegistry $registry)
 {
     $definition = new Definition($options['entity'], $this->doctrine->getManagerForClass($options['entity']));
     $definition->setTemplates($this->getTemplateDefinition($options['templates']));
     $definition->setObjectRetriever($options['object_retriever']);
     $definition->setController($options['controller']);
     $definition->setFlags(['create' => $options['create'], 'update' => $options['update'], 'delete' => $options['delete']]);
     $definition->setIndex($this->getIndexDefinition($key, $options));
     $definition->setForm($this->getFormDefinition($options['form'], $options['form_options_provider']));
     $definition->setName($key);
     if (null === $options['title']) {
         $definition->setEntityTitle(ucfirst(str_replace(['-', '_', '.'], ' ', $key)));
     } else {
         $definition->setEntityTitle($options['title']);
     }
     $definition->setExtras($options['extras']);
     $registry->addDefinition($definition, $key);
 }
开发者ID:bravesheep,项目名称:crudify-bundle,代码行数:18,代码来源:DIDefinitionLoader.php

示例14: process

 /**
  * @param ShoppingList $shoppingList
  *
  * @return bool
  */
 public function process(ShoppingList $shoppingList)
 {
     $this->form->setData($shoppingList);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($shoppingList->getId() === null) {
                 $this->manager->setCurrent($shoppingList->getAccountUser(), $shoppingList);
             } else {
                 $em = $this->doctrine->getManagerForClass('OroB2BShoppingListBundle:ShoppingList');
                 $em->persist($shoppingList);
                 $em->flush();
             }
             return true;
         }
     }
     return false;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:23,代码来源:ShoppingListHandler.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     if (!$constraint instanceof TreeChoice) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\TreeParent');
     }
     $class = get_class($entity);
     $em = $this->registry->getManagerForClass($class);
     if (!$em) {
         throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', $class));
     }
     $reader = new AnnotationReader();
     $metadata = $em->getClassMetadata($class);
     $properties = $metadata->getReflectionProperties();
     $idProperty = $metadata->getIdentifier();
     if (count($idProperty) > 1) {
         throw new ConstraintDefinitionException('Entity is not allowed to have more than one identifier field to be ' . 'part of a unique constraint in: ' . $metadata->getName());
     }
     $idProperty = $idProperty[0];
     $parentProperty = null;
     foreach ($properties as $property) {
         if ($reader->getPropertyAnnotation($property, static::PARENT_ANNOTATION)) {
             $parentProperty = $property->getName();
             break;
         }
     }
     if (null === $parentProperty) {
         throw new ConstraintDefinitionException('Neither of property of class: ' . $class . ' does not contain annotation:' . static::PARENT_ANNOTATION);
     }
     $parentEntity = $this->propertyAccessor->getValue($entity, $parentProperty);
     if (null === $parentEntity) {
         return;
     }
     if (!$parentEntity instanceof $class) {
         throw new ConstraintDefinitionException('Parent property value should be instance of: ' . $class . ' but given instance of: ' . get_class($parentEntity));
     }
     $entityId = $this->propertyAccessor->getValue($entity, $idProperty);
     $parentId = $this->propertyAccessor->getValue($parentEntity, $idProperty);
     if ($entityId === $parentId) {
         $this->context->buildViolation($constraint->message)->atPath($parentProperty)->addViolation();
     }
 }
开发者ID:snovichkov,项目名称:TreeChoiceBundle,代码行数:44,代码来源:TreeChoiceValidator.php


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