本文整理汇总了PHP中Doctrine\Common\Persistence\ManagerRegistry::getManager方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getManager方法的具体用法?PHP ManagerRegistry::getManager怎么用?PHP ManagerRegistry::getManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ManagerRegistry
的用法示例。
在下文中一共展示了ManagerRegistry::getManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* DiffAbstract constructor.
* @param ManagerRegistry $managerRegistry
* @param int $maxNbSpecimenPerPass
*/
public function __construct(ManagerRegistry $managerRegistry, $maxNbSpecimenPerPass)
{
$this->maxNbSpecimenPerPass = $maxNbSpecimenPerPass;
$this->managerRegistry = $managerRegistry;
$this->emR = $managerRegistry->getManager('default');
$this->emB = $managerRegistry->getManager('buffer');
}
示例2: prepareDatabase
private function prepareDatabase()
{
/** @var EntityManager $em */
$em = $this->registry->getManager();
$tool = new SchemaTool($em);
$tool->createSchema($em->getMetadataFactory()->getAllMetadata());
}
示例3: onLexikjwtauthenticationOnjwtcreated
public function onLexikjwtauthenticationOnjwtcreated(JWTCreatedEvent $event)
{
$em = $this->registry->getManager();
$data = $event->getData();
$data['wownewfield'] = 'muchcool';
$event->setData($data);
}
示例4: 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));
}
示例5: onConsoleTerminate
/**
* @param ConsoleTerminateEvent $event
*/
public function onConsoleTerminate(ConsoleTerminateEvent $event)
{
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) {
$entities = $this->registry->getRepository('OroSearchBundle:UpdateEntity')->findAll();
if (count($entities)) {
$em = $this->registry->getManager();
foreach ($entities as $entity) {
$job = new Job(ReindexCommand::COMMAND_NAME, ['class' => $entity->getEntity()]);
$em->persist($job);
$em->remove($entity);
}
$em->flush($job);
}
}
}
示例6: isApplicableOnMarketingList
/**
* Checks the object is an instance of a given class.
*
* @param MarketingList $marketingList
* @return bool
*/
public function isApplicableOnMarketingList($marketingList)
{
if ($marketingList instanceof MarketingList) {
return (bool) $this->registry->getManager()->getRepository('OroCRMMailChimpBundle:StaticSegment')->findOneBy(['marketingList' => $marketingList]);
}
return false;
}
示例7: getObjectManager
/**
* @param string $name
*
* @return \Doctrine\Common\Persistence\ObjectManager
*
* @throws \Exception
*/
private function getObjectManager($name)
{
if (null === ($manager = $this->doctrine->getManager($name))) {
throw new \Exception(sprintf('Can\'t find doctrine manager named "%s"'), $name);
}
return $manager;
}
示例8: updateToken
/**
* Updates a Token.
*
* @param Token $token
* @param Boolean $andFlush Whether to flush the changes (default true)
*/
public function updateToken(Token $token, $andFlush = true)
{
$this->doctrine->getManager()->persist($token);
if ($andFlush) {
$this->doctrine->getManager()->flush();
}
}
示例9: getCollection
/**
* @param string $institutionCode
* @param string $collectionCode
* @param User|null $user
* @return Collection|AccessDeniedException
*/
public function getCollection($institutionCode, $collectionCode, User $user = null)
{
$collection = $this->managerRegistry->getManager('default')->getRepository('AppBundle:Collection')->findOneByCollectionAndInstitution($institutionCode, $collectionCode);
if (!is_null($user) && !is_null($collection)) {
$this->checkUserRight($user, $collection);
}
return $collection;
}
示例10: resetDoctrineSchema
/**
* @param string|null $managerName
*
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function resetDoctrineSchema($managerName = null)
{
$manager = $this->doctrine->getManager($managerName);
$metadata = $manager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($manager);
$schemaTool->dropSchema($metadata);
$schemaTool->createSchema($metadata);
}
示例11: validate
/**
* @param object $entity
* @param Constraint $constraint
*/
public function validate($entity, Constraint $constraint)
{
if (!is_array($constraint->fields) && !is_string($constraint->fields)) {
throw new UnexpectedTypeException($constraint->fields, 'array');
}
$fields = (array) $constraint->fields;
if (0 === count($fields)) {
throw new ConstraintDefinitionException('At least one field has to be specified.');
}
if ($constraint->em) {
$em = $this->registry->getManager($constraint->em);
} else {
$em = $this->registry->getManagerForClass(get_class($entity));
}
$className = $this->context->getCurrentClass();
$class = $em->getClassMetadata($className);
/* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$criteria = array();
foreach ($fields as $fieldName) {
if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
throw new ConstraintDefinitionException("Only field names mapped by Doctrine can be validated for uniqueness.");
}
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);
if (null === $criteria[$fieldName]) {
return;
}
if ($class->hasAssociation($fieldName)) {
/* Ensure the Proxy is initialized before using reflection to
* read its identifiers. This is necessary because the wrapped
* getter methods in the Proxy are being bypassed.
*/
$em->initializeObject($criteria[$fieldName]);
$relatedClass = $em->getClassMetadata($class->getAssociationTargetClass($fieldName));
$relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]);
if (count($relatedId) > 1) {
throw new ConstraintDefinitionException("Associated entities are not allowed to have more than one identifier field to be " . "part of a unique constraint in: " . $class->getName() . "#" . $fieldName);
}
$criteria[$fieldName] = array_pop($relatedId);
}
}
$repository = $em->getRepository($className);
$result = $repository->findBy($criteria);
/* If the result is a MongoCursor, it must be advanced to the first
* element. Rewinding should have no ill effect if $result is another
* iterator implementation.
*/
if ($result instanceof \Iterator) {
$result->rewind();
}
/* If no entity matched the query criteria or a single entity matched,
* which is the same as the entity being validated, the criteria is
* unique.
*/
if (0 === count($result) || 1 === count($result) && $entity === ($result instanceof \Iterator ? $result->current() : current($result))) {
return;
}
$this->context->addViolationAtSubPath($fields[0], $constraint->message, array(), $criteria[$fields[0]]);
}
示例12: beforeSuite
/**
* {@inheritdoc}
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options)
{
foreach ($options['managers'] as $managerName) {
/** @var DocumentManager $manager */
$manager = $this->managerRegistry->getManager($managerName);
$purger = new MongoDBPurger($manager);
$purger->purge();
}
}
示例13: isApplicableOnEmailCampaign
/**
* Checks the object is an instance of a given class.
*
* @param EmailCampaign $entity
* @return bool
*/
public function isApplicableOnEmailCampaign($entity)
{
if ($entity instanceof EmailCampaign && $entity->getTransport() == MailChimpTransport::NAME) {
$campaign = $this->registry->getManager()->getRepository('OroCRMMailChimpBundle:Campaign')->findOneBy(['emailCampaign' => $entity]);
return (bool) $campaign;
} else {
return false;
}
}
示例14: removeAll
protected function removeAll()
{
/** @var EntityManager $em */
$em = $this->doctrine->getManager();
foreach ($this->doctrine->getRepository('NetNexusTimesheetBundle:Workitem')->findAll() as $wi) {
$em->remove($wi);
}
$em->flush();
}
示例15: getIdentifierValues
/**
* @param object $value
*
* @throws \InvalidArgumentException When $value is not a Doctrine object
*
* @return array
*/
protected function getIdentifierValues($value)
{
if (!is_object($value)) {
throw new \InvalidArgumentException('Only Doctrine objects can be serialized');
}
$class = get_class($value);
$metadata = $this->doctrine->getManager()->getClassMetadata($class);
return $metadata->getIdentifierValues($value);
}