1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,148 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-namespace Illuminate\Support; |
|
4 |
- |
|
5 |
-use Closure; |
|
6 |
-use InvalidArgumentException; |
|
7 |
- |
|
8 |
-abstract class Manager |
|
9 |
-{ |
|
10 |
- /** |
|
11 |
- * The application instance. |
|
12 |
- * |
|
13 |
- * @var \Illuminate\Contracts\Foundation\Application |
|
14 |
- */ |
|
15 |
- protected $app; |
|
16 |
- |
|
17 |
- /** |
|
18 |
- * The registered custom driver creators. |
|
19 |
- * |
|
20 |
- * @var array |
|
21 |
- */ |
|
22 |
- protected $customCreators = []; |
|
23 |
- |
|
24 |
- /** |
|
25 |
- * The array of created "drivers". |
|
26 |
- * |
|
27 |
- * @var array |
|
28 |
- */ |
|
29 |
- protected $drivers = []; |
|
30 |
- |
|
31 |
- /** |
|
32 |
- * Create a new manager instance. |
|
33 |
- * |
|
34 |
- * @param \Illuminate\Contracts\Foundation\Application $app |
|
35 |
- * @return void |
|
36 |
- */ |
|
37 |
- public function __construct($app) |
|
38 |
- { |
|
39 |
- $this->app = $app; |
|
40 |
- } |
|
41 |
- |
|
42 |
- /** |
|
43 |
- * Get the default driver name. |
|
44 |
- * |
|
45 |
- * @return string |
|
46 |
- */ |
|
47 |
- abstract public function getDefaultDriver(); |
|
48 |
- |
|
49 |
- /** |
|
50 |
- * Get a driver instance. |
|
51 |
- * |
|
52 |
- * @param string $driver |
|
53 |
- * @return mixed |
|
54 |
- * |
|
55 |
- * @throws \InvalidArgumentException |
|
56 |
- */ |
|
57 |
- public function driver($driver = null) |
|
58 |
- { |
|
59 |
- $driver = $driver ?: $this->getDefaultDriver(); |
|
60 |
- |
|
61 |
- if (is_null($driver)) { |
|
62 |
- throw new InvalidArgumentException(sprintf( |
|
63 |
- 'Unable to resolve NULL driver for [%s].', static::class |
|
64 |
- )); |
|
65 |
- } |
|
66 |
- |
|
67 |
- // If the given driver has not been created before, we will create the instances |
|
68 |
- // here and cache it so we can return it next time very quickly. If there is |
|
69 |
- // already a driver created by this name, we'll just return that instance. |
|
70 |
- if (! isset($this->drivers[$driver])) { |
|
71 |
- $this->drivers[$driver] = $this->createDriver($driver); |
|
72 |
- } |
|
73 |
- |
|
74 |
- return $this->drivers[$driver]; |
|
75 |
- } |
|
76 |
- |
|
77 |
- /** |
|
78 |
- * Create a new driver instance. |
|
79 |
- * |
|
80 |
- * @param string $driver |
|
81 |
- * @return mixed |
|
82 |
- * |
|
83 |
- * @throws \InvalidArgumentException |
|
84 |
- */ |
|
85 |
- protected function createDriver($driver) |
|
86 |
- { |
|
87 |
- // First, we will determine if a custom driver creator exists for the given driver and |
|
88 |
- // if it does not we will check for a creator method for the driver. Custom creator |
|
89 |
- // callbacks allow developers to build their own "drivers" easily using Closures. |
|
90 |
- if (isset($this->customCreators[$driver])) { |
|
91 |
- return $this->callCustomCreator($driver); |
|
92 |
- } else { |
|
93 |
- $method = 'create'.Str::studly($driver).'Driver'; |
|
94 |
- |
|
95 |
- if (method_exists($this, $method)) { |
|
96 |
- return $this->$method(); |
|
97 |
- } |
|
98 |
- } |
|
99 |
- throw new InvalidArgumentException("Driver [$driver] not supported."); |
|
100 |
- } |
|
101 |
- |
|
102 |
- /** |
|
103 |
- * Call a custom driver creator. |
|
104 |
- * |
|
105 |
- * @param string $driver |
|
106 |
- * @return mixed |
|
107 |
- */ |
|
108 |
- protected function callCustomCreator($driver) |
|
109 |
- { |
|
110 |
- return $this->customCreators[$driver]($this->app); |
|
111 |
- } |
|
112 |
- |
|
113 |
- /** |
|
114 |
- * Register a custom driver creator Closure. |
|
115 |
- * |
|
116 |
- * @param string $driver |
|
117 |
- * @param \Closure $callback |
|
118 |
- * @return $this |
|
119 |
- */ |
|
120 |
- public function extend($driver, Closure $callback) |
|
121 |
- { |
|
122 |
- $this->customCreators[$driver] = $callback; |
|
123 |
- |
|
124 |
- return $this; |
|
125 |
- } |
|
126 |
- |
|
127 |
- /** |
|
128 |
- * Get all of the created "drivers". |
|
129 |
- * |
|
130 |
- * @return array |
|
131 |
- */ |
|
132 |
- public function getDrivers() |
|
133 |
- { |
|
134 |
- return $this->drivers; |
|
135 |
- } |
|
136 |
- |
|
137 |
- /** |
|
138 |
- * Dynamically call the default driver instance. |
|
139 |
- * |
|
140 |
- * @param string $method |
|
141 |
- * @param array $parameters |
|
142 |
- * @return mixed |
|
143 |
- */ |
|
144 |
- public function __call($method, $parameters) |
|
145 |
- { |
|
146 |
- return $this->driver()->$method(...$parameters); |
|
147 |
- } |
|
148 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,148 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Illuminate\Support; |
|
4 |
+ |
|
5 |
+use Closure; |
|
6 |
+use InvalidArgumentException; |
|
7 |
+ |
|
8 |
+abstract class Manager |
|
9 |
+{ |
|
10 |
+ /** |
|
11 |
+ * The application instance. |
|
12 |
+ * |
|
13 |
+ * @var \Illuminate\Contracts\Foundation\Application |
|
14 |
+ */ |
|
15 |
+ protected $app; |
|
16 |
+ |
|
17 |
+ /** |
|
18 |
+ * The registered custom driver creators. |
|
19 |
+ * |
|
20 |
+ * @var array |
|
21 |
+ */ |
|
22 |
+ protected $customCreators = []; |
|
23 |
+ |
|
24 |
+ /** |
|
25 |
+ * The array of created "drivers". |
|
26 |
+ * |
|
27 |
+ * @var array |
|
28 |
+ */ |
|
29 |
+ protected $drivers = []; |
|
30 |
+ |
|
31 |
+ /** |
|
32 |
+ * Create a new manager instance. |
|
33 |
+ * |
|
34 |
+ * @param \Illuminate\Contracts\Foundation\Application $app |
|
35 |
+ * @return void |
|
36 |
+ */ |
|
37 |
+ public function __construct($app) |
|
38 |
+ { |
|
39 |
+ $this->app = $app; |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ /** |
|
43 |
+ * Get the default driver name. |
|
44 |
+ * |
|
45 |
+ * @return string |
|
46 |
+ */ |
|
47 |
+ abstract public function getDefaultDriver(); |
|
48 |
+ |
|
49 |
+ /** |
|
50 |
+ * Get a driver instance. |
|
51 |
+ * |
|
52 |
+ * @param string $driver |
|
53 |
+ * @return mixed |
|
54 |
+ * |
|
55 |
+ * @throws \InvalidArgumentException |
|
56 |
+ */ |
|
57 |
+ public function driver($driver = null) |
|
58 |
+ { |
|
59 |
+ $driver = $driver ?: $this->getDefaultDriver(); |
|
60 |
+ |
|
61 |
+ if (is_null($driver)) { |
|
62 |
+ throw new InvalidArgumentException(sprintf( |
|
63 |
+ 'Unable to resolve NULL driver for [%s].', static::class |
|
64 |
+ )); |
|
65 |
+ } |
|
66 |
+ |
|
67 |
+ // If the given driver has not been created before, we will create the instances |
|
68 |
+ // here and cache it so we can return it next time very quickly. If there is |
|
69 |
+ // already a driver created by this name, we'll just return that instance. |
|
70 |
+ if (! isset($this->drivers[$driver])) { |
|
71 |
+ $this->drivers[$driver] = $this->createDriver($driver); |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ return $this->drivers[$driver]; |
|
75 |
+ } |
|
76 |
+ |
|
77 |
+ /** |
|
78 |
+ * Create a new driver instance. |
|
79 |
+ * |
|
80 |
+ * @param string $driver |
|
81 |
+ * @return mixed |
|
82 |
+ * |
|
83 |
+ * @throws \InvalidArgumentException |
|
84 |
+ */ |
|
85 |
+ protected function createDriver($driver) |
|
86 |
+ { |
|
87 |
+ // First, we will determine if a custom driver creator exists for the given driver and |
|
88 |
+ // if it does not we will check for a creator method for the driver. Custom creator |
|
89 |
+ // callbacks allow developers to build their own "drivers" easily using Closures. |
|
90 |
+ if (isset($this->customCreators[$driver])) { |
|
91 |
+ return $this->callCustomCreator($driver); |
|
92 |
+ } else { |
|
93 |
+ $method = 'create'.Str::studly($driver).'Driver'; |
|
94 |
+ |
|
95 |
+ if (method_exists($this, $method)) { |
|
96 |
+ return $this->$method(); |
|
97 |
+ } |
|
98 |
+ } |
|
99 |
+ throw new InvalidArgumentException("Driver [$driver] not supported."); |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ /** |
|
103 |
+ * Call a custom driver creator. |
|
104 |
+ * |
|
105 |
+ * @param string $driver |
|
106 |
+ * @return mixed |
|
107 |
+ */ |
|
108 |
+ protected function callCustomCreator($driver) |
|
109 |
+ { |
|
110 |
+ return $this->customCreators[$driver]($this->app); |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ /** |
|
114 |
+ * Register a custom driver creator Closure. |
|
115 |
+ * |
|
116 |
+ * @param string $driver |
|
117 |
+ * @param \Closure $callback |
|
118 |
+ * @return $this |
|
119 |
+ */ |
|
120 |
+ public function extend($driver, Closure $callback) |
|
121 |
+ { |
|
122 |
+ $this->customCreators[$driver] = $callback; |
|
123 |
+ |
|
124 |
+ return $this; |
|
125 |
+ } |
|
126 |
+ |
|
127 |
+ /** |
|
128 |
+ * Get all of the created "drivers". |
|
129 |
+ * |
|
130 |
+ * @return array |
|
131 |
+ */ |
|
132 |
+ public function getDrivers() |
|
133 |
+ { |
|
134 |
+ return $this->drivers; |
|
135 |
+ } |
|
136 |
+ |
|
137 |
+ /** |
|
138 |
+ * Dynamically call the default driver instance. |
|
139 |
+ * |
|
140 |
+ * @param string $method |
|
141 |
+ * @param array $parameters |
|
142 |
+ * @return mixed |
|
143 |
+ */ |
|
144 |
+ public function __call($method, $parameters) |
|
145 |
+ { |
|
146 |
+ return $this->driver()->$method(...$parameters); |
|
147 |
+ } |
|
148 |
+} |