1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Database;
|
4 |
|
|
|
5 |
|
|
class ConnectionResolver implements ConnectionResolverInterface
|
6 |
|
|
{
|
7 |
|
|
/**
|
8 |
|
|
* All of the registered connections.
|
9 |
|
|
*
|
10 |
|
|
* @var array
|
11 |
|
|
*/
|
12 |
|
|
protected $connections = [];
|
13 |
|
|
|
14 |
|
|
/**
|
15 |
|
|
* The default connection name.
|
16 |
|
|
*
|
17 |
|
|
* @var string
|
18 |
|
|
*/
|
19 |
|
|
protected $default;
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Create a new connection resolver instance.
|
23 |
|
|
*
|
24 |
|
|
* @param array $connections
|
25 |
|
|
* @return void
|
26 |
|
|
*/
|
27 |
|
|
public function __construct(array $connections = [])
|
28 |
|
|
{
|
29 |
|
|
foreach ($connections as $name => $connection) {
|
30 |
|
|
$this->addConnection($name, $connection);
|
31 |
|
|
}
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* Get a database connection instance.
|
36 |
|
|
*
|
37 |
|
|
* @param string $name
|
38 |
|
|
* @return \Illuminate\Database\ConnectionInterface
|
39 |
|
|
*/
|
40 |
|
|
public function connection($name = null)
|
41 |
|
|
{
|
42 |
|
|
if (is_null($name)) {
|
43 |
|
|
$name = $this->getDefaultConnection();
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
return $this->connections[$name];
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Add a connection to the resolver.
|
51 |
|
|
*
|
52 |
|
|
* @param string $name
|
53 |
|
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
54 |
|
|
* @return void
|
55 |
|
|
*/
|
56 |
|
|
public function addConnection($name, ConnectionInterface $connection)
|
57 |
|
|
{
|
58 |
|
|
$this->connections[$name] = $connection;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Check if a connection has been registered.
|
63 |
|
|
*
|
64 |
|
|
* @param string $name
|
65 |
|
|
* @return bool
|
66 |
|
|
*/
|
67 |
|
|
public function hasConnection($name)
|
68 |
|
|
{
|
69 |
|
|
return isset($this->connections[$name]);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Get the default connection name.
|
74 |
|
|
*
|
75 |
|
|
* @return string
|
76 |
|
|
*/
|
77 |
|
|
public function getDefaultConnection()
|
78 |
|
|
{
|
79 |
|
|
return $this->default;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
/**
|
83 |
|
|
* Set the default connection name.
|
84 |
|
|
*
|
85 |
|
|
* @param string $name
|
86 |
|
|
* @return void
|
87 |
|
|
*/
|
88 |
|
|
public function setDefaultConnection($name)
|
89 |
|
|
{
|
90 |
|
|
$this->default = $name;
|
91 |
|
|
}
|
92 |
|
|
}
|