本文整理汇总了PHP中Symfony\Bridge\Doctrine\ManagerRegistry::getManager方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getManager方法的具体用法?PHP ManagerRegistry::getManager怎么用?PHP ManagerRegistry::getManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bridge\Doctrine\ManagerRegistry
的用法示例。
在下文中一共展示了ManagerRegistry::getManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpDoctrine
/**
*/
protected function setUpDoctrine()
{
static::bootKernel();
$this->container = static::$kernel->getContainer();
$this->doctrine = $this->createDoctrineRegistry();
$this->em = $this->doctrine->getManager();
$this->loader = new Loader();
}
示例2: isKnownEntityClassNamespace
/**
* Checks whether the given namespace is registered in the Doctrine
*
* @param string $namespace
* @return bool
*/
public function isKnownEntityClassNamespace($namespace)
{
foreach (array_keys($this->doctrine->getManagers()) as $name) {
$namespaces = $this->doctrine->getManager($name)->getConfiguration()->getEntityNamespaces();
if (in_array($namespace, $namespaces, true)) {
return true;
}
}
return false;
}
示例3: createLike
public function createLike(Post $post, $score)
{
// Récupère l'utilisateur courant
$user = $this->tokenStorage->getToken()->getUser();
// Création du postlike
$postLike = new PostLike();
$postLike->setScore($score);
$postLike->setTarget($post);
$postLike->setUser($user);
// Sauvegarde
$em = $this->doctrine->getManager();
$em->persist($postLike);
$em->flush($postLike);
}
示例4: send
public function send()
{
$this->assertTransport();
$marketingList = $this->emailCampaign->getMarketingList();
/** @var EntityManager $manager */
$manager = $this->registry->getManager();
foreach ($this->getIterator() as $entity) {
$to = $this->contactInformationFieldsProvider->getQueryContactInformationFields($marketingList->getSegment(), $entity, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL);
try {
$manager->beginTransaction();
// Do actual send
$this->transport->send($this->emailCampaign, $entity, [$this->getSenderEmail() => $this->getSenderName()], $to);
// Mark marketing list item as contacted
$marketingListItem = $this->marketingListItemConnector->contact($marketingList, $entity->getId());
// Record email campaign contact statistic
$statisticsRecord = new EmailCampaignStatistics();
$statisticsRecord->setEmailCampaign($this->emailCampaign)->setMarketingListItem($marketingListItem);
$manager->persist($statisticsRecord);
$manager->flush();
$manager->commit();
} catch (\Exception $e) {
$manager->rollback();
if ($this->logger) {
$this->logger->error(sprintf('Email sending to "%s" failed.', implode(', ', $to)), array('exception' => $e));
}
}
}
$this->emailCampaign->setSent(true);
$manager->persist($this->emailCampaign);
$manager->flush();
}
示例5: getManager
/**
* @return ObjectManager
*/
protected function getManager()
{
if (!$this->manager) {
$this->manager = $this->doctrine->getManager();
}
return $this->manager;
}
示例6: __construct
/**
* DiffManager constructor.
* @param ManagerRegistry $managerRegistry
* @param string $recolnatAlias
* @param string $recolnatBufferAlias
*/
public function __construct(ManagerRegistry $managerRegistry, $recolnatAlias, $recolnatBufferAlias)
{
$this->managerRegistry = $managerRegistry;
$this->em = $managerRegistry->getManager('default');
$this->recolnatAlias = $recolnatAlias;
$this->recolnatBufferAlias = $recolnatBufferAlias;
}
示例7: __invoke
/**
* Retrieves a collection of resources.
*
* @param Request $request
*
* @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
*
* @throws RuntimeException|RootNodeNotFoundException|RootMayNotBeMovedException|MissingParentCategoryException
*/
public function __invoke(Request $request, $id)
{
list($resourceType) = $this->extractAttributes($request);
$entity = $this->getItem($this->dataProvider, $resourceType, $id);
$parentId = $request->request->get("parent");
$parentEntity = $this->iriConverter->getItemFromIri($parentId);
if ($parentEntity === null) {
throw new MissingParentCategoryException($parentId);
}
if ($entity->getLevel() === 0) {
throw new RootMayNotBeMovedException();
}
$entity->setParent($parentEntity);
$this->registry->getManager()->flush();
return new Response($request->request->get("parent"));
}
示例8: __invoke
/**
* Retrieves a collection of resources.
*
* @param Request $request The request
* @param int $id The ID of the part
*
* @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
*
* @throws RuntimeException|RootNodeNotFoundException
*/
public function __invoke(Request $request, $id)
{
list($resourceType) = $this->extractAttributes($request);
$part = $this->getItem($this->dataProvider, $resourceType, $id);
/**
* @var $part Part
*/
$quantity = $request->request->get("quantity");
$user = $this->userService->getUser();
$stock = new StockEntry(0 - intval($quantity), $user);
if ($request->request->has("comment") && $request->request->get("comment") !== null) {
$stock->setComment($request->request->get("comment"));
}
$part->addStockEntry($stock);
$this->registry->getManager()->persist($stock);
$this->registry->getManager()->flush();
return $part;
}
示例9: isEntity
/**
* @param mixed $object
*
* @return bool
*/
private function isEntity($object)
{
$isEntity = false;
if (is_object($object)) {
$class = $object instanceof Proxy ? get_parent_class($object) : get_class($object);
if (null !== ($manager = $this->registry->getManagerForClass($class))) {
$isEntity = !$this->registry->getManager()->getMetadataFactory()->isTransient($class);
}
}
return $isEntity;
}
示例10: executeJob
/**
* @param string $jobType
* @param string $jobName
* @param array $configuration
* @return JobResult
*/
public function executeJob($jobType, $jobName, array $configuration = array())
{
// create and persist job instance and job execution
$jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName);
$jobInstance->setCode($this->generateJobCode($jobName));
$jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName));
$jobInstance->setRawConfiguration($configuration);
$jobExecution = new JobExecution();
$jobExecution->setJobInstance($jobInstance);
// persist batch entities
$this->batchJobManager->persist($jobInstance);
$this->batchJobManager->persist($jobExecution);
// do job
$jobResult = $this->doJob($jobInstance, $jobExecution);
// EntityManager can be closed when there was an exception in flush method called inside some jobs execution
// Can't be implemented right now due to OroEntityManager external dependencies
// on ExtendManager and FilterCollection
if (!$this->entityManager->isOpen()) {
$this->managerRegistry->resetManager();
$this->entityManager = $this->managerRegistry->getManager();
}
// flush batch entities
$this->batchJobManager->flush($jobInstance);
$this->batchJobManager->flush($jobExecution);
// set data to JobResult
$jobResult->setJobId($jobInstance->getId());
$jobResult->setJobCode($jobInstance->getCode());
// TODO: Find a way to work with multiple amount of job and step executions
// TODO: https://magecore.atlassian.net/browse/BAP-2600
/** @var JobExecution $jobExecution */
$jobExecution = $jobInstance->getJobExecutions()->first();
if ($jobExecution) {
$stepExecution = $jobExecution->getStepExecutions()->first();
if ($stepExecution) {
$context = $this->contextRegistry->getByStepExecution($stepExecution);
$jobResult->setContext($context);
}
}
return $jobResult;
}
示例11: __invoke
/**
* Retrieves a collection of resources.
*
* @param Request $request The request
* @param int $id The ID of the part
*
* @throws RuntimeException|RootNodeNotFoundException
*
* @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
*/
public function __invoke(Request $request, $id)
{
list($resourceType) = $this->extractAttributes($request);
$part = $this->getItem($this->dataProvider, $resourceType, $id);
/*
* @var $part Part
*/
$quantity = $request->request->get('quantity');
$user = $this->userService->getUser();
$oldQuantity = $part->getStockLevel();
$correctionQuantity = $quantity - $oldQuantity;
if ($correctionQuantity != 0) {
$stock = new StockEntry();
$stock->setStockLevel($correctionQuantity);
$stock->setUser($user);
if ($request->request->has('comment') && $request->request->get('comment') !== null) {
$stock->setComment($request->request->get('comment'));
}
$part->addStockLevel($stock);
$this->registry->getManager()->persist($stock);
$this->registry->getManager()->flush();
}
return $part;
}
示例12: loadNameMaps
/**
* Loads table name <-> entity class name maps
*/
protected function loadNameMaps()
{
$this->tableToClassMap = [];
$this->classToTableMap = [];
$names = array_keys($this->doctrine->getManagers());
foreach ($names as $name) {
$manager = $this->doctrine->getManager($name);
if ($manager instanceof EntityManager) {
$allMetadata = $this->getAllMetadata($manager);
foreach ($allMetadata as $metadata) {
$tableName = $metadata->getTableName();
if (!empty($tableName)) {
$className = $metadata->getName();
$this->tableToClassMap[$tableName] = $className;
$this->classToTableMap[$className] = $tableName;
}
}
}
}
}
示例13: send
public function send()
{
if (!$this->assertTransport()) {
return;
}
$marketingList = $this->emailCampaign->getMarketingList();
if (is_null($marketingList)) {
return;
}
$iterator = $this->getIterator();
if (is_null($iterator)) {
return;
}
/** @var EntityManager $manager */
$manager = $this->registry->getManager();
$emailFields = $this->contactInformationFieldsProvider->getMarketingListTypedFields($marketingList, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL);
foreach ($iterator as $entity) {
$to = $this->contactInformationFieldsProvider->getTypedFieldsValues($emailFields, $entity);
$to = array_unique($to);
try {
$manager->beginTransaction();
// Do actual send
$this->transport->send($this->emailCampaign, $entity, [$this->getSenderEmail() => $this->getSenderName()], $to);
$statisticsRecord = $this->statisticsConnector->getStatisticsRecord($this->emailCampaign, $entity);
// Mark marketing list item as contacted
$statisticsRecord->getMarketingListItem()->contact();
$manager->flush($statisticsRecord);
$manager->commit();
} catch (\Exception $e) {
$manager->rollback();
if ($this->logger) {
$this->logger->error(sprintf('Email sending to "%s" failed.', implode(', ', $to)), ['exception' => $e]);
}
}
}
$this->emailCampaign->setSent(true);
$manager->persist($this->emailCampaign);
$manager->flush();
}
示例14: __construct
public function __construct(ManagerRegistry $doctrine, TwigEngine $twig, $template_class)
{
$this->dm = $doctrine->getManager();
$this->twig = $twig;
$this->template_class = $template_class;
}
示例15: initialize
/**
* Initialize environment
*/
protected function initialize()
{
$this->entityManager = $this->managerRegistry->getManager();
}