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


PHP RegistryInterface::getManager方法代码示例

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


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

示例1: generateEntity

 /**
  * Generate the entity PHP code.
  *
  * @param BundleInterface $bundle
  * @param string          $name
  * @param array           $fields
  * @param string          $namePrefix
  * @param string          $dbPrefix
  * @param string|null     $extendClass
  *
  * @return array
  * @throws \RuntimeException
  */
 protected function generateEntity(BundleInterface $bundle, $name, $fields, $namePrefix, $dbPrefix, $extendClass = null)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager(null)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity\\' . $namePrefix), $config->getEntityNamespaces()));
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $namePrefix . '\\' . $name;
     $entityPath = $bundle->getPath() . '/Entity/' . $namePrefix . '/' . str_replace('\\', '/', $name) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
     }
     $class = new ClassMetadataInfo($entityClass, new UnderscoreNamingStrategy());
     foreach ($fields as $fieldSet) {
         foreach ($fieldSet as $fieldArray) {
             foreach ($fieldArray as $field) {
                 if (array_key_exists('joinColumn', $field)) {
                     $class->mapManyToOne($field);
                 } elseif (array_key_exists('joinTable', $field)) {
                     $class->mapManyToMany($field);
                 } else {
                     $class->mapField($field);
                 }
             }
         }
     }
     $class->setPrimaryTable(array('name' => strtolower($dbPrefix . strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name))) . 's'));
     $entityCode = $this->getEntityGenerator($extendClass)->generateEntityClass($class);
     return array($entityCode, $entityPath);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:41,代码来源:KunstmaanGenerator.php

示例2: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$this->context instanceof ExecutionContext) {
         throw new UnexpectedTypeException($this->context, ExecutionContext::class);
     }
     if (!$constraint instanceof UniqueUser) {
         throw new UnexpectedTypeException($constraint, UniqueUser::class);
     }
     // just return null if the value is empty
     // since an empty value cannot exist in the database
     // and should be validated using the NotBlank constraint
     if (null === $value) {
         return;
     }
     if (!is_string($value) && !is_object($value) && !method_exists($constraint, '__toString')) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $entityManager = $this->registry->getManager($constraint->entityManager);
     if (!$entityManager) {
         throw new RuntimeException(sprintf('Invalid manager "%s"!', $constraint->entityManager));
     }
     $repository = $entityManager->getRepository($constraint->entity);
     $result = $repository->findOneBy([$constraint->property => $value]);
     if (null !== $result) {
         $this->context->buildViolation($constraint->message)->setInvalidValue($value)->setParameter('%prop%', $constraint->property)->addViolation();
     }
 }
开发者ID:thesoftwarefactoryuk,项目名称:SenNetwork,代码行数:30,代码来源:UniqueUserValidator.php

示例3: generate

 /**
  * Generate Fixture from bundle name, entity name, fixture name and ids
  *
  * @param BundleInterface $bundle
  * @param string          $entity
  * @param string          $name
  * @param array           $ids
  * @param string|null     $connectionName
  */
 public function generate(BundleInterface $bundle, $entity, $name, array $ids, $order, $connectionName = null)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager($connectionName)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
     $fixtureFileName = $this->getFixtureFileName($entity, $name, $ids);
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
     $fixturePath = $bundle->getPath() . '/DataFixtures/ORM/' . $fixtureFileName . '.php';
     $bundleNameSpace = $bundle->getNamespace();
     if (file_exists($fixturePath)) {
         throw new \RuntimeException(sprintf('Fixture "%s" already exists.', $fixtureFileName));
     }
     $class = new ClassMetadataInfo($entityClass);
     $fixtureGenerator = $this->getFixtureGenerator();
     $fixtureGenerator->setFixtureName($fixtureFileName);
     $fixtureGenerator->setBundleNameSpace($bundleNameSpace);
     $fixtureGenerator->setMetadata($class);
     $fixtureGenerator->setFixtureOrder($order);
     /** @var EntityManager $em */
     $em = $this->registry->getManager($connectionName);
     $repo = $em->getRepository($class->rootEntityName);
     if (empty($ids)) {
         $items = $repo->findAll();
     } else {
         $items = $repo->findById($ids);
     }
     $fixtureGenerator->setItems($items);
     $fixtureCode = $fixtureGenerator->generateFixtureClass($class);
     $this->filesystem->mkdir(dirname($fixturePath));
     file_put_contents($fixturePath, $fixtureCode);
 }
开发者ID:GMBN,项目名称:DoctrineFixturesGeneratorBundle,代码行数:40,代码来源:DoctrineFixtureGenerator.php

示例4: order

 /**
  * {@inheritdoc}
  */
 public function order(OrderInterface $order)
 {
     if (!$order->getId()) {
         throw new \RuntimeException('The order is not persisted into the database');
     }
     $this->generateReference($order, $this->registry->getManager()->getClassMetadata(get_class($order))->table['name']);
 }
开发者ID:sonata-project,项目名称:ecommerce,代码行数:10,代码来源:MysqlReference.php

示例5: getSideBar

 /**
  * @param \Twig_Environment $twig
  * @return string
  */
 public function getSideBar(\Twig_Environment $twig)
 {
     $em = $this->doctrine->getManager();
     $posts = $em->getRepository('AppBundle:Post')->showMostPopularPost();
     $comments = $em->getRepository('AppBundle:Comment')->showLastFiveComment();
     $tags = $em->getRepository('AppBundle:Tag')->showNotNullTags();
     return $twig->render('@App/sidebar.html.twig', array('posts' => $posts, 'comments' => $comments, 'tags' => $tags));
 }
开发者ID:alexgoncharcherkassy,项目名称:blog,代码行数:12,代码来源:AppExtension.php

示例6: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke(UserActivateCommand $command)
 {
     $user = $command->getUser();
     $user->setEnabled(true);
     $em = $this->registry->getManager();
     $em->persist($user);
     $em->flush();
 }
开发者ID:NoUseFreak,项目名称:brokkes,代码行数:11,代码来源:UserActivateHandler.php

示例7: updateEntities

 /**
  * Mass updates entities
  *
  * @param string $class
  * @param array  $data
  * @param array  $ids
  */
 public function updateEntities($class, array $data, array $ids)
 {
     $qb = $this->doctrine->getManager()->createQueryBuilder()->update($class, 'o')->where('o.id IN (:ids)')->setParameter('ids', $ids);
     foreach ($data as $key => $value) {
         $qb->set("o.{$key}", ":{$key}")->setParameter(":{$key}", $value);
     }
     $qb->getQuery()->execute();
 }
开发者ID:ronanguilloux,项目名称:CustomEntityBundle,代码行数:15,代码来源:MassUpdater.php

示例8: hydrate

 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $entityId = $metaInformation->getEntityId();
     $doctrineEntity = $this->doctrine->getManager()->getRepository($metaInformation->getClassName())->find($entityId);
     if ($doctrineEntity !== null) {
         $metaInformation->setEntity($doctrineEntity);
     }
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
开发者ID:zquintana,项目名称:SolrBundle,代码行数:12,代码来源:DoctrineHydrator.php

示例9: getChannelReference

 /**
  * @return Channel|bool
  */
 protected function getChannelReference()
 {
     $channelId = $this->request->query->get('channelId');
     if (!empty($channelId)) {
         /** @var EntityManager $em */
         $em = $this->registry->getManager();
         return $em->getReference('OroCRMChannelBundle:Channel', $channelId);
     }
     return false;
 }
开发者ID:antrampa,项目名称:crm,代码行数:13,代码来源:RequestChannelProvider.php

示例10: execute

 /**
  * {@inheritDoc}
  *
  * @param Notify $request
  */
 public function execute($request)
 {
     $notification = new NotificationDetails();
     $request->getToken() ? $notification->setGatewayName($request->getToken()->getGatewayName()) : $notification->setGatewayName('unknown');
     $this->gateway->execute($getHttpRequest = new GetHttpRequest());
     $notification->setDetails($getHttpRequest->query);
     $notification->setCreatedAt(new \DateTime());
     $this->doctrine->getManager()->persist($notification);
     $this->doctrine->getManager()->flush();
 }
开发者ID:partkeepr,项目名称:PayumBundleSandbox,代码行数:15,代码来源:StoreNotificationAction.php

示例11: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke(UserRegisterCommand $command)
 {
     $user = $command->getUser();
     $user->setUsername($user->getEmail());
     $em = $this->registry->getManager();
     $em->persist($user);
     $em->flush();
     $hash = password_hash($user->getSalt(), PASSWORD_DEFAULT);
     $message = \Swift_Message::newInstance()->setSubject('Brökkes Account validation')->setFrom('send@example.com')->setTo($user->getEmail())->setBody($this->templating->render(':Email:registration.html.twig', ['hash' => urlencode($hash), 'user' => $user]), 'text/html')->addPart($this->templating->render(':Email:registration.txt.twig', ['hash' => urlencode($hash), 'user' => $user]), 'text/plain');
     $this->mailer->send($message);
 }
开发者ID:NoUseFreak,项目名称:brokkes,代码行数:14,代码来源:UserRegisterHandler.php

示例12: trainContainer

 protected function trainContainer()
 {
     $this->request->getSession()->willReturn($this->session);
     $this->request->getLocale()->willReturn('fr_FR');
     $this->doctrine->getManager()->willReturn($this->manager);
     $this->doctrine->getManager()->willReturn($this->manager);
     $this->doctrine->getRepository('DonateCoreBundle:Intent')->willReturn($this->intentRepository);
     $this->container->has('doctrine')->willReturn(true);
     $this->container->get('doctrine')->willReturn($this->doctrine);
     $this->container->get('request')->willReturn($this->request);
     $this->container->get('donate_core.payment_method_discovery')->willReturn($this->discovery);
     $this->container->get('event_dispatcher')->willReturn($this->dispatcher);
     $this->container->get('logger')->willReturn($this->logger);
 }
开发者ID:bco-trey,项目名称:edonate,代码行数:14,代码来源:DefaultIntentManagerSpec.php

示例13: execute

 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var NotifyRequest $request */
     $notification = new NotificationDetails();
     if ($request instanceof SecuredNotifyRequest) {
         $notification->setPaymentName($request->getToken()->getPaymentName());
     } else {
         $notification->setPaymentName('unknown');
     }
     $notification->setDetails($request->getNotification());
     $notification->setCreatedAt(new \DateTime());
     $this->doctrine->getManager()->persist($notification);
     $this->doctrine->getManager()->flush();
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:17,代码来源:StoreNotificationAction.php

示例14: rotate

 /**
  * Rotates imported feeds
  *
  * @param Feed    $feed The feed to rotate imports for
  * @param integer $max  The number of imports to keep
  */
 public function rotate(Feed $feed, $max = 4)
 {
     /** @var ImportRepository $repo */
     $repo = $this->doctrine->getRepository('FMIoBundle:Import');
     $imports = $repo->findCompletedByFeed($feed);
     if (sizeof($imports) <= $max) {
         return;
     }
     $manager = $this->doctrine->getManager();
     foreach (array_slice($imports, $max) as $import) {
         $this->eventDispatcher->dispatch(IoEvents::IMPORT_ROTATE, new ImportEvent($import));
         $manager->remove($import);
         $manager->flush();
     }
 }
开发者ID:mvanduijker,项目名称:FMIoBundle,代码行数:21,代码来源:ImportRotator.php

示例15: __construct

 /**
  * @param string                    $name
  * @param EngineInterface           $templating
  * @param RegistryInterface         $registry
  * @param CurrencyDetectorInterface $currencyDetector
  * @param ProductFinderInterface    $productFinder
  * @param string                    $productClass
  */
 public function __construct($name, EngineInterface $templating, RegistryInterface $registry, CurrencyDetectorInterface $currencyDetector, ProductFinderInterface $productFinder, $productClass)
 {
     $this->productRepository = $registry->getManager()->getRepository($productClass);
     $this->currencyDetector = $currencyDetector;
     $this->productFinder = $productFinder;
     parent::__construct($name, $templating);
 }
开发者ID:sonata-project,项目名称:ecommerce,代码行数:15,代码来源:SimilarProductsBlockService.php


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