当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManagerInterface::getConnection方法代码示例

本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getConnection方法的具体用法?PHP EntityManagerInterface::getConnection怎么用?PHP EntityManagerInterface::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\EntityManagerInterface的用法示例。


在下文中一共展示了EntityManagerInterface::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConnection

 /**
  * @return Connection
  */
 public function getConnection()
 {
     /** @var Connection $con */
     $con = $this->em->getConnection();
     $con = $this->pingIt($con);
     return $con;
 }
开发者ID:arnulfojr,项目名称:qcharts,代码行数:10,代码来源:DynamicEntityManager.php

示例2: 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);
     }
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:40,代码来源:UrlShortener.php

示例3: execute

 public function execute()
 {
     $criteria = new Criteria(['owner' => $this->user], null, null, null);
     $items = $this->basketRepository->findByCriteria($criteria);
     $order = $this->orderRepository->findActive();
     $connection = $this->entityManager->getConnection();
     $connection->beginTransaction();
     try {
         $orderItems = [];
         foreach ($items as $item) {
             /** @var Basket $item */
             $previousOrderItem = $this->orderItemRepository->findOneByCriteria(new Criteria(['owner' => $item->getOwner(), 'product' => $item->getProduct()]));
             if ($previousOrderItem) {
                 /** @var OrderItem $orderItem */
                 $orderItem = $previousOrderItem;
                 $orderItem->increaseQuantityBy($item->getQuantity());
             } else {
                 $orderItem = OrderItem::createFromBasket($item, $order);
             }
             $this->entityManager->persist($orderItem);
             $this->entityManager->remove($item);
             $orderItems[] = $orderItem;
         }
         $this->entityManager->flush();
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         return $e->getMessage();
     }
 }
开发者ID:drymek,项目名称:fcs-backend,代码行数:30,代码来源:BasketItemOrderAction.php

示例4: purgeDatabase

 /**
  * @BeforeScenario
  */
 public function purgeDatabase()
 {
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $purger = new ORMPurger($this->entityManager);
     $purger->purge();
     $this->entityManager->clear();
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:10,代码来源:DoctrineORMContext.php

示例5: encode

 /**
  * @param Url $url
  * @return Url|object
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function encode(Url $url)
 {
     $this->em->beginTransaction();
     try {
         $urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
         $entity = $urlRepository->findOneBy(['url' => $url->getUrl()]);
         if ($entity) {
             /** @var Url $url */
             $url = $entity;
         } else {
             $url->setNew(true);
             $this->em->persist($url);
             $this->em->flush();
             $url->setCode($this->encoder->encode($url->getId()));
             $params = ['code' => $url->getCode()];
             if (!$url->isDefaultSequence()) {
                 $params['index'] = $url->getSequence();
             }
             $url->setShortUrl($this->router->generate(UrlShortenerBundle::URL_GO, $params, UrlGeneratorInterface::ABSOLUTE_URL));
             $this->em->persist($url);
             $this->em->flush();
         }
         $this->em->getConnection()->commit();
         return $url;
     } catch (\Exception $e) {
         $this->em->getConnection()->rollBack();
         throw $e;
     }
 }
开发者ID:RuslanZavacky,项目名称:url-shortener-api,代码行数:35,代码来源:Shortener.php

示例6: purgeUsingCachedQueries

 private function purgeUsingCachedQueries()
 {
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     foreach ($this->cachedQueries as $cachedQuery) {
         $this->entityManager->getConnection()->executeUpdate($cachedQuery['sql'], $cachedQuery['params'], $cachedQuery['types']);
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:7,代码来源:ORMPurger.php

示例7: loadCountry

 /**
  * Load country data
  *
  * @param string $countryIso Country iso
  *
  * @return $this Self object
  */
 public function loadCountry($countryIso)
 {
     $content = $this->locationLoaderAdapter->getSqlForCountry($countryIso);
     $statement = $this->locationEntityManager->getConnection()->prepare($content);
     $statement->execute();
     return $this;
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:14,代码来源:LocationLoader.php

示例8: 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();
 }
开发者ID:Reallymute,项目名称:IRMApplicative,代码行数:28,代码来源:CarmaWebTestCase.php

示例9: executeSqlFile

 /**
  * Executes given sql file
  *
  * @param string $path
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Exception
  */
 private function executeSqlFile($path)
 {
     if (!file_exists($path)) {
         throw new \Exception(sprintf('SQL file does not exist: %s', $path));
     }
     $databaseSchema = file_get_contents($path);
     $this->entityManager->getConnection()->exec($databaseSchema);
 }
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:15,代码来源:DatabaseSchemaCreator.php

示例10: purgeDatabase

 /**
  * @BeforeScenario
  */
 public function purgeDatabase()
 {
     if (null === $this->entityManager) {
         throw new \RuntimeException('Cannot purge database. Entity manager is not set');
     }
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $purger = new ORMPurger($this->entityManager);
     $purger->purge();
     $this->entityManager->clear();
 }
开发者ID:ahmadrabie,项目名称:Sylius,代码行数:13,代码来源:DoctrineORMContext.php

示例11: defer

 /**
  * Defer task.
  *
  * @param int      $pid
  * @param callable $deferrer
  *
  * @return $this
  */
 public function defer($pid, $deferrer)
 {
     $connection = $this->entityManager->getConnection();
     $this->entity->setPid($pid);
     $this->entityManager->flush();
     $connection->close();
     $exitCode = $deferrer();
     $connection->connect();
     $this->entity->setExitCode($exitCode);
     $this->entityManager->flush();
     return $this;
 }
开发者ID:gravitymedia,项目名称:commander,代码行数:20,代码来源:Task.php

示例12: __construct

 /**
  * @param EntityManager $em
  * @param Cache $cache
  * @param CacheHitsContainer $hitsContainer
  */
 public function __construct(EntityManagerInterface $em, Cache $cache, CacheHitsContainer $hitsContainer)
 {
     $this->em = $em;
     $this->connection = $em->getConnection();
     $this->cache = $cache;
     $this->hitsContainer = $hitsContainer;
 }
开发者ID:lsnova,项目名称:simple-query-executor,代码行数:12,代码来源:DbCacheableExecutor.php

示例13: __construct

 /**
  * @param EntityManagerInterface $em
  */
 public function __construct(EntityManagerInterface $em)
 {
     $params = $em->getConnection()->getParams();
     $dsn = "mysql:host={$params['host']};dbname={$params['dbname']}";
     $this->pdo = new PDO($dsn, $params['user'], $params['password']);
     $this->pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
 }
开发者ID:b4nan,项目名称:doctrine,代码行数:10,代码来源:DatabaseBackup.php

示例14: getTargetPlatform

 /**
  * @return Platforms\AbstractPlatform
  */
 private function getTargetPlatform()
 {
     if (!$this->targetPlatform) {
         $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
     }
     return $this->targetPlatform;
 }
开发者ID:StoshSeb,项目名称:doctrine2,代码行数:10,代码来源:ClassMetadataFactory.php

示例15: getUpdateSchemaSql

 /**
  * Gets the sequence of SQL statements that need to be performed in order
  * to bring the given class mappings in-synch with the relational schema.
  * If $saveMode is set to true the command is executed in the Database,
  * else SQL is returned.
  *
  * @param array   $classes  The classes to consider.
  * @param boolean $saveMode True for writing to DB, false for SQL string.
  *
  * @return array The sequence of SQL statements.
  */
 public function getUpdateSchemaSql(array $classes, $saveMode = false)
 {
     $sm = $this->em->getConnection()->getSchemaManager();
     $fromSchema = $sm->createSchema();
     $toSchema = $this->getSchemaFromMetadata($classes);
     foreach ($toSchema->getTables() as $table) {
         foreach ($table->getColumns() as $column) {
             if ($column->getAutoincrement()) {
                 continue;
             }
             if (!preg_match('/^(?P<column>(?P<table>.*)_id)$/', $column->getName(), $matches)) {
                 continue;
             }
             $referencedTable = 'oc_' . $matches['table'];
             if (!$toSchema->hasTable($referencedTable)) {
                 continue;
             }
             if ($toSchema->getTable($referencedTable) === $table) {
                 continue;
             }
             $table->addForeignKeyConstraint($toSchema->getTable($referencedTable), [$matches['column']], [$matches['column']]);
         }
     }
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     foreach ($schemaDiff->changedTables as $changedTable) {
         $changedTable->changedColumns = [];
     }
     if ($saveMode) {
         return $schemaDiff->toSaveSql($this->platform);
     }
     return $schemaDiff->toSql($this->platform);
 }
开发者ID:jkhaled,项目名称:OpenCartDoctrineSchema,代码行数:44,代码来源:SchemaTool.patched.php


注:本文中的Doctrine\ORM\EntityManagerInterface::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。