1 | <?php |
||
64 | class Loader |
||
65 | { |
||
66 | /** |
||
67 | * The path to the package's default configuration file. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | const CONFIG_PATH = __DIR__ . '/../../config/redis-sentinel.php'; |
||
72 | |||
73 | /** |
||
74 | * Indicates whether the current application runs the Lumen framework. |
||
75 | * |
||
76 | * @var bool |
||
77 | */ |
||
78 | public $isLumen; |
||
79 | |||
80 | /** |
||
81 | * Indicates whether the current application supports sessions. |
||
82 | * |
||
83 | * @var bool |
||
84 | */ |
||
85 | public $supportsSessions; |
||
86 | |||
87 | /** |
||
88 | * Indicates whether the package should override Laravel's standard Redis |
||
89 | * API ("Redis" facade and "redis" service binding). |
||
90 | * |
||
91 | * @var bool |
||
92 | */ |
||
93 | public $shouldOverrideLaravelRedisApi; |
||
94 | |||
95 | /** |
||
96 | * Indicates whether Laravel Horizon is installed. |
||
97 | * |
||
98 | * @var bool |
||
99 | */ |
||
100 | public $horizonAvailable; |
||
101 | |||
102 | /** |
||
103 | * The current Laravel or Lumen application instance that provides context |
||
104 | * and services used to load the appropriate configuration. |
||
105 | * |
||
106 | * @var LaravelApplication|LumenApplication |
||
107 | */ |
||
108 | private $app; |
||
109 | |||
110 | /** |
||
111 | * Used to fetch and set application configuration values. |
||
112 | * |
||
113 | * @var \Illuminate\Contracts\Config\Repository |
||
114 | */ |
||
115 | private $config; |
||
116 | |||
117 | /** |
||
118 | * Contains the set of configuration values used to configure the package |
||
119 | * as loaded from "config/redis-sentinel.php". Empty when the application's |
||
120 | * standard config files provide all the values needed to configure the |
||
121 | * package (such as when a developer provides a custom config). |
||
122 | * |
||
123 | * @var array |
||
124 | */ |
||
125 | private $packageConfig; |
||
126 | |||
127 | /** |
||
128 | * Initialize the configuration loader. Any actual loading occurs when |
||
129 | * calling the 'loadConfiguration()' method. |
||
130 | * |
||
131 | * @param LaravelApplication|LumenApplication $app The current application |
||
132 | * instance that provides context and services needed to load the |
||
133 | * appropriate configuration. |
||
134 | */ |
||
135 | public function __construct($app) |
||
146 | |||
147 | /** |
||
148 | * Create an instance of the loader and load the configuration in one step. |
||
149 | * |
||
150 | * @param LaravelApplication|LumenApplication $app The current application |
||
151 | * instance that provides context and services needed to load the |
||
152 | * appropriate configuration. |
||
153 | * |
||
154 | * @return self An initialized instance of this class |
||
155 | */ |
||
156 | public static function load($app) |
||
163 | |||
164 | /** |
||
165 | * Load the package configuration. |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | public function loadConfiguration() |
||
184 | |||
185 | /** |
||
186 | * Get the fully-qualified class name of the RedisSentinelManager class |
||
187 | * for the current version of Laravel or Lumen. |
||
188 | * |
||
189 | * @return string The class name of the appropriate RedisSentinelManager |
||
190 | * with its namespace |
||
191 | */ |
||
192 | public function getVersionedRedisSentinelManagerClass() |
||
208 | |||
209 | /** |
||
210 | * Fetch the specified application configuration value. |
||
211 | * |
||
212 | * This helper method enables the package's service providers to get config |
||
213 | * values without having to resolve the config service from the container. |
||
214 | * |
||
215 | * @param string|array $key The key(s) for the value(s) to fetch. |
||
216 | * @param mixed $default Returned if the key does not exist. |
||
217 | * |
||
218 | * @return mixed The requested configuration value or the provided default |
||
219 | * if the key does not exist. |
||
220 | */ |
||
221 | public function get($key, $default = null) |
||
225 | |||
226 | /** |
||
227 | * Set the specified application configuration value. |
||
228 | * |
||
229 | * This helper method enables the package's service providers to set config |
||
230 | * values without having to resolve the config service from the container. |
||
231 | * |
||
232 | * @param string|array $key The key of the value or a tree of values as |
||
233 | * an associative array. |
||
234 | * @param mixed $value The value to set for the specified key. |
||
235 | * |
||
236 | * @return void |
||
237 | */ |
||
238 | public function set($key, $value = null) |
||
242 | |||
243 | /** |
||
244 | * Determine if the package should automatically configure itself. |
||
245 | * |
||
246 | * Developers may set the value of "redis-sentinel.load_config" to FALSE to |
||
247 | * disable the package's automatic configuration. This class also sets this |
||
248 | * value to FALSE after loading the package configuration to skip the auto- |
||
249 | * configuration when the application cached its configuration values (via |
||
250 | * "artisan config:cache", for example). |
||
251 | * |
||
252 | * @return bool TRUE if the package should load its configuration |
||
253 | */ |
||
254 | protected function shouldLoadConfiguration() |
||
262 | |||
263 | /** |
||
264 | * Configure the Lumen components that this package depends on. |
||
265 | * |
||
266 | * Lumen lazily loads many of its components. We must instruct Lumen to |
||
267 | * load the configuration for components that this class configures so |
||
268 | * that the values are accessible and so that the framework does not |
||
269 | * revert the configuration settings that this class changes when one of |
||
270 | * the components initializes later. |
||
271 | * |
||
272 | * @return void |
||
273 | */ |
||
274 | protected function configureLumenComponents() |
||
281 | |||
282 | /** |
||
283 | * Reconcile the package configuration and use it to set the appropriate |
||
284 | * configuration values for other application components. |
||
285 | * |
||
286 | * @return void |
||
287 | */ |
||
288 | protected function loadPackageConfiguration() |
||
303 | |||
304 | /** |
||
305 | * Set the application configuration value for the specified key with the |
||
306 | * value from the package configuration. |
||
307 | * |
||
308 | * @param string $configKey The key of the config value to set. Should |
||
309 | * correspond to a key in the package's configuration. |
||
310 | * @param bool $checkExists If TRUE, don't set the value if the key |
||
311 | * already exists in the application configuration. |
||
312 | * |
||
313 | * @return void |
||
314 | */ |
||
315 | protected function setConfigurationFor($configKey, $checkExists = true) |
||
325 | |||
326 | /** |
||
327 | * Set the application session configuration as specified by the package's |
||
328 | * configuration if the app supports sessions. |
||
329 | * |
||
330 | * @return void |
||
331 | */ |
||
332 | protected function setSessionConfiguration() |
||
343 | |||
344 | /** |
||
345 | * Get the package configuration for the specified key. |
||
346 | * |
||
347 | * @param string $configKey The key of the configuration value to get |
||
348 | * |
||
349 | * @return mixed The value of the configuration with the specified key |
||
350 | */ |
||
351 | protected function getPackageConfigurationFor($configKey) |
||
359 | |||
360 | /** |
||
361 | * Merge the package's default configuration with the override config file |
||
362 | * supplied by the developer, if any. |
||
363 | * |
||
364 | * @return void |
||
365 | */ |
||
366 | protected function mergePackageConfiguration() |
||
373 | |||
374 | /** |
||
375 | * Parse Redis Sentinel connection host definitions to create single host |
||
376 | * entries for host definitions that specify multiple hosts. |
||
377 | * |
||
378 | * @return void |
||
379 | */ |
||
380 | protected function normalizeHosts() |
||
393 | |||
394 | /** |
||
395 | * Remove the package's configuration from the application configuration |
||
396 | * repository. |
||
397 | * |
||
398 | * This package's configuration contains partial elements from several |
||
399 | * other component configurations. By default, the package removes its |
||
400 | * configuration after merging the values into each of the appropriate |
||
401 | * config locations for the components it initializes. This behavior |
||
402 | * prevents the artisan "config:cache" command from saving unnecessary |
||
403 | * configuration values to the cache file. |
||
404 | * |
||
405 | * @return void |
||
406 | */ |
||
407 | protected function cleanPackageConfiguration() |
||
422 | } |
||
423 |