PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.11.1
Independent Analytics – WordPress Analytics Plugin v2.11.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / vendor / illuminate / database / Capsule / Manager.php
Manager.php
180 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Capsule;
4
5 use IAWPSCOPED\Illuminate\Container\Container;
6 use IAWPSCOPED\Illuminate\Contracts\Events\Dispatcher;
7 use IAWPSCOPED\Illuminate\Database\Connectors\ConnectionFactory;
8 use IAWPSCOPED\Illuminate\Database\DatabaseManager;
9 use IAWPSCOPED\Illuminate\Database\Eloquent\Model as Eloquent;
10 use IAWPSCOPED\Illuminate\Support\Traits\CapsuleManagerTrait;
11 use PDO;
12 /** @internal */
13 class Manager
14 {
15 use CapsuleManagerTrait;
16 /**
17 * The database manager instance.
18 *
19 * @var \Illuminate\Database\DatabaseManager
20 */
21 protected $manager;
22 /**
23 * Create a new database capsule manager.
24 *
25 * @param \Illuminate\Container\Container|null $container
26 * @return void
27 */
28 public function __construct(Container $container = null)
29 {
30 $this->setupContainer($container ?: new Container());
31 // Once we have the container setup, we will setup the default configuration
32 // options in the container "config" binding. This will make the database
33 // manager work correctly out of the box without extreme configuration.
34 $this->setupDefaultConfiguration();
35 $this->setupManager();
36 }
37 /**
38 * Setup the default database configuration options.
39 *
40 * @return void
41 */
42 protected function setupDefaultConfiguration()
43 {
44 $this->container['config']['database.fetch'] = PDO::FETCH_OBJ;
45 $this->container['config']['database.default'] = 'default';
46 }
47 /**
48 * Build the database manager instance.
49 *
50 * @return void
51 */
52 protected function setupManager()
53 {
54 $factory = new ConnectionFactory($this->container);
55 $this->manager = new DatabaseManager($this->container, $factory);
56 }
57 /**
58 * Get a connection instance from the global manager.
59 *
60 * @param string|null $connection
61 * @return \Illuminate\Database\Connection
62 */
63 public static function connection($connection = null)
64 {
65 return static::$instance->getConnection($connection);
66 }
67 /**
68 * Get a fluent query builder instance.
69 *
70 * @param \Closure|\Illuminate\Database\Query\Builder|string $table
71 * @param string|null $as
72 * @param string|null $connection
73 * @return \Illuminate\Database\Query\Builder
74 */
75 public static function table($table, $as = null, $connection = null)
76 {
77 return static::$instance->connection($connection)->table($table, $as);
78 }
79 /**
80 * Get a schema builder instance.
81 *
82 * @param string|null $connection
83 * @return \Illuminate\Database\Schema\Builder
84 */
85 public static function schema($connection = null)
86 {
87 return static::$instance->connection($connection)->getSchemaBuilder();
88 }
89 /**
90 * Get a registered connection instance.
91 *
92 * @param string|null $name
93 * @return \Illuminate\Database\Connection
94 */
95 public function getConnection($name = null)
96 {
97 return $this->manager->connection($name);
98 }
99 /**
100 * Register a connection with the manager.
101 *
102 * @param array $config
103 * @param string $name
104 * @return void
105 */
106 public function addConnection(array $config, $name = 'default')
107 {
108 $connections = $this->container['config']['database.connections'];
109 $connections[$name] = $config;
110 $this->container['config']['database.connections'] = $connections;
111 }
112 /**
113 * Bootstrap Eloquent so it is ready for usage.
114 *
115 * @return void
116 */
117 public function bootEloquent()
118 {
119 Eloquent::setConnectionResolver($this->manager);
120 // If we have an event dispatcher instance, we will go ahead and register it
121 // with the Eloquent ORM, allowing for model callbacks while creating and
122 // updating "model" instances; however, it is not necessary to operate.
123 if ($dispatcher = $this->getEventDispatcher()) {
124 Eloquent::setEventDispatcher($dispatcher);
125 }
126 }
127 /**
128 * Set the fetch mode for the database connections.
129 *
130 * @param int $fetchMode
131 * @return $this
132 */
133 public function setFetchMode($fetchMode)
134 {
135 $this->container['config']['database.fetch'] = $fetchMode;
136 return $this;
137 }
138 /**
139 * Get the database manager instance.
140 *
141 * @return \Illuminate\Database\DatabaseManager
142 */
143 public function getDatabaseManager()
144 {
145 return $this->manager;
146 }
147 /**
148 * Get the current event dispatcher instance.
149 *
150 * @return \Illuminate\Contracts\Events\Dispatcher|null
151 */
152 public function getEventDispatcher()
153 {
154 if ($this->container->bound('events')) {
155 return $this->container['events'];
156 }
157 }
158 /**
159 * Set the event dispatcher instance to be used by connections.
160 *
161 * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
162 * @return void
163 */
164 public function setEventDispatcher(Dispatcher $dispatcher)
165 {
166 $this->container->instance('events', $dispatcher);
167 }
168 /**
169 * Dynamically pass methods to the default connection.
170 *
171 * @param string $method
172 * @param array $parameters
173 * @return mixed
174 */
175 public static function __callStatic($method, $parameters)
176 {
177 return static::connection()->{$method}(...$parameters);
178 }
179 }
180