1 | <?php |
||
8 | class HashidManager extends Manager |
||
9 | { |
||
10 | /** |
||
11 | * Get a hashid connection instance. |
||
12 | * |
||
13 | * @param string|null $name |
||
14 | * @return mixed |
||
15 | */ |
||
16 | 10 | public function connection($name = null) |
|
20 | |||
21 | /** |
||
22 | * Get all of the created connections. |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | 1 | public function getConnections() |
|
30 | |||
31 | /** |
||
32 | * Get the default connection name. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | 2 | public function getDefaultConnection() |
|
40 | |||
41 | /** |
||
42 | * Set the default connection name. |
||
43 | * |
||
44 | * @param string $name |
||
45 | * @return $this |
||
46 | */ |
||
47 | 1 | public function setDefaultConnection($name) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 1 | public function getDefaultDriver() |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 10 | protected function createDriver($name) |
|
87 | |||
88 | /** |
||
89 | * Create a new hashid connection instance. |
||
90 | * |
||
91 | * @param array $config |
||
92 | * @return mixed |
||
93 | * |
||
94 | * @throws \InvalidArgumentException |
||
95 | */ |
||
96 | 4 | protected function createConnection(array $config) |
|
97 | { |
||
98 | 4 | if (! isset($config['driver'])) { |
|
99 | 1 | throw new InvalidArgumentException('A driver must be specified.'); |
|
100 | } |
||
101 | |||
102 | 3 | $driver = $config['driver']; |
|
103 | |||
104 | 3 | if ($this->app->bound($key = "hashid.connection.{$driver}")) { |
|
105 | 2 | if ($this->app->isShared($key)) { |
|
106 | 1 | return $this->app->make($key); |
|
107 | } |
||
108 | |||
109 | // `Container::make($abstract, $parameters)` which can |
||
110 | // pass additional parameters to the constructor was removed |
||
111 | // in Laravel 5.4 (https://github.com/laravel/internals/issues/391), |
||
112 | // but then re-added as `makeWith()` in v5.4.16 |
||
113 | // (https://github.com/laravel/framework/pull/18271). And in L55 |
||
114 | // `makeWith()` is just an alias to `make()`. |
||
115 | 1 | $makeWith = method_exists($this->app, 'makeWith') ? 'makeWith' : 'make'; |
|
116 | |||
117 | 1 | return $this->app->{$makeWith}($key, [ |
|
118 | 1 | 'app' => $this->app, |
|
119 | 1 | 'config' => $this->getConfigWithoutDriver($config), |
|
120 | 1 | ]); |
|
121 | } |
||
122 | |||
123 | 1 | throw new InvalidArgumentException("Unsupported driver [$driver]"); |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Get connection configuration without "driver" element. |
||
128 | * |
||
129 | * @param array $config |
||
130 | * @return array |
||
131 | */ |
||
132 | 2 | protected function getConfigWithoutDriver($config) |
|
138 | } |
||
139 |