1 | <?php |
||
63 | class Loader |
||
64 | { |
||
65 | /** |
||
66 | * The path to the package's default configuration file. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | const CONFIG_PATH = __DIR__ . '/../../config/redis-sentinel.php'; |
||
71 | |||
72 | /** |
||
73 | * Indicates whether the current application runs the Lumen framework. |
||
74 | * |
||
75 | * @var bool |
||
76 | */ |
||
77 | public $isLumen; |
||
78 | |||
79 | /** |
||
80 | * Indicates whether the current application supports sessions. |
||
81 | * |
||
82 | * @var bool |
||
83 | */ |
||
84 | public $supportsSessions; |
||
85 | |||
86 | /** |
||
87 | * Indicates whether the package should override Laravel's standard Redis |
||
88 | * API ("Redis" facade and "redis" service binding). |
||
89 | * |
||
90 | * @var bool |
||
91 | */ |
||
92 | public $shouldOverrideLaravelRedisApi; |
||
93 | |||
94 | /** |
||
95 | * The current Laravel or Lumen application instance that provides context |
||
96 | * and services used to load the appropriate configuration. |
||
97 | * |
||
98 | * @var LaravelApplication|LumenApplication |
||
99 | */ |
||
100 | private $app; |
||
101 | |||
102 | /** |
||
103 | * Used to fetch and set application configuration values. |
||
104 | * |
||
105 | * @var \Illuminate\Contracts\Config\Repository |
||
106 | */ |
||
107 | private $config; |
||
108 | |||
109 | /** |
||
110 | * Contains the set of configuration values used to configure the package |
||
111 | * as loaded from "config/redis-sentinel.php". Empty when the application's |
||
112 | * standard config files provide all the values needed to configure the |
||
113 | * package (such as when a developer provides a custom config). |
||
114 | * |
||
115 | * @var array |
||
116 | */ |
||
117 | private $packageConfig; |
||
118 | |||
119 | /** |
||
120 | * Initialize the configuration loader. Any actual loading occurs when |
||
121 | * calling the 'loadConfiguration()' method. |
||
122 | * |
||
123 | * @param LaravelApplication|LumenApplication $app The current application |
||
124 | * instance that provides context and services needed to load the |
||
125 | * appropriate configuration. |
||
126 | */ |
||
127 | public function __construct($app) |
||
137 | |||
138 | /** |
||
139 | * Create an instance of the loader and load the configuration in one step. |
||
140 | * |
||
141 | * @param LaravelApplication|LumenApplication $app The current application |
||
142 | * instance that provides context and services needed to load the |
||
143 | * appropriate configuration. |
||
144 | * |
||
145 | * @return self An initialized instance of this class |
||
146 | */ |
||
147 | public static function load($app) |
||
154 | |||
155 | /** |
||
156 | * Load the package configuration. |
||
157 | * |
||
158 | * @return void |
||
159 | */ |
||
160 | public function loadConfiguration() |
||
175 | |||
176 | /** |
||
177 | * Get the fully-qualified class name of the RedisSentinelManager class |
||
178 | * for the current version of Laravel or Lumen. |
||
179 | * |
||
180 | * @return string The class name of the appropriate RedisSentinelManager |
||
181 | * with its namespace |
||
182 | */ |
||
183 | public function getVersionedRedisSentinelManagerClass() |
||
199 | |||
200 | /** |
||
201 | * Fetch the specified application configuration value. |
||
202 | * |
||
203 | * This helper method enables the package's service providers to get config |
||
204 | * values without having to resolve the config service from the container. |
||
205 | * |
||
206 | * @param string|array $key The key(s) for the value(s) to fetch. |
||
207 | * @param mixed $default Returned if the key does not exist. |
||
208 | * |
||
209 | * @return mixed The requested configuration value or the provided default |
||
210 | * if the key does not exist. |
||
211 | */ |
||
212 | public function get($key, $default = null) |
||
216 | |||
217 | /** |
||
218 | * Set the specified application configuration value. |
||
219 | * |
||
220 | * This helper method enables the package's service providers to set config |
||
221 | * values without having to resolve the config service from the container. |
||
222 | * |
||
223 | * @param string|array $key The key of the value or a tree of values as |
||
224 | * an associative array. |
||
225 | * @param mixed $value The value to set for the specified key. |
||
226 | * |
||
227 | * @return void |
||
228 | */ |
||
229 | public function set($key, $value = null) |
||
233 | |||
234 | /** |
||
235 | * Determine if the package should automatically configure itself. |
||
236 | * |
||
237 | * Developers may set the value of "redis-sentinel.load_config" to FALSE to |
||
238 | * disable the package's automatic configuration. This class also sets this |
||
239 | * value to FALSE after loading the package configuration to skip the auto- |
||
240 | * configuration when the application cached its configuration values (via |
||
241 | * "artisan config:cache", for example). |
||
242 | * |
||
243 | * @return bool TRUE if the package should load its configuration |
||
244 | */ |
||
245 | protected function shouldLoadConfiguration() |
||
253 | |||
254 | /** |
||
255 | * Configure the Lumen components that this package depends on. |
||
256 | * |
||
257 | * Lumen lazily loads many of its components. We must instruct Lumen to |
||
258 | * load the configuration for components that this class configures so |
||
259 | * that the values are accessible and so that the framework does not |
||
260 | * revert the configuration settings that this class changes when one of |
||
261 | * the components initializes later. |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | protected function configureLumenComponents() |
||
272 | |||
273 | /** |
||
274 | * Reconcile the package configuration and use it to set the appropriate |
||
275 | * configuration values for other application components. |
||
276 | * |
||
277 | * @return void |
||
278 | */ |
||
279 | protected function loadPackageConfiguration() |
||
294 | |||
295 | /** |
||
296 | * Set the application configuration value for the specified key with the |
||
297 | * value from the package configuration. |
||
298 | * |
||
299 | * @param string $configKey The key of the config value to set. Should |
||
300 | * correspond to a key in the package's configuration. |
||
301 | * @param bool $checkExists If TRUE, don't set the value if the key |
||
302 | * already exists in the application configuration. |
||
303 | * |
||
304 | * @return void |
||
305 | */ |
||
306 | protected function setConfigurationFor($configKey, $checkExists = true) |
||
316 | |||
317 | /** |
||
318 | * Set the application session configuration as specified by the package's |
||
319 | * configuration if the app supports sessions. |
||
320 | * |
||
321 | * @return void |
||
322 | */ |
||
323 | protected function setSessionConfiguration() |
||
334 | |||
335 | /** |
||
336 | * Get the package configuration for the specified key. |
||
337 | * |
||
338 | * @param string $configKey The key of the configuration value to get |
||
339 | * |
||
340 | * @return mixed The value of the configuration with the specified key |
||
341 | */ |
||
342 | protected function getPackageConfigurationFor($configKey) |
||
350 | |||
351 | /** |
||
352 | * Merge the package's default configuration with the override config file |
||
353 | * supplied by the developer, if any. |
||
354 | * |
||
355 | * @return void |
||
356 | */ |
||
357 | protected function mergePackageConfiguration() |
||
364 | |||
365 | /** |
||
366 | * Parse Redis Sentinel connection host definitions to create single host |
||
367 | * entries for host definitions that specify multiple hosts. |
||
368 | * |
||
369 | * @return void |
||
370 | */ |
||
371 | protected function normalizeHosts() |
||
384 | |||
385 | /** |
||
386 | * Remove the package's configuration from the application configuration |
||
387 | * repository. |
||
388 | * |
||
389 | * This package's configuration contains partial elements from several |
||
390 | * other component configurations. By default, the package removes its |
||
391 | * configuration after merging the values into each of the appropriate |
||
392 | * config locations for the components it initializes. This behavior |
||
393 | * prevents the artisan "config:cache" command from saving unnecessary |
||
394 | * configuration values to the cache file. |
||
395 | * |
||
396 | * @return void |
||
397 | */ |
||
398 | protected function cleanPackageConfiguration() |
||
413 | } |
||
414 |