本文整理汇总了PHP中EntityManager::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::getConnection方法的具体用法?PHP EntityManager::getConnection怎么用?PHP EntityManager::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::getConnection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param Repository $repository
*/
public function __construct(Repository $repository)
{
$this->repository = $repository;
$this->manager = $repository->getManager();
$this->metadata = $repository->getMetadata();
$this->query = $this->manager->getConnection()->createQueryBuilder()->from($this->metadata->getTable());
}
示例2: _generateDiscriminatorColumnConditionSQL
/**
* Generates a discriminator column SQL condition for the class with the given DQL alias.
*
* @param array $dqlAliases List of root DQL aliases to inspect for discriminator restrictions.
* @return string
*/
private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases)
{
$encapsulate = false;
$sql = '';
foreach ($dqlAliases as $dqlAlias) {
$class = $this->_queryComponents[$dqlAlias]['metadata'];
if ($class->isInheritanceTypeSingleTable()) {
$conn = $this->_em->getConnection();
$values = array();
if ($class->discriminatorValue !== null) {
// discrimnators can be 0
$values[] = $conn->quote($class->discriminatorValue);
}
foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->_em->getClassMetadata($subclassName)->discriminatorValue);
}
if ($sql != '') {
$sql .= ' AND ';
$encapsulate = true;
}
$sql .= ($sql != '' ? ' AND ' : '') . ($this->_useSqlTableAliases ? $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.' : '') . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')';
}
}
return $encapsulate ? '(' . $sql . ')' : $sql;
}
示例3: getConnection
public function getConnection()
{
$classMetadata = array();
$this->em = $this->createEntityManager();
$conn = $this->em->getConnection();
$pdo = $conn->getWrappedConnection();
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
if (count($this->classes) > 0) {
foreach ($this->classes as $class) {
$classMetadata[] = $this->em->getClassMetadata($class);
}
} else {
throw new \Doctrine\ORM\ORMException("No associated classes not yet implemented.");
}
$schemaTool->createSchema($classMetadata);
return $this->createDefaultDBConnection($pdo, $conn->getDatabase());
}
示例4: testAuditable
public function testAuditable()
{
$user = new UserAudit("beberlei");
$article = new ArticleAudit("test", "yadda!", $user, 'text');
$this->em->persist($user);
$this->em->persist($article);
$this->em->flush();
$this->assertEquals(1, count($this->em->getConnection()->fetchAll('SELECT id FROM revisions')));
$this->assertEquals(1, count($this->em->getConnection()->fetchAll('SELECT * FROM UserAudit_audit')));
$this->assertEquals(1, count($this->em->getConnection()->fetchAll('SELECT * FROM ArticleAudit_audit')));
$article->setText("oeruoa");
$this->em->flush();
$this->assertEquals(2, count($this->em->getConnection()->fetchAll('SELECT id FROM revisions')));
$this->assertEquals(2, count($this->em->getConnection()->fetchAll('SELECT * FROM ArticleAudit_audit')));
$this->em->remove($user);
$this->em->remove($article);
$this->em->flush();
$this->assertEquals(3, count($this->em->getConnection()->fetchAll('SELECT id FROM revisions')));
$this->assertEquals(2, count($this->em->getConnection()->fetchAll('SELECT * FROM UserAudit_audit')));
$this->assertEquals(3, count($this->em->getConnection()->fetchAll('SELECT * FROM ArticleAudit_audit')));
}
示例5: _generateDiscriminatorColumnConditionSql
/**
* Generates a discriminator column SQL condition for the class with the given DQL alias.
*
* @param string $dqlAlias
* @return string
*/
private function _generateDiscriminatorColumnConditionSql($dqlAlias)
{
$sql = '';
if ($dqlAlias) {
$class = $this->_queryComponents[$dqlAlias]['metadata'];
if ($class->isInheritanceTypeSingleTable()) {
$conn = $this->_em->getConnection();
$values = array($conn->quote($class->discriminatorValue));
foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->_em->getClassMetadata($subclassName)->discriminatorValue);
}
$sql .= ($this->_useSqlTableAliases ? $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias) . '.' : '') . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')';
}
}
return $sql;
}
示例6: _generateDiscriminatorColumnConditionSQL
/**
* Generates a discriminator column SQL condition for the class with the given DQL alias.
*
* @param array $dqlAliases List of root DQL aliases to inspect for discriminator restrictions.
* @return string
*/
private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases)
{
$sqlParts = array();
foreach ($dqlAliases as $dqlAlias) {
$class = $this->queryComponents[$dqlAlias]['metadata'];
if (!$class->isInheritanceTypeSingleTable()) {
continue;
}
$conn = $this->em->getConnection();
$values = array();
if ($class->discriminatorValue !== null) {
// discrimnators can be 0
$values[] = $conn->quote($class->discriminatorValue);
}
foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue);
}
$sqlParts[] = ($this->useSqlTableAliases ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' : '') . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')';
}
$sql = implode(' AND ', $sqlParts);
return count($sqlParts) > 1 ? '(' . $sql . ')' : $sql;
}
示例7: truncate
/**
* Truncate the table for the current entity.
*
* @throws \Doctrine\DBAL\DBALException
*/
public static function truncate()
{
$connection = \EntityManager::getConnection();
$platform = $connection->getDatabasePlatform();
$connection->executeUpdate($platform->getTruncateTableSQL(self::getTable(), false));
}
示例8: __construct
/**
* Constructor.
*
* @param EntityManager $manager
* @param Metadata $metadata
*/
public function __construct(EntityManager $manager, Metadata $metadata)
{
$this->manager = $manager;
$this->metadata = $metadata;
$this->query = $manager->getConnection()->createQueryBuilder()->from($metadata->getTable());
}
示例9: getConnection
/**
*
* @return \dbrecord\Connection
*/
public function getConnection()
{
return $this->em->getConnection();
}