本文整理汇总了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);
}
示例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();
}
}
示例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);
}
示例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']);
}
示例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));
}
示例6: __invoke
/**
* @inheritDoc
*/
public function __invoke(UserActivateCommand $command)
{
$user = $command->getUser();
$user->setEnabled(true);
$em = $this->registry->getManager();
$em->persist($user);
$em->flush();
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
}
示例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);
}