本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::getConnection方法的具体用法?PHP EntityManager::getConnection怎么用?PHP EntityManager::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kdyby\Doctrine\EntityManager
的用法示例。
在下文中一共展示了EntityManager::getConnection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clearDatabase
public function clearDatabase()
{
$connection = $this->em->getConnection();
$tables = $connection->getSchemaManager()->listTableNames();
$connection->prepare('SET FOREIGN_KEY_CHECKS = 0')->execute();
foreach ($tables as $table) {
if ($table !== 'db_version') {
$connection->prepare('TRUNCATE TABLE ' . $table)->execute();
}
}
$connection->prepare('SET FOREIGN_KEY_CHECKS = 1')->execute();
}
示例2: invalidate
public function invalidate()
{
$ormConfig = $this->entityManager->getConfiguration();
$dbalConfig = $this->entityManager->getConnection()->getConfiguration();
$cache = array($ormConfig->getHydrationCacheImpl(), $ormConfig->getMetadataCacheImpl(), $ormConfig->getQueryCacheImpl(), $ormConfig->getResultCacheImpl(), $dbalConfig->getResultCacheImpl());
foreach ($cache as $impl) {
if (!$impl instanceof CacheProvider) {
continue;
}
$impl->deleteAll();
}
}
示例3: process
public function process(AMQPMessage $message) : int
{
try {
if (!($request = Json::decode($message->body, Json::FORCE_ARRAY))) {
return self::MSG_REJECT;
}
} catch (JsonException $e) {
$this->logger->addError($e->getMessage());
return self::MSG_REJECT;
}
$orderId = $request['orderId'];
try {
$conn = $this->em->getConnection();
if ($conn->ping() === false) {
$conn->close();
$conn->connect();
}
/** @var Order $order */
$orders = $this->em->getRepository(Order::class);
if (!($order = $orders->find($orderId))) {
$this->logger->addWarning(sprintf('Order %s not found in db', $orderId));
return self::MSG_REJECT;
}
if (!$order->getUser()) {
$this->logger->addWarning(sprintf('Order %s has no user', $orderId));
return self::MSG_REJECT;
}
$this->user->passwordLessLogin($order->getUser()->getId());
return $this->processOrder($order, $request['options']);
} catch (\App\Exception\DatabaseDeadlockException $e) {
return $this->restartJob($request, $e);
} catch (\Doctrine\DBAL\Exception\DriverException $e) {
if ($deadlock = \App\Exception\DatabaseDeadlockException::fromDriverException($e)) {
$e = $deadlock;
$message = null;
} else {
$this->logger->addError($e->getMessage(), ['exception' => $e]);
$message = $e->getPrevious() instanceof \Doctrine\DBAL\Driver\PDOException ? $e->getPrevious()->getMessage() : $e->getMessage();
}
return $this->restartJob($request, $e, $message);
} catch (\Exception $e) {
$this->logger->addError($this->getQueue(), ['exception' => $e]);
return $this->restartJob($request, $e);
} finally {
$this->user->logout(true);
$this->em->clear();
}
}
示例4: invalidate
public function invalidate()
{
$ormConfig = $this->entityManager->getConfiguration();
$dbalConfig = $this->entityManager->getConnection()->getConfiguration();
$cache = $this->cacheStorages;
$cache[] = $ormConfig->getHydrationCacheImpl();
$cache[] = $ormConfig->getMetadataCacheImpl();
$cache[] = $ormConfig->getQueryCacheImpl();
$cache[] = $ormConfig->getResultCacheImpl();
$cache[] = $dbalConfig->getResultCacheImpl();
foreach ($cache as $impl) {
if (!$impl instanceof ClearableCache) {
continue;
}
$impl->deleteAll();
}
}
示例5: __construct
/**
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->em = $em;
$this->db = $em->getConnection();
$this->platform = $this->db->getDatabasePlatform();
$this->quotes = $em->getConfiguration()->getQuoteStrategy();
$this->uow = $this->em->getUnitOfWork();
}
示例6: getWrappedPDOConnection
/**
* @return IWrappedConnection
*/
private function getWrappedPDOConnection()
{
$wrappedConnection = $this->entityManager->getConnection()->getWrappedConnection();
if (!$wrappedConnection instanceof IWrappedConnection) {
$message = sprintf('Change "preventImplicitFlush" to FALSE or set doctrine connection "driverClass" to %s.', MySqlDriver::class);
throw new LogicException($message);
}
return $wrappedConnection;
}
示例7: setupLocalityEntity
/**
* @param Locality $locality
* @return Locality
* @throws \Doctrine\DBAL\DBALException
* @throws \Exception
*/
public function setupLocalityEntity(Locality $locality)
{
/* In order to NOT auto increment locality ID counter in DB by
INSERTs that actually wont happen (e.g. safePersist()) and
because Doctrine2 does NOT support locking of entire tables,
we have to use native SQL(MySQL) query.
DUAL is "dummy" table - there is no need to reference any table
(more info in MySQL SELECT documentation)
*/
$this->em->getConnection()->executeQuery('INSERT INTO locality (name)
SELECT :name FROM DUAL
WHERE NOT EXISTS(
SELECT l.name
FROM locality l
WHERE l.name = :name)
LIMIT 1', ['name' => $locality->getName()]);
$result = $this->em->createQuery('SELECT l FROM ' . Locality::class . ' l
WHERE l.name = :name')->setParameters(['name' => $locality->getName()])->getSingleResult();
return $result;
}
示例8: setupWorkedHoursEntity
/**
* @param WorkedHours $workedHours
* @return WorkedHours
* @throws \Doctrine\DBAL\DBALException
* @throws \Exception
*/
public function setupWorkedHoursEntity(WorkedHours $workedHours)
{
$values = $workedHours->toArray(true);
/* In order to NOT auto increment workedHours ID counter in DB by
INSERTs that actually wont happen (e.g. safePersist()) and
because Doctrine2 does NOT support locking of entire tables,
we have to use native SQL(MySQL) query.
DUAL is "dummy" table - there is no need to reference any table
(more info in MySQL SELECT documentation)
*/
$this->em->getConnection()->executeQuery('INSERT INTO worked_hours (work_start, work_end, lunch, other_hours)
SELECT :workStart, :workEnd, :lunch, :otherHours FROM DUAL
WHERE NOT EXISTS(
SELECT work_start, work_end, lunch, other_hours
FROM worked_hours
WHERE work_start = :workStart AND work_end = :workEnd AND
lunch = :lunch AND other_hours = :otherHours)
LIMIT 1', $values);
$result = $this->em->createQuery('SELECT wh FROM ' . WorkedHours::class . ' wh
WHERE wh.workStart = :workStart AND wh.workEnd = :workEnd AND
wh.lunch = :lunch AND wh.otherHours = :otherHours')->setParameters($values)->getOneOrNullResult();
return $result;
}