1 | <?php |
||
65 | class Loader |
||
66 | { |
||
67 | /** |
||
68 | * The path to the package's default configuration file. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | const CONFIG_PATH = __DIR__ . '/../../config/redis-sentinel.php'; |
||
73 | |||
74 | /** |
||
75 | * Flag that indicates whether the package should check that the framework |
||
76 | * runs full Laravel before loading Horizon support. |
||
77 | * |
||
78 | * Horizon does not yet officially support Lumen applications, so the |
||
79 | * package will not configure itself for Horizon in Lumen applications by |
||
80 | * default. Set this value to TRUE in bootstrap/app.php to short-circuit |
||
81 | * the check and attempt to load Horizon support anyway. This provides for |
||
82 | * testing unofficial Lumen implementations. Use at your own risk. |
||
83 | * |
||
84 | * @var bool |
||
85 | */ |
||
86 | public static $ignoreHorizonRequirements = false; |
||
87 | |||
88 | /** |
||
89 | * Indicates whether the current application runs the Lumen framework. |
||
90 | * |
||
91 | * @var bool |
||
92 | */ |
||
93 | public $isLumen; |
||
94 | |||
95 | /** |
||
96 | * Indicates whether the current application supports sessions. |
||
97 | * |
||
98 | * @var bool |
||
99 | */ |
||
100 | public $supportsSessions; |
||
101 | |||
102 | /** |
||
103 | * Indicates whether the package should override Laravel's standard Redis |
||
104 | * API ("Redis" facade and "redis" service binding). |
||
105 | * |
||
106 | * @var bool |
||
107 | */ |
||
108 | public $shouldOverrideLaravelRedisApi; |
||
109 | |||
110 | /** |
||
111 | * Indicates whether Laravel Horizon is installed. Currently FALSE in Lumen. |
||
112 | * |
||
113 | * @var bool |
||
114 | */ |
||
115 | public $horizonAvailable; |
||
116 | |||
117 | /** |
||
118 | * Indicates whether the package should integrate with Laravel Horizon |
||
119 | * based on availability and the value of the "horizon.driver" directive. |
||
120 | * |
||
121 | * @var bool |
||
122 | */ |
||
123 | public $shouldIntegrateHorizon; |
||
124 | |||
125 | /** |
||
126 | * The current Laravel or Lumen application instance that provides context |
||
127 | * and services used to load the appropriate configuration. |
||
128 | * |
||
129 | * @var LaravelApplication|LumenApplication |
||
130 | */ |
||
131 | private $app; |
||
132 | |||
133 | /** |
||
134 | * Used to fetch and set application configuration values. |
||
135 | * |
||
136 | * @var \Illuminate\Contracts\Config\Repository |
||
137 | */ |
||
138 | private $config; |
||
139 | |||
140 | /** |
||
141 | * Contains the set of configuration values used to configure the package |
||
142 | * as loaded from "config/redis-sentinel.php". Empty when the application's |
||
143 | * standard config files provide all the values needed to configure the |
||
144 | * package (such as when a developer provides a custom config). |
||
145 | * |
||
146 | * @var array |
||
147 | */ |
||
148 | private $packageConfig; |
||
149 | |||
150 | /** |
||
151 | * Initialize the configuration loader. Any actual loading occurs when |
||
152 | * calling the 'loadConfiguration()' method. |
||
153 | * |
||
154 | * @param LaravelApplication|LumenApplication $app The current application |
||
155 | * instance that provides context and services needed to load the |
||
156 | * appropriate configuration. |
||
157 | */ |
||
158 | public function __construct($app) |
||
170 | |||
171 | /** |
||
172 | * Create an instance of the loader and load the configuration in one step. |
||
173 | * |
||
174 | * @param LaravelApplication|LumenApplication $app The current application |
||
175 | * instance that provides context and services needed to load the |
||
176 | * appropriate configuration. |
||
177 | * |
||
178 | * @return self An initialized instance of this class |
||
179 | */ |
||
180 | public static function load($app) |
||
187 | |||
188 | /** |
||
189 | * Load the package configuration. |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | public function loadConfiguration() |
||
211 | |||
212 | /** |
||
213 | * Sets the Horizon Redis Sentinel connection configuration. |
||
214 | * |
||
215 | * @return void |
||
216 | */ |
||
217 | public function loadHorizonConfiguration() |
||
235 | |||
236 | /** |
||
237 | * Get the version number of the current Laravel or Lumen application. |
||
238 | * |
||
239 | * @return string The version as declared by the framework. |
||
240 | */ |
||
241 | public function getApplicationVersion() |
||
249 | |||
250 | /** |
||
251 | * Fetch the specified application configuration value. |
||
252 | * |
||
253 | * This helper method enables the package's service providers to get config |
||
254 | * values without having to resolve the config service from the container. |
||
255 | * |
||
256 | * @param string|array $key The key(s) for the value(s) to fetch. |
||
257 | * @param mixed $default Returned if the key does not exist. |
||
258 | * |
||
259 | * @return mixed The requested configuration value or the provided default |
||
260 | * if the key does not exist. |
||
261 | */ |
||
262 | public function get($key, $default = null) |
||
266 | |||
267 | /** |
||
268 | * Set the specified application configuration value. |
||
269 | * |
||
270 | * This helper method enables the package's service providers to set config |
||
271 | * values without having to resolve the config service from the container. |
||
272 | * |
||
273 | * @param string|array $key The key of the value or a tree of values as |
||
274 | * an associative array. |
||
275 | * @param mixed $value The value to set for the specified key. |
||
276 | * |
||
277 | * @return void |
||
278 | */ |
||
279 | public function set($key, $value = null) |
||
283 | |||
284 | /** |
||
285 | * Determine if the package should automatically configure itself. |
||
286 | * |
||
287 | * Developers may set the value of "redis-sentinel.load_config" to FALSE to |
||
288 | * disable the package's automatic configuration. This class also sets this |
||
289 | * value to FALSE after loading the package configuration to skip the auto- |
||
290 | * configuration when the application cached its configuration values (via |
||
291 | * "artisan config:cache", for example). |
||
292 | * |
||
293 | * @return bool TRUE if the package should load its configuration |
||
294 | */ |
||
295 | protected function shouldLoadConfiguration() |
||
303 | |||
304 | /** |
||
305 | * Configure the Lumen components that this package depends on. |
||
306 | * |
||
307 | * Lumen lazily loads many of its components. We must instruct Lumen to |
||
308 | * load the configuration for components that this class configures so |
||
309 | * that the values are accessible and so that the framework does not |
||
310 | * revert the configuration settings that this class changes when one of |
||
311 | * the components initializes later. |
||
312 | * |
||
313 | * @return void |
||
314 | */ |
||
315 | protected function configureLumenComponents() |
||
322 | |||
323 | /** |
||
324 | * Copy the Redis Sentinel connection configuration to use for Horizon |
||
325 | * connections from the connection specified by "horizon.use". |
||
326 | * |
||
327 | * @return array The configuration matching the connection name specified |
||
328 | * by the "horizon.use" config directive. |
||
329 | * |
||
330 | * @throws UnexpectedValueException If no Redis Sentinel connection matches |
||
331 | * the name declared by "horizon.use". |
||
332 | */ |
||
333 | protected function getSelectedHorizonConnectionConfiguration() |
||
346 | |||
347 | /** |
||
348 | * Reconcile the package configuration and use it to set the appropriate |
||
349 | * configuration values for other application components. |
||
350 | * |
||
351 | * @return void |
||
352 | */ |
||
353 | protected function loadPackageConfiguration() |
||
371 | |||
372 | /** |
||
373 | * Set the application configuration value for the specified key with the |
||
374 | * value from the package configuration. |
||
375 | * |
||
376 | * @param string $configKey The key of the config value to set. Should |
||
377 | * correspond to a key in the package's configuration. |
||
378 | * @param bool $checkExists If TRUE, don't set the value if the key |
||
379 | * already exists in the application configuration. |
||
380 | * |
||
381 | * @return void |
||
382 | */ |
||
383 | protected function setConfigurationFor($configKey, $checkExists = true) |
||
393 | |||
394 | /** |
||
395 | * Set the application session configuration as specified by the package's |
||
396 | * configuration if the app supports sessions. |
||
397 | * |
||
398 | * @return void |
||
399 | */ |
||
400 | protected function setSessionConfiguration() |
||
411 | |||
412 | /** |
||
413 | * Get the package configuration for the specified key. |
||
414 | * |
||
415 | * @param string $configKey The key of the configuration value to get |
||
416 | * |
||
417 | * @return mixed The value of the configuration with the specified key |
||
418 | */ |
||
419 | protected function getPackageConfigurationFor($configKey) |
||
427 | |||
428 | /** |
||
429 | * Merge the package's default configuration with the override config file |
||
430 | * supplied by the developer, if any. |
||
431 | * |
||
432 | * @return void |
||
433 | */ |
||
434 | protected function mergePackageConfiguration() |
||
441 | |||
442 | /** |
||
443 | * Parse Redis Sentinel connection host definitions to create single host |
||
444 | * entries for host definitions that specify multiple hosts. |
||
445 | * |
||
446 | * @return void |
||
447 | */ |
||
448 | protected function normalizeHosts() |
||
461 | |||
462 | /** |
||
463 | * Remove the package's configuration from the application configuration |
||
464 | * repository. |
||
465 | * |
||
466 | * This package's configuration contains partial elements from several |
||
467 | * other component configurations. By default, the package removes its |
||
468 | * configuration after merging the values into each of the appropriate |
||
469 | * config locations for the components it initializes. This behavior |
||
470 | * prevents the artisan "config:cache" command from saving unnecessary |
||
471 | * configuration values to the cache file. |
||
472 | * |
||
473 | * @return void |
||
474 | */ |
||
475 | protected function cleanPackageConfiguration() |
||
489 | } |
||
490 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.