1 | <?php |
||
62 | class Loader |
||
63 | { |
||
64 | /** |
||
65 | * The path to the package's default configuration file. |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | const CONFIG_PATH = __DIR__ . '/../../config/redis-sentinel.php'; |
||
70 | |||
71 | /** |
||
72 | * Indicates whether the current application runs the Lumen framework. |
||
73 | * |
||
74 | * @var bool |
||
75 | */ |
||
76 | public $isLumen; |
||
77 | |||
78 | /** |
||
79 | * Indicates whether the current application supports sessions. |
||
80 | * |
||
81 | * @var bool |
||
82 | */ |
||
83 | public $supportsSessions; |
||
84 | |||
85 | /** |
||
86 | * The current Laravel or Lumen application instance that provides context |
||
87 | * and services used to load the appropriate configuration. |
||
88 | * |
||
89 | * @var LaravelApplication|LumenApplication |
||
90 | */ |
||
91 | private $app; |
||
92 | |||
93 | /** |
||
94 | * Used to fetch and set application configuration values. |
||
95 | * |
||
96 | * @var \Illuminate\Contracts\Config\Repository |
||
97 | */ |
||
98 | private $config; |
||
99 | |||
100 | /** |
||
101 | * Contains the set of configuration values used to configure the package |
||
102 | * as loaded from "config/redis-sentinel.php". Empty when the application's |
||
103 | * standard config files provide all the values needed to configure the |
||
104 | * package (such as when a developer provides a custom config). |
||
105 | * |
||
106 | * @var array |
||
107 | */ |
||
108 | private $packageConfig; |
||
109 | |||
110 | /** |
||
111 | * Initialize the configuration loader. Any actual loading occurs when |
||
112 | * calling the 'loadConfiguration()' method. |
||
113 | * |
||
114 | * @param LaravelApplication|LumenApplication $app The current application |
||
115 | * instance that provides context and services needed to load the |
||
116 | * appropriate configuration. |
||
117 | */ |
||
118 | public function __construct($app) |
||
128 | |||
129 | /** |
||
130 | * Create an instance of the loader and load the configuration in one step. |
||
131 | * |
||
132 | * @param LaravelApplication|LumenApplication $app The current application |
||
133 | * instance that provides context and services needed to load the |
||
134 | * appropriate configuration. |
||
135 | * |
||
136 | * @return self An initialized instance of this class |
||
137 | */ |
||
138 | public static function load($app) |
||
145 | |||
146 | /** |
||
147 | * Load the package configuration. |
||
148 | * |
||
149 | * @return void |
||
150 | */ |
||
151 | public function loadConfiguration() |
||
163 | |||
164 | /** |
||
165 | * Determine whether the package should override Laravel's standard Redis |
||
166 | * API ("Redis" facade and "redis" service binding). |
||
167 | * |
||
168 | * @return bool TRUE if the package should override Laravel's standard |
||
169 | * Redis API |
||
170 | */ |
||
171 | public function shouldOverrideLaravelRedisApi() |
||
178 | |||
179 | /** |
||
180 | * Determine if the package should automatically configure itself. |
||
181 | * |
||
182 | * Developers may set the value of "redis-sentinel.load_config" to FALSE to |
||
183 | * disable the package's automatic configuration. This class also sets this |
||
184 | * value to FALSE after loading the package configuration to skip the auto- |
||
185 | * configuration when the application cached its configuration values (via |
||
186 | * "artisan config:cache", for example). |
||
187 | * |
||
188 | * @return bool TRUE if the package should load its configuration |
||
189 | */ |
||
190 | protected function shouldLoadConfiguration() |
||
198 | |||
199 | /** |
||
200 | * Configure the Lumen components that this package depends on. |
||
201 | * |
||
202 | * Lumen lazily loads many of its components. We must instruct Lumen to |
||
203 | * load the configuration for components that this class configures so |
||
204 | * that the values are accessible and so that the framework does not |
||
205 | * revert the configuration settings that this class changes when one of |
||
206 | * the components initializes later. |
||
207 | * |
||
208 | * @return void |
||
209 | */ |
||
210 | protected function configureLumenComponents() |
||
216 | |||
217 | /** |
||
218 | * Reconcile the package configuration and use it to set the appropriate |
||
219 | * configuration values for other application components. |
||
220 | * |
||
221 | * @return void |
||
222 | */ |
||
223 | protected function loadPackageConfiguration() |
||
237 | |||
238 | /** |
||
239 | * Set the application configuration value for the specified key with the |
||
240 | * value from the package configuration. |
||
241 | * |
||
242 | * @param string $configKey The key of the config value to set. Should |
||
243 | * correspond to a key in the package's configuration. |
||
244 | * @param bool $checkExists If TRUE, don't set the value if the key |
||
245 | * already exists in the application configuration. |
||
246 | * |
||
247 | * @return void |
||
248 | */ |
||
249 | protected function setConfigurationFor($configKey, $checkExists = true) |
||
259 | |||
260 | /** |
||
261 | * Set the application session configuration as specified by the package's |
||
262 | * configuration if the app supports sessions. |
||
263 | * |
||
264 | * @return void |
||
265 | */ |
||
266 | protected function setSessionConfiguration() |
||
277 | |||
278 | /** |
||
279 | * Get the package configuration for the specified key. |
||
280 | * |
||
281 | * @param string $configKey The key of the configuration value to get |
||
282 | * |
||
283 | * @return mixed The value of the configuration with the specified key |
||
284 | */ |
||
285 | protected function getPackageConfigurationFor($configKey) |
||
293 | |||
294 | /** |
||
295 | * Merge the package's default configuration with the override config file |
||
296 | * supplied by the developer, if any. |
||
297 | * |
||
298 | * @return void |
||
299 | */ |
||
300 | protected function mergePackageConfiguration() |
||
307 | |||
308 | /** |
||
309 | * Parse Redis Sentinel connection host definitions to create single host |
||
310 | * entries for host definitions that specify multiple hosts. |
||
311 | * |
||
312 | * @return void |
||
313 | */ |
||
314 | protected function normalizeHosts() |
||
327 | |||
328 | /** |
||
329 | * Remove the package's configuration from the application configuration |
||
330 | * repository. |
||
331 | * |
||
332 | * This package's configuration contains partial elements from several |
||
333 | * other component configurations. By default, the package removes its |
||
334 | * configuration after merging the values into each of the appropriate |
||
335 | * config locations for the components it initializes. This behavior |
||
336 | * prevents the artisan "config:cache" command from saving unnecessary |
||
337 | * configuration values to the cache file. |
||
338 | * |
||
339 | * @return void |
||
340 | */ |
||
341 | protected function cleanPackageConfiguration() |
||
352 | } |
||
353 |