本文整理汇总了PHP中Symfony\Bridge\Doctrine\RegistryInterface::resetManager方法的典型用法代码示例。如果您正苦于以下问题:PHP RegistryInterface::resetManager方法的具体用法?PHP RegistryInterface::resetManager怎么用?PHP RegistryInterface::resetManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bridge\Doctrine\RegistryInterface
的用法示例。
在下文中一共展示了RegistryInterface::resetManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ensureEntityManagerReady
/**
* Prepares EntityManager, reset it if closed with error
*/
protected function ensureEntityManagerReady()
{
$this->em = $this->registry->getManager();
if (!$this->em->isOpen()) {
$this->registry->resetManager();
$this->ensureEntityManagerReady();
}
}
示例2: rollback
/**
* Closes the entity manager, and rollbacks the pending transaction on the underlying database connection of a
* Doctrine's entity manager with the given name. This method also resets the manager, so as it can be recreated for
* a new transaction, when needed.
*/
protected function rollback()
{
$this->logger->debug(static::class . '::rollback');
$this->getEntityManager()->rollback();
// Close the manager if there is no transaction started.
if (!$this->getEntityManager()->getConnection()->isTransactionActive()) {
$this->getEntityManager()->close();
$this->entityManagerRegistry->resetManager();
}
}
示例3: write
/**
* {@inheritdoc}
*/
public function write(array $items)
{
/** @var EntityManager $em */
$em = $this->registry->getManager();
try {
$em->beginTransaction();
foreach ($items as $item) {
$em->persist($item);
}
$em->flush();
$em->commit();
$configuration = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration();
$contextSkipClear = $this->stepExecution->getJobExecution()->getExecutionContext()->get(EntityWriter::SKIP_CLEAR);
if (empty($configuration[EntityWriter::SKIP_CLEAR]) && !$contextSkipClear) {
$em->clear();
}
} catch (\Exception $exception) {
$em->rollback();
if (!$em->isOpen()) {
$this->registry->resetManager();
}
$jobName = $this->stepExecution->getJobExecution()->getJobInstance()->getAlias();
$event = new WriterErrorEvent($items, $jobName, $exception);
$this->eventDispatcher->dispatch(WriterErrorEvent::NAME, $event);
if ($event->getCouldBeSkipped()) {
$importContext = $this->contextRegistry->getByStepExecution($this->stepExecution);
$importContext->setValue('error_entries_count', (int) $importContext->getValue('error_entries_count') + count($items));
$this->logger->warning($event->getWarning());
if ($event->getException() === $exception) {
// exception are already handled and job can move forward
throw new InvalidItemException($event->getWarning(), []);
} else {
// exception are already created and ready to be rethrown
throw $event->getException();
}
} else {
throw $exception;
}
}
$this->eventDispatcher->dispatch(WriterAfterFlushEvent::NAME, new WriterAfterFlushEvent($em));
}