本文整理汇总了PHP中Illuminate\Database\ConnectionResolverInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionResolverInterface类的具体用法?PHP ConnectionResolverInterface怎么用?PHP ConnectionResolverInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectionResolverInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* connects the database, saves SQL-Connection, database-name and prefix
* @param ConnectionResolverInterface $db
* @throws \ErrorException
*/
public function __construct(ConnectionResolverInterface $db)
{
try {
/** @var Connection $connection */
$connection = $db->connection();
$this->sql = $connection->getPdo();
$this->db = $connection->getConfig('database');
$this->pref = $connection->getConfig('prefix');
} catch (\Exception $e) {
$this->sql = false;
$this->error = $e->getMessage();
throw new \ErrorException('No Connection to Database: ' . $e->getMessage());
}
}
示例2: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (!$this->confirmToProceed()) {
return;
}
$this->resolver->setDefaultConnection($this->getDatabase());
$this->getSeeder()->run();
}
示例3: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$name = $this->input->getOption('database');
$total = $this->seeder->seed($this->resolver->connection($name), $this->path);
if ($total == 0) {
$this->info('Nothing to seed.');
}
}
示例4: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (!$this->confirmToProceed()) {
return;
}
$this->resolver->setDefaultConnection($this->getDatabase());
Model::unguarded(function () {
$this->getSeeder()->__invoke();
});
}
示例5: handle
/**
* @return mixed
*/
public function handle()
{
// TODO: Implement handle() method.
if (!$this->confirmToProceed()) {
return;
}
$this->resolver->setDefaultConnection($this->getDatabase());
Model::unguarded(function () {
$this->getSeeder()->run();
});
}
示例6: handle
/**
* @param Request $request
* @param Closure $next
* @return mixed
* @throws \Exception
*/
public function handle(Request $request, Closure $next)
{
$this->connectionResolver->connection()->beginTransaction();
try {
$response = $next($request);
} catch (\Exception $e) {
$this->connectionResolver->connection()->rollBack();
throw $e;
}
$this->connectionResolver->connection()->commit();
return $response;
}
示例7: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$tenants = $this->manager->getRepository()->getTenants();
$seeder = $this->getSeeder();
foreach ($tenants as $tenant) {
$this->manager->bootstrapConnectionByTenantName($tenant->tenant_name);
$this->resolver->setDefaultConnection($tenant->tenant_name);
$this->manager->assumeTenant($tenant->id, true);
$seeder->run();
$this->output->writeln('<info>Seeded tenant ' . $tenant->tenant_name . '</info>');
$this->manager->restoreTenant();
}
}
示例8: setConnection
/**
* Set the default connection name.
*
* @param string $name
* @return void
*/
public function setConnection($name)
{
if (!is_null($name)) {
$this->resolver->setDefaultConnection($name);
}
$this->repository->setSource($name);
$this->connection = $name;
}
示例9: table
/**
* Get a query builder for the given table.
*
* @param string $table
* @return \Illuminate\Database\Query\Builder
*/
protected function table($table)
{
return $this->db->connection($this->connection)->table($table);
}
示例10: table
/**
* Get a query builder for the given table.
*
* @param string $table
* @return \Illuminate\Database\Query\Builder
*/
protected function table($table)
{
return $this->db->connection($this->connection)->table($table)->useWritePdo();
}
示例11: getConnection
/**
* Get the connection.
*
* @return \Illuminate\Database\ConnectionInterface
*/
protected function getConnection()
{
return $this->resolver->connection($this->connectionName);
}
示例12: resolveConnection
/**
* Resolve a connection instance by name.
*
* @param string $connection
* @return Illuminate\Database\Connection
*/
public static function resolveConnection($connection)
{
return static::$resolver->connection($connection);
}
示例13: microtime
function it_should_get_connection_for_source()
{
$connection = microtime();
$this->resolver->connection($this->source)->willReturn($connection);
$this->getConnection()->shouldBe($connection);
}
示例14: connect
/**
* Establish a queue connection.
*
* @param array $config
* @return \Illuminate\Contracts\Queue\Queue
*/
public function connect(array $config)
{
return new DatabaseQueue($this->connections->connection(array_get($config, 'connection')), array_get($config, 'table', 'queues'), array_get($config, 'queue', null), array_get($config, 'expire', 60), array_get($config, 'lock_type', 60));
}
示例15: errorException
/**
* @Transactional(value="testing",expect=\LogicException::class)
*
* @return string
*/
public function errorException()
{
$this->db->connection()->statement('CREATE TABLE tests (test varchar(255) NOT NULL)');
$this->db->connection()->table("tests")->insert(['test' => 'testing']);
throw new \LogicException();
}