本文整理汇总了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;
}
示例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;
}
示例3: onSuccess
/**
* @param GridView $entity
*/
protected function onSuccess(GridView $entity)
{
$this->fixFilters($entity);
$om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
$om->persist($entity);
$om->flush();
}
示例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'));
}
示例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;
}
示例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;
}
示例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();
}
示例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']);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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();
}
}