本文整理汇总了PHP中Doctrine\Common\Persistence\ManagerRegistry::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getConnection方法的具体用法?PHP ManagerRegistry::getConnection怎么用?PHP ManagerRegistry::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ManagerRegistry
的用法示例。
在下文中一共展示了ManagerRegistry::getConnection方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: truncateTable
protected function truncateTable($class, $connection = null)
{
//@TODO Comprendre comment marche exactement getManager et récupérer le manager avec la class
$tableName = $this->getTableName($class, $connection);
$connection = $this->managerRegistry->getConnection($connection);
$connection->exec('DELETE FROM ' . $tableName);
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dbname = $input->getArgument('dbname');
$designdoc = $input->getArgument('designdoc');
$view = $input->getArgument('view');
/** @var \Doctrine\CouchDB\CouchDBClient $client */
$client = $this->registry->getConnection($dbname);
$query = $client->createViewQuery($designdoc, $view);
$ret = $query->execute();
$output->writeln('Updated');
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Bangpound\Bundle\TwitterStreamingBundle\CouchDocument\AtomEntry
$em = $this->registry->getManager();
/** @var \Doctrine\CouchDB\CouchDBClient $default_client */
$default_client = $this->registry->getConnection();
$tag = $input->getArgument('tag');
$outputFile = $input->getOption('output');
$start = \DateTime::createFromFormat('Y-m-d', $input->getOption('start'));
$end = \DateTime::createFromFormat('Y-m-d', $input->getOption('end'));
$limit = 1000;
// Executing the query without grouping allows the view to be refreshed.
/** @var $query */
$query = $default_client->createViewQuery('maint', 'tag');
if ($input->getOption('stale') !== 'ok') {
$output->writeln('Updating view.');
$query->execute();
}
// All other executions will allow stale results.
$query->setGroup(false);
$query->setIncludeDocs(true);
$query->setStale('ok');
$query->setReduce(false);
$query->setStartKey([$tag, (int) $start->format('Y'), (int) $start->format('m'), (int) $start->format('d')]);
$query->setEndKey([$tag, (int) $end->format('Y'), (int) $end->format('m'), (int) $end->format('d')]);
$query->setLimit($limit + 1);
file_put_contents($outputFile, '[');
do {
$result = $query->execute();
$next_start_key = null;
if (count($result) > 0) {
if (count($result) == $limit + 1) {
$next_start_key = $result[$limit]['key'];
$query->setStartKey($result[$limit]['key']);
$query->setStartKeyDocId($result[$limit]['id']);
$output->writeln('resume with ' . implode('-', $result[$limit]['key']) . ' ' . $result[$limit]['id']);
}
$rows = array();
foreach ($result as $i => $row) {
if ($i < $limit) {
$rows[] = json_encode($row['doc']);
}
}
$data = implode(',', $rows);
if ($next_start_key) {
$data .= ',';
}
file_put_contents($outputFile, $data, FILE_APPEND | LOCK_EX);
}
} while ($next_start_key);
file_put_contents($outputFile, ']', FILE_APPEND | LOCK_EX);
}
示例4: putDocumentAction
/**
* Handle article PUT
*/
public function putDocumentAction(Request $request, $id)
{
$path = '/' . $id;
$data = $request->request->all();
$session = $this->registry->getConnection($this->name);
$node = $session->getNode($path);
if (empty($node)) {
throw new ResourceNotFoundException($path . ' not found');
}
$this->fromJsonLD($node, $data);
$session->save();
// return the updated version
$view = View::create($this->toJsonLd($node))->setFormat('json');
return $this->viewHandler->handle($view, $request);
}
示例5: getPlatform
/**
* @return AbstractPlatform
*/
protected function getPlatform()
{
if (!$this->platform) {
$this->platform = $this->managerRegistry->getConnection()->getDatabasePlatform();
}
return $this->platform;
}
示例6: __construct
/**
* Construct AclFilter
*
* @DI\InjectParams({
* "doctrine" = @DI\Inject("doctrine"),
* "securityContext" = @DI\Inject("security.context"),
* "aclWalker" = @DI\Inject("%vib.security.acl_walker%"),
* "roleHierarchy" = @DI\Inject("%security.role_hierarchy.roles%")
* })
*
* @param Doctrine\Common\Persistence\ManagerRegistry $doctrine
* @param Symfony\Component\Security\Core\SecurityContextInterface $securityContext
* @param string $aclWalker
* @param array $roleHierarchy
*/
public function __construct(ManagerRegistry $doctrine, SecurityContextInterface $securityContext, $aclWalker, $roleHierarchy)
{
$this->em = $doctrine->getManager();
$this->securityContext = $securityContext;
$this->aclConnection = $doctrine->getConnection('default');
$this->aclWalker = $aclWalker;
$this->roleHierarchy = $roleHierarchy;
}
示例7: setUp
protected function setUp()
{
$this->registry = new SimpleManagerRegistry(function ($id) {
switch ($id) {
case 'default_connection':
return $this->createConnection();
case 'default_manager':
return $this->createEntityManager($this->registry->getConnection());
default:
throw new \RuntimeException(sprintf('Unknown service id "%s".', $id));
}
});
$this->serializer = SerializerBuilder::create()->setMetadataDriverFactory(new CallbackDriverFactory(function (array $metadataDirs, Reader $annotationReader) {
$defaultFactory = new DefaultDriverFactory();
return new DoctrineTypeDriver($defaultFactory->createDriver($metadataDirs, $annotationReader), $this->registry);
}))->build();
$this->prepareDatabase();
}
示例8: truncateTable
/**
* {@inheritdoc}
*/
public function truncateTable($className)
{
$metadata = $this->getClassMetadata($className);
if ($metadata instanceof ClassMetadata) {
$connection = $this->registry->getConnection();
$connection->beginTransaction();
try {
$sql = 'DELETE FROM :table';
$stmt = $connection->prepare($sql);
$stmt->bindValue('table', $metadata->getTableName());
$stmt->execute();
$connection->commit();
return true;
} catch (\Exception $e) {
$connection->rollback();
}
}
return false;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Bangpound\Bundle\TwitterStreamingBundle\CouchDocument\AtomEntry
$em = $this->registry->getManager();
/** @var \Doctrine\CouchDB\CouchDBClient $default_client */
$default_client = $this->registry->getConnection();
$date = \DateTime::createFromFormat('Y-m-d', $input->getArgument('date'));
$limit = 1000;
// Executing the query without grouping allows the view to be refreshed.
/** @var $query */
$query = $default_client->createViewQuery('maint', 'date');
$output->writeln('Updating view.');
$query->execute();
// All other executions will allow stale results.
$query->setGroup(false);
$query->setIncludeDocs(false);
$query->setStale('ok');
$query->setReduce(false);
$query->setStartKey(array());
$query->setEndKey(array((int) $date->format('Y'), (int) $date->format('m'), (int) $date->format('d'), array()));
$query->setLimit($limit + 1);
do {
$result = $query->execute();
$next_start_key = null;
if (count($result) > 0) {
if (count($result) == $limit + 1) {
$next_start_key = $result[$limit]['key'];
$query->setStartKey($result[$limit]['key']);
$query->setStartKeyDocId($result[$limit]['id']);
$output->writeln('resume with ' . implode('-', $result[$limit]['key']) . ' ' . $result[$limit]['id']);
}
$bulk = $default_client->createBulkUpdater();
foreach ($result as $i => $row) {
if ($i < $limit) {
$bulk->deleteDocument($row['id'], $row['value']);
}
}
$result = $bulk->execute();
}
} while ($next_start_key);
}
示例10: __construct
/**
* Construct AclFilter
*
* @DI\InjectParams({
* "doctrine" = @DI\Inject("doctrine"),
* "tokenStorage" = @DI\Inject("security.token_storage"),
* "aclWalker" = @DI\Inject("%bluemesa_acl.walker%"),
* "roleHierarchy" = @DI\Inject("%security.role_hierarchy.roles%")
* })
*
* @param ManagerRegistry $doctrine
* @param TokenStorageInterface $tokenStorage
* @param string $aclWalker
* @param array $roleHierarchy
* @throws Exception
*/
public function __construct(ManagerRegistry $doctrine, TokenStorageInterface $tokenStorage, $aclWalker, $roleHierarchy)
{
$em = $doctrine->getManager();
if (!$em instanceof EntityManager) {
throw new Exception();
}
$this->em = $em;
$this->tokenStorage = $tokenStorage;
$this->aclConnection = $doctrine->getConnection('default');
$this->aclWalker = $aclWalker;
$this->roleHierarchy = $roleHierarchy;
}
示例11: getConnection
/**
* @param $name
* @return object
*/
public function getConnection($name)
{
return $this->managerRegistry->getConnection($name);
}
示例12: isReservedWord
/**
* Determines whether the given value is reserved SQL word or not
*
* @param string $value
* @return bool
*/
protected function isReservedWord($value)
{
return $this->doctrine->getConnection()->getDatabasePlatform()->getReservedKeywordsList()->isKeyword($value);
}
示例13: getForConnection
/**
* @param string|null $name
*
* @return Configuration
*/
public function getForConnection($name = null)
{
$connection = $this->registry->getConnection($name);
return $this->factory->make($connection);
}