當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::getConnection方法代碼示例

本文整理匯總了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();
 }
開發者ID:rhrebecek,項目名稱:skeleton,代碼行數:12,代碼來源:DatabaseTester.php

示例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();
     }
 }
開發者ID:peterkrejci,項目名稱:music-collection,代碼行數:12,代碼來源:CacheCleaner.php

示例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();
     }
 }
開發者ID:fprochazka,項目名稱:posobota-rabbitmq-workshop-01-2016,代碼行數:48,代碼來源:BaseSubmitOrderQueue.php

示例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();
     }
 }
開發者ID:richard-ejem,項目名稱:Doctrine,代碼行數:17,代碼來源:CacheCleaner.php

示例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();
 }
開發者ID:peterkrejci,項目名稱:music-collection,代碼行數:11,代碼來源:NonLockingUniqueInserter.php

示例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;
 }
開發者ID:damejidlo,項目名稱:modular-testcase,代碼行數:12,代碼來源:TransactionIsolationModule.php

示例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;
 }
開發者ID:blitzik,項目名稱:vycetky-doctrine,代碼行數:27,代碼來源:LocalityProvider.php

示例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;
 }
開發者ID:blitzik,項目名稱:vycetky-doctrine,代碼行數:30,代碼來源:WorkedHoursProvider.php


注:本文中的Kdyby\Doctrine\EntityManager::getConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。