本文整理匯總了PHP中Doctrine\ORM\EntityManagerInterface::close方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManagerInterface::close方法的具體用法?PHP EntityManagerInterface::close怎麽用?PHP EntityManagerInterface::close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::close方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tearDown
protected function tearDown()
{
//Close & unsets
if (is_object($this->em)) {
$this->em->getConnection()->close();
$this->em->close();
}
unset($this->em);
unset($this->container);
unset($this->kern);
unset($this->client);
//Nettoyage des mocks
//http://kriswallsmith.net/post/18029585104/faster-phpunit
$refl = new \ReflectionObject($this);
foreach ($refl->getProperties() as $prop) {
if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
$prop->setAccessible(true);
$prop->setValue($this, null);
}
}
//Nettoyage du garbage
if (!gc_enabled()) {
gc_enable();
}
gc_collect_cycles();
//Parent
parent::tearDown();
}
示例2: execute
/**
* Executes the given command and optionally returns a value
*
* @param object $command
* @param callable $next
* @return mixed
* @throws Exception
*/
public function execute($command, callable $next)
{
$this->entityManager->beginTransaction();
try {
$returnValue = $next($command);
$this->entityManager->flush();
$this->entityManager->commit();
} catch (Exception $e) {
$this->entityManager->close();
$this->entityManager->rollback();
throw $e;
}
return $returnValue;
}
示例3: urlToShortCode
/**
* Creates and persists a unique shortcode generated for provided url
*
* @param UriInterface $url
* @param string[] $tags
* @return string
* @throws InvalidUrlException
* @throws RuntimeException
*/
public function urlToShortCode(UriInterface $url, array $tags = [])
{
// If the url already exists in the database, just return its short code
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy(['originalUrl' => $url]);
if (isset($shortUrl)) {
return $shortUrl->getShortCode();
}
// Check that the URL exists
$this->checkUrlExists($url);
// Transactionally insert the short url, then generate the short code and finally update the short code
try {
$this->em->beginTransaction();
// First, create the short URL with an empty short code
$shortUrl = new ShortUrl();
$shortUrl->setOriginalUrl($url);
$this->em->persist($shortUrl);
$this->em->flush();
// Generate the short code and persist it
$shortCode = $this->convertAutoincrementIdToShortCode($shortUrl->getId());
$shortUrl->setShortCode($shortCode)->setTags($this->tagNamesToEntities($this->em, $tags));
$this->em->flush();
$this->em->commit();
return $shortCode;
} catch (ORMException $e) {
if ($this->em->getConnection()->isTransactionActive()) {
$this->em->rollback();
$this->em->close();
}
throw new RuntimeException('An error occurred while persisting the short URL', -1, $e);
}
}
示例4: tearDown
protected function tearDown()
{
parent::tearDown();
$this->em->close();
}
示例5: commit
/**
* Commits the UnitOfWork, executing all operations that have been postponed
* up to this point. The state of all managed entities will be synchronized with
* the database.
*
* The operations are executed in the following order:
*
* 1) All entity insertions
* 2) All entity updates
* 3) All collection deletions
* 4) All collection updates
* 5) All entity deletions
*
* @param null|object|array $entity
*
* @return void
*
* @throws \Exception
*/
public function commit($entity = null)
{
// Raise preFlush
if ($this->evm->hasListeners(Events::preFlush)) {
$this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));
}
// Compute changes done since last commit.
if ($entity === null) {
$this->computeChangeSets();
} elseif (is_object($entity)) {
$this->computeSingleEntityChangeSet($entity);
} elseif (is_array($entity)) {
foreach ($entity as $object) {
$this->computeSingleEntityChangeSet($object);
}
}
if (!($this->entityInsertions || $this->entityDeletions || $this->entityUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
$this->dispatchOnFlushEvent();
$this->dispatchPostFlushEvent();
return;
// Nothing to do.
}
if ($this->orphanRemovals) {
foreach ($this->orphanRemovals as $orphan) {
$this->remove($orphan);
}
}
$this->dispatchOnFlushEvent();
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->getCommitOrder();
$conn = $this->em->getConnection();
$conn->beginTransaction();
try {
if ($this->entityInsertions) {
foreach ($commitOrder as $class) {
$this->executeInserts($class);
}
}
if ($this->entityUpdates) {
foreach ($commitOrder as $class) {
$this->executeUpdates($class);
}
}
// Extra updates that were requested by persisters.
if ($this->extraUpdates) {
$this->executeExtraUpdates();
}
// Collection deletions (deletions of complete collections)
foreach ($this->collectionDeletions as $collectionToDelete) {
$this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
}
// Collection updates (deleteRows, updateRows, insertRows)
foreach ($this->collectionUpdates as $collectionToUpdate) {
$this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
}
// Entity deletions come last and need to be in reverse commit order
if ($this->entityDeletions) {
for ($count = count($commitOrder), $i = $count - 1; $i >= 0 && $this->entityDeletions; --$i) {
$this->executeDeletions($commitOrder[$i]);
}
}
$conn->commit();
} catch (Exception $e) {
$this->em->close();
$conn->rollback();
$this->afterTransactionRolledBack();
throw $e;
}
$this->afterTransactionComplete();
// Take new snapshots from visited collections
foreach ($this->visitedCollections as $coll) {
$coll->takeSnapshot();
}
$this->dispatchPostFlushEvent();
// Clear up
$this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->extraUpdates = $this->entityChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForSynchronization = $this->orphanRemovals = array();
}
示例6: close
/**
* {@inheritdoc}
*/
public function close()
{
return $this->wrapped->close();
}