@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @since 0.4.2 |
| 135 | 135 | * |
| 136 | - * @return ConfigInterface Configuration settings to use. |
|
| 136 | + * @return Config|null Configuration settings to use. |
|
| 137 | 137 | */ |
| 138 | 138 | protected function fetchDefaultConfig() |
| 139 | 139 | { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @since 0.4.2 |
| 153 | 153 | * |
| 154 | - * @return ConfigInterface Configuration settings to use. |
|
| 154 | + * @return Config|null Configuration settings to use. |
|
| 155 | 155 | */ |
| 156 | 156 | protected function fetchConfig($configFile) |
| 157 | 157 | { |
@@ -25,140 +25,140 @@ |
||
| 25 | 25 | trait ConfigTrait |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Reference to the Config object. |
|
| 30 | - * |
|
| 31 | - * @since 0.1.2 |
|
| 32 | - * |
|
| 33 | - * @var ConfigInterface |
|
| 34 | - */ |
|
| 35 | - protected $config; |
|
| 28 | + /** |
|
| 29 | + * Reference to the Config object. |
|
| 30 | + * |
|
| 31 | + * @since 0.1.2 |
|
| 32 | + * |
|
| 33 | + * @var ConfigInterface |
|
| 34 | + */ |
|
| 35 | + protected $config; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Process the passed-in configuration file. |
|
| 39 | - * |
|
| 40 | - * @since 0.1.2 |
|
| 41 | - * |
|
| 42 | - * @param ConfigInterface $config The Config to process. |
|
| 43 | - * @param string ... List of keys. |
|
| 44 | - * |
|
| 45 | - * @throws FailedToProcessConfigException If the arguments could not be parsed into a Config. |
|
| 46 | - */ |
|
| 47 | - protected function processConfig(ConfigInterface $config) |
|
| 48 | - { |
|
| 49 | - if (func_num_args() > 1) { |
|
| 50 | - try { |
|
| 51 | - $keys = func_get_args(); |
|
| 52 | - array_shift($keys); |
|
| 53 | - $config = $config->getSubConfig($keys); |
|
| 54 | - } catch (Exception $exception) { |
|
| 55 | - throw new FailedToProcessConfigException( |
|
| 56 | - sprintf( |
|
| 57 | - _('Could not process the config with the arguments "%1$s".'), |
|
| 58 | - print_r(func_get_args(), true) |
|
| 59 | - ) |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $this->config = $config; |
|
| 64 | - } |
|
| 37 | + /** |
|
| 38 | + * Process the passed-in configuration file. |
|
| 39 | + * |
|
| 40 | + * @since 0.1.2 |
|
| 41 | + * |
|
| 42 | + * @param ConfigInterface $config The Config to process. |
|
| 43 | + * @param string ... List of keys. |
|
| 44 | + * |
|
| 45 | + * @throws FailedToProcessConfigException If the arguments could not be parsed into a Config. |
|
| 46 | + */ |
|
| 47 | + protected function processConfig(ConfigInterface $config) |
|
| 48 | + { |
|
| 49 | + if (func_num_args() > 1) { |
|
| 50 | + try { |
|
| 51 | + $keys = func_get_args(); |
|
| 52 | + array_shift($keys); |
|
| 53 | + $config = $config->getSubConfig($keys); |
|
| 54 | + } catch (Exception $exception) { |
|
| 55 | + throw new FailedToProcessConfigException( |
|
| 56 | + sprintf( |
|
| 57 | + _('Could not process the config with the arguments "%1$s".'), |
|
| 58 | + print_r(func_get_args(), true) |
|
| 59 | + ) |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $this->config = $config; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Check whether the Config has a specific key. |
|
| 68 | - * |
|
| 69 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 70 | - * |
|
| 71 | - * @since 0.1.2 |
|
| 72 | - * @since 0.1.5 Accepts list of keys. |
|
| 73 | - * |
|
| 74 | - * @param string|array $_ List of keys. |
|
| 75 | - * |
|
| 76 | - * @return bool Whether the key is known. |
|
| 77 | - */ |
|
| 78 | - protected function hasConfigKey($_) |
|
| 79 | - { |
|
| 80 | - $keys = func_get_args(); |
|
| 66 | + /** |
|
| 67 | + * Check whether the Config has a specific key. |
|
| 68 | + * |
|
| 69 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 70 | + * |
|
| 71 | + * @since 0.1.2 |
|
| 72 | + * @since 0.1.5 Accepts list of keys. |
|
| 73 | + * |
|
| 74 | + * @param string|array $_ List of keys. |
|
| 75 | + * |
|
| 76 | + * @return bool Whether the key is known. |
|
| 77 | + */ |
|
| 78 | + protected function hasConfigKey($_) |
|
| 79 | + { |
|
| 80 | + $keys = func_get_args(); |
|
| 81 | 81 | |
| 82 | - return $this->config->hasKey($keys); |
|
| 83 | - } |
|
| 82 | + return $this->config->hasKey($keys); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get the Config value for a specific key. |
|
| 87 | - * |
|
| 88 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 89 | - * |
|
| 90 | - * @since 0.1.2 |
|
| 91 | - * @since 0.1.5 Accepts list of keys. |
|
| 92 | - * |
|
| 93 | - * @param string|array $_ List of keys. |
|
| 94 | - * |
|
| 95 | - * @return mixed Value of the key. |
|
| 96 | - */ |
|
| 97 | - protected function getConfigKey($_) |
|
| 98 | - { |
|
| 99 | - $keys = func_get_args(); |
|
| 85 | + /** |
|
| 86 | + * Get the Config value for a specific key. |
|
| 87 | + * |
|
| 88 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 89 | + * |
|
| 90 | + * @since 0.1.2 |
|
| 91 | + * @since 0.1.5 Accepts list of keys. |
|
| 92 | + * |
|
| 93 | + * @param string|array $_ List of keys. |
|
| 94 | + * |
|
| 95 | + * @return mixed Value of the key. |
|
| 96 | + */ |
|
| 97 | + protected function getConfigKey($_) |
|
| 98 | + { |
|
| 99 | + $keys = func_get_args(); |
|
| 100 | 100 | |
| 101 | - return $this->config->getKey($keys); |
|
| 102 | - } |
|
| 101 | + return $this->config->getKey($keys); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
| 106 | - * |
|
| 107 | - * @since 0.1.4 |
|
| 108 | - * |
|
| 109 | - * @return array All the configuration settings. |
|
| 110 | - */ |
|
| 111 | - protected function getConfigArray() |
|
| 112 | - { |
|
| 113 | - return $this->config->getAll(); |
|
| 114 | - } |
|
| 104 | + /** |
|
| 105 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
| 106 | + * |
|
| 107 | + * @since 0.1.4 |
|
| 108 | + * |
|
| 109 | + * @return array All the configuration settings. |
|
| 110 | + */ |
|
| 111 | + protected function getConfigArray() |
|
| 112 | + { |
|
| 113 | + return $this->config->getAll(); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Get an array of all the keys that are known by the Config. |
|
| 118 | - * |
|
| 119 | - * @since 0.1.2 |
|
| 120 | - * |
|
| 121 | - * @return array Array of strings containing all the keys. |
|
| 122 | - */ |
|
| 123 | - protected function getConfigKeys() |
|
| 124 | - { |
|
| 125 | - return $this->config->getKeys(); |
|
| 126 | - } |
|
| 116 | + /** |
|
| 117 | + * Get an array of all the keys that are known by the Config. |
|
| 118 | + * |
|
| 119 | + * @since 0.1.2 |
|
| 120 | + * |
|
| 121 | + * @return array Array of strings containing all the keys. |
|
| 122 | + */ |
|
| 123 | + protected function getConfigKeys() |
|
| 124 | + { |
|
| 125 | + return $this->config->getKeys(); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Get a default configuration in case none was injected into the constructor. |
|
| 130 | - * |
|
| 131 | - * The name and path of the configuration needs to be set as a const called DEFAULT_CONFIG within the class |
|
| 132 | - * containing the trait. The path needs to be relative to the location of the containing class file. |
|
| 133 | - * |
|
| 134 | - * @since 0.4.2 |
|
| 135 | - * |
|
| 136 | - * @return ConfigInterface Configuration settings to use. |
|
| 137 | - */ |
|
| 138 | - protected function fetchDefaultConfig() |
|
| 139 | - { |
|
| 140 | - $configFile = method_exists($this, 'getDefaultConfigFile') |
|
| 141 | - ? $this->getDefaultConfigFile() |
|
| 142 | - : __DIR__ . '/../config/defaults.php'; |
|
| 128 | + /** |
|
| 129 | + * Get a default configuration in case none was injected into the constructor. |
|
| 130 | + * |
|
| 131 | + * The name and path of the configuration needs to be set as a const called DEFAULT_CONFIG within the class |
|
| 132 | + * containing the trait. The path needs to be relative to the location of the containing class file. |
|
| 133 | + * |
|
| 134 | + * @since 0.4.2 |
|
| 135 | + * |
|
| 136 | + * @return ConfigInterface Configuration settings to use. |
|
| 137 | + */ |
|
| 138 | + protected function fetchDefaultConfig() |
|
| 139 | + { |
|
| 140 | + $configFile = method_exists($this, 'getDefaultConfigFile') |
|
| 141 | + ? $this->getDefaultConfigFile() |
|
| 142 | + : __DIR__ . '/../config/defaults.php'; |
|
| 143 | 143 | |
| 144 | - return $this->fetchConfig($configFile); |
|
| 145 | - } |
|
| 144 | + return $this->fetchConfig($configFile); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Get a configuration from a specified $file. |
|
| 149 | - * |
|
| 150 | - * If file is not accessible or readable, returns an empty Config. |
|
| 151 | - * |
|
| 152 | - * @since 0.4.2 |
|
| 153 | - * |
|
| 154 | - * @return ConfigInterface Configuration settings to use. |
|
| 155 | - */ |
|
| 156 | - protected function fetchConfig($configFile) |
|
| 157 | - { |
|
| 158 | - if (is_string($configFile) && ! is_readable($configFile)) { |
|
| 159 | - $configFile = []; |
|
| 160 | - } |
|
| 147 | + /** |
|
| 148 | + * Get a configuration from a specified $file. |
|
| 149 | + * |
|
| 150 | + * If file is not accessible or readable, returns an empty Config. |
|
| 151 | + * |
|
| 152 | + * @since 0.4.2 |
|
| 153 | + * |
|
| 154 | + * @return ConfigInterface Configuration settings to use. |
|
| 155 | + */ |
|
| 156 | + protected function fetchConfig($configFile) |
|
| 157 | + { |
|
| 158 | + if (is_string($configFile) && ! is_readable($configFile)) { |
|
| 159 | + $configFile = []; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return ConfigFactory::create($configFile); |
|
| 163 | - } |
|
| 162 | + return ConfigFactory::create($configFile); |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -139,7 +139,7 @@ |
||
| 139 | 139 | { |
| 140 | 140 | $configFile = method_exists($this, 'getDefaultConfigFile') |
| 141 | 141 | ? $this->getDefaultConfigFile() |
| 142 | - : __DIR__ . '/../config/defaults.php'; |
|
| 142 | + : __DIR__.'/../config/defaults.php'; |
|
| 143 | 143 | |
| 144 | 144 | return $this->fetchConfig($configFile); |
| 145 | 145 | } |