PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
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 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / support / MultipleInstanceManager.php
independent-analytics / vendor / illuminate / support Last commit date
Facades 2 years ago Testing 2 years ago Traits 2 years ago AggregateServiceProvider.php 2 years ago Carbon.php 2 years ago Composer.php 2 years ago ConfigurationUrlParser.php 2 years ago DateFactory.php 2 years ago Env.php 2 years ago Fluent.php 2 years ago HigherOrderTapProxy.php 2 years ago HtmlString.php 2 years ago InteractsWithTime.php 2 years ago Js.php 2 years ago Manager.php 2 years ago MessageBag.php 2 years ago MultipleInstanceManager.php 2 years ago NamespacedItemResolver.php 2 years ago Optional.php 2 years ago Pluralizer.php 2 years ago ProcessUtils.php 2 years ago Reflector.php 2 years ago ServiceProvider.php 2 years ago Str.php 2 years ago Stringable.php 2 years ago Timebox.php 2 years ago ValidatedInput.php 2 years ago ViewErrorBag.php 2 years ago helpers.php 2 years ago
MultipleInstanceManager.php
169 lines
1 <?php
2
3 namespace IAWP_SCOPED\Illuminate\Support;
4
5 use Closure;
6 use InvalidArgumentException;
7 use RuntimeException;
8 /** @internal */
9 abstract class MultipleInstanceManager
10 {
11 /**
12 * The application instance.
13 *
14 * @var \Illuminate\Contracts\Foundation\Application
15 */
16 protected $app;
17 /**
18 * The array of resolved instances.
19 *
20 * @var array
21 */
22 protected $instances = [];
23 /**
24 * The registered custom instance creators.
25 *
26 * @var array
27 */
28 protected $customCreators = [];
29 /**
30 * Create a new manager instance.
31 *
32 * @param \Illuminate\Contracts\Foundation\Application $app
33 * @return void
34 */
35 public function __construct($app)
36 {
37 $this->app = $app;
38 }
39 /**
40 * Get the default instance name.
41 *
42 * @return string
43 */
44 public abstract function getDefaultInstance();
45 /**
46 * Set the default instance name.
47 *
48 * @param string $name
49 * @return void
50 */
51 public abstract function setDefaultInstance($name);
52 /**
53 * Get the instance specific configuration.
54 *
55 * @param string $name
56 * @return array
57 */
58 public abstract function getInstanceConfig($name);
59 /**
60 * Get an instance instance by name.
61 *
62 * @param string|null $name
63 * @return mixed
64 */
65 public function instance($name = null)
66 {
67 $name = $name ?: $this->getDefaultInstance();
68 return $this->instances[$name] = $this->get($name);
69 }
70 /**
71 * Attempt to get an instance from the local cache.
72 *
73 * @param string $name
74 * @return mixed
75 */
76 protected function get($name)
77 {
78 return $this->instances[$name] ?? $this->resolve($name);
79 }
80 /**
81 * Resolve the given instance.
82 *
83 * @param string $name
84 * @return mixed
85 *
86 * @throws \InvalidArgumentException
87 */
88 protected function resolve($name)
89 {
90 $config = $this->getInstanceConfig($name);
91 if (\is_null($config)) {
92 throw new InvalidArgumentException("Instance [{$name}] is not defined.");
93 }
94 if (!\array_key_exists('driver', $config)) {
95 throw new RuntimeException("Instance [{$name}] does not specify a driver.");
96 }
97 if (isset($this->customCreators[$config['driver']])) {
98 return $this->callCustomCreator($config);
99 } else {
100 $driverMethod = 'create' . \ucfirst($config['driver']) . 'Driver';
101 if (\method_exists($this, $driverMethod)) {
102 return $this->{$driverMethod}($config);
103 } else {
104 throw new InvalidArgumentException("Instance driver [{$config['driver']}] is not supported.");
105 }
106 }
107 }
108 /**
109 * Call a custom instance creator.
110 *
111 * @param array $config
112 * @return mixed
113 */
114 protected function callCustomCreator(array $config)
115 {
116 return $this->customCreators[$config['driver']]($this->app, $config);
117 }
118 /**
119 * Unset the given instances.
120 *
121 * @param array|string|null $name
122 * @return $this
123 */
124 public function forgetInstance($name = null)
125 {
126 $name = $name ?? $this->getDefaultInstance();
127 foreach ((array) $name as $instanceName) {
128 if (isset($this->instances[$instanceName])) {
129 unset($this->instances[$instanceName]);
130 }
131 }
132 return $this;
133 }
134 /**
135 * Disconnect the given instance and remove from local cache.
136 *
137 * @param string|null $name
138 * @return void
139 */
140 public function purge($name = null)
141 {
142 $name = $name ?? $this->getDefaultInstance();
143 unset($this->instances[$name]);
144 }
145 /**
146 * Register a custom instance creator Closure.
147 *
148 * @param string $name
149 * @param \Closure $callback
150 * @return $this
151 */
152 public function extend($name, Closure $callback)
153 {
154 $this->customCreators[$name] = $callback->bindTo($this, $this);
155 return $this;
156 }
157 /**
158 * Dynamically call the default instance.
159 *
160 * @param string $method
161 * @param array $parameters
162 * @return mixed
163 */
164 public function __call($method, $parameters)
165 {
166 return $this->instance()->{$method}(...$parameters);
167 }
168 }
169