@@ -27,110 +27,110 @@ |
||
| 27 | 27 | abstract class AbstractConfig extends ArrayObject implements ConfigInterface |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Instantiate the AbstractConfig object. |
|
| 32 | - * |
|
| 33 | - * @since 0.1.0 |
|
| 34 | - * |
|
| 35 | - * @param array $config Array with settings. |
|
| 36 | - */ |
|
| 37 | - public function __construct(array $config) |
|
| 38 | - { |
|
| 39 | - // Make sure the config entries can be accessed as properties. |
|
| 40 | - parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * Instantiate the AbstractConfig object. |
|
| 32 | + * |
|
| 33 | + * @since 0.1.0 |
|
| 34 | + * |
|
| 35 | + * @param array $config Array with settings. |
|
| 36 | + */ |
|
| 37 | + public function __construct(array $config) |
|
| 38 | + { |
|
| 39 | + // Make sure the config entries can be accessed as properties. |
|
| 40 | + parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Check whether the Config has a specific key. |
|
| 45 | - * |
|
| 46 | - * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 47 | - * |
|
| 48 | - * @since 0.1.0 |
|
| 49 | - * @since 0.1.4 Accepts list of keys. |
|
| 50 | - * |
|
| 51 | - * @param string ... List of keys. |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function hasKey() |
|
| 55 | - { |
|
| 56 | - $keys = array_reverse(func_get_args()); |
|
| 43 | + /** |
|
| 44 | + * Check whether the Config has a specific key. |
|
| 45 | + * |
|
| 46 | + * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 47 | + * |
|
| 48 | + * @since 0.1.0 |
|
| 49 | + * @since 0.1.4 Accepts list of keys. |
|
| 50 | + * |
|
| 51 | + * @param string ... List of keys. |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function hasKey() |
|
| 55 | + { |
|
| 56 | + $keys = array_reverse(func_get_args()); |
|
| 57 | 57 | |
| 58 | - $array = $this->getArrayCopy(); |
|
| 59 | - while (count($keys) > 0) { |
|
| 60 | - $key = array_pop($keys); |
|
| 61 | - if ( ! array_key_exists($key, $array)) { |
|
| 62 | - return false; |
|
| 63 | - } |
|
| 64 | - $array = $array[$key]; |
|
| 65 | - } |
|
| 58 | + $array = $this->getArrayCopy(); |
|
| 59 | + while (count($keys) > 0) { |
|
| 60 | + $key = array_pop($keys); |
|
| 61 | + if ( ! array_key_exists($key, $array)) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 64 | + $array = $array[$key]; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return true; |
|
| 68 | - } |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get the value of a specific key. |
|
| 72 | - * |
|
| 73 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 74 | - * |
|
| 75 | - * @since 0.1.0 |
|
| 76 | - * @since 0.1.4 Accepts list of keys. |
|
| 77 | - * |
|
| 78 | - * @param string ... List of keys. |
|
| 79 | - * @return mixed |
|
| 80 | - * @throws BadMethodCallException If no argument was provided. |
|
| 81 | - * @throws OutOfRangeException If an unknown key is requested. |
|
| 82 | - */ |
|
| 83 | - public function getKey() |
|
| 84 | - { |
|
| 85 | - if (func_num_args() < 1) { |
|
| 86 | - throw new BadMethodCallException(_('No configuration was provided to getKey().')); |
|
| 87 | - } |
|
| 70 | + /** |
|
| 71 | + * Get the value of a specific key. |
|
| 72 | + * |
|
| 73 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 74 | + * |
|
| 75 | + * @since 0.1.0 |
|
| 76 | + * @since 0.1.4 Accepts list of keys. |
|
| 77 | + * |
|
| 78 | + * @param string ... List of keys. |
|
| 79 | + * @return mixed |
|
| 80 | + * @throws BadMethodCallException If no argument was provided. |
|
| 81 | + * @throws OutOfRangeException If an unknown key is requested. |
|
| 82 | + */ |
|
| 83 | + public function getKey() |
|
| 84 | + { |
|
| 85 | + if (func_num_args() < 1) { |
|
| 86 | + throw new BadMethodCallException(_('No configuration was provided to getKey().')); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $keys = func_get_args(); |
|
| 89 | + $keys = func_get_args(); |
|
| 90 | 90 | |
| 91 | - if ( ! call_user_func_array([$this, 'hasKey'], $keys)) { |
|
| 92 | - throw new OutOfRangeException(sprintf(_('The configuration key %1$s does not exist.'), |
|
| 93 | - implode('->', $keys))); |
|
| 94 | - } |
|
| 91 | + if ( ! call_user_func_array([$this, 'hasKey'], $keys)) { |
|
| 92 | + throw new OutOfRangeException(sprintf(_('The configuration key %1$s does not exist.'), |
|
| 93 | + implode('->', $keys))); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - $keys = array_reverse($keys); |
|
| 97 | - $array = $this->getArrayCopy(); |
|
| 98 | - while (count($keys) > 0) { |
|
| 99 | - $key = array_pop($keys); |
|
| 100 | - $array = $array[$key]; |
|
| 101 | - } |
|
| 96 | + $keys = array_reverse($keys); |
|
| 97 | + $array = $this->getArrayCopy(); |
|
| 98 | + while (count($keys) > 0) { |
|
| 99 | + $key = array_pop($keys); |
|
| 100 | + $array = $array[$key]; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return $array; |
|
| 104 | - } |
|
| 103 | + return $array; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
| 108 | - * |
|
| 109 | - * @since 0.1.4 |
|
| 110 | - * |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function getAll() |
|
| 114 | - { |
|
| 115 | - return $this->getArrayCopy(); |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
| 108 | + * |
|
| 109 | + * @since 0.1.4 |
|
| 110 | + * |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function getAll() |
|
| 114 | + { |
|
| 115 | + return $this->getArrayCopy(); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Get the an array with all the keys |
|
| 120 | - * |
|
| 121 | - * @since 0.1.0 |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - public function getKeys() |
|
| 125 | - { |
|
| 126 | - return array_keys((array)$this); |
|
| 127 | - } |
|
| 118 | + /** |
|
| 119 | + * Get the an array with all the keys |
|
| 120 | + * |
|
| 121 | + * @since 0.1.0 |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + public function getKeys() |
|
| 125 | + { |
|
| 126 | + return array_keys((array)$this); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Validate the Config file. |
|
| 131 | - * |
|
| 132 | - * @since 0.1.0 |
|
| 133 | - * @return boolean |
|
| 134 | - */ |
|
| 135 | - abstract public function isValid(); |
|
| 129 | + /** |
|
| 130 | + * Validate the Config file. |
|
| 131 | + * |
|
| 132 | + * @since 0.1.0 |
|
| 133 | + * @return boolean |
|
| 134 | + */ |
|
| 135 | + abstract public function isValid(); |
|
| 136 | 136 | } |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | */ |
| 124 | 124 | public function getKeys() |
| 125 | 125 | { |
| 126 | - return array_keys((array)$this); |
|
| 126 | + return array_keys((array) $this); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Config Interface |
|
| 4 | - * |
|
| 5 | - * @package BrightNucleus\Config |
|
| 6 | - * @author Alain Schlesser <[email protected]> |
|
| 7 | - * @license GPL-2.0+ |
|
| 8 | - * @link http://www.brightnucleus.com/ |
|
| 9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | - */ |
|
| 3 | + * Config Interface |
|
| 4 | + * |
|
| 5 | + * @package BrightNucleus\Config |
|
| 6 | + * @author Alain Schlesser <[email protected]> |
|
| 7 | + * @license GPL-2.0+ |
|
| 8 | + * @link http://www.brightnucleus.com/ |
|
| 9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | namespace BrightNucleus\Config; |
| 13 | 13 | |
@@ -27,70 +27,70 @@ discard block |
||
| 27 | 27 | interface ConfigInterface extends IteratorAggregate, ArrayAccess, Serializable, Countable |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Creates a copy of the ArrayObject. |
|
| 32 | - * |
|
| 33 | - * Returns a copy of the array. When the ArrayObject refers to an object an |
|
| 34 | - * array of the public properties of that object will be returned. |
|
| 35 | - * This is implemented by \ArrayObject. |
|
| 36 | - * |
|
| 37 | - * @since 0.1.0 |
|
| 38 | - * |
|
| 39 | - * @return array Copy of the array. |
|
| 40 | - */ |
|
| 41 | - public function getArrayCopy(); |
|
| 30 | + /** |
|
| 31 | + * Creates a copy of the ArrayObject. |
|
| 32 | + * |
|
| 33 | + * Returns a copy of the array. When the ArrayObject refers to an object an |
|
| 34 | + * array of the public properties of that object will be returned. |
|
| 35 | + * This is implemented by \ArrayObject. |
|
| 36 | + * |
|
| 37 | + * @since 0.1.0 |
|
| 38 | + * |
|
| 39 | + * @return array Copy of the array. |
|
| 40 | + */ |
|
| 41 | + public function getArrayCopy(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Check whether the Config has a specific key. |
|
| 45 | - * |
|
| 46 | - * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 47 | - * |
|
| 48 | - * @since 0.1.0 |
|
| 49 | - * @since 0.1.4 Accepts list of keys. |
|
| 50 | - * |
|
| 51 | - * @param string ... List of keys. |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function hasKey(); |
|
| 43 | + /** |
|
| 44 | + * Check whether the Config has a specific key. |
|
| 45 | + * |
|
| 46 | + * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 47 | + * |
|
| 48 | + * @since 0.1.0 |
|
| 49 | + * @since 0.1.4 Accepts list of keys. |
|
| 50 | + * |
|
| 51 | + * @param string ... List of keys. |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function hasKey(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the value of a specific key. |
|
| 58 | - * |
|
| 59 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 60 | - * |
|
| 61 | - * @since 0.1.0 |
|
| 62 | - * @since 0.1.4 Accepts list of keys. |
|
| 63 | - * |
|
| 64 | - * @param string ... List of keys. |
|
| 65 | - * |
|
| 66 | - * @return mixed |
|
| 67 | - */ |
|
| 68 | - public function getKey(); |
|
| 56 | + /** |
|
| 57 | + * Get the value of a specific key. |
|
| 58 | + * |
|
| 59 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
| 60 | + * |
|
| 61 | + * @since 0.1.0 |
|
| 62 | + * @since 0.1.4 Accepts list of keys. |
|
| 63 | + * |
|
| 64 | + * @param string ... List of keys. |
|
| 65 | + * |
|
| 66 | + * @return mixed |
|
| 67 | + */ |
|
| 68 | + public function getKey(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
| 72 | - * |
|
| 73 | - * @since 0.1.4 |
|
| 74 | - * |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public function getAll(); |
|
| 70 | + /** |
|
| 71 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
| 72 | + * |
|
| 73 | + * @since 0.1.4 |
|
| 74 | + * |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public function getAll(); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get the an array with all the keys |
|
| 81 | - * |
|
| 82 | - * @since 0.1.0 |
|
| 83 | - * |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function getKeys(); |
|
| 79 | + /** |
|
| 80 | + * Get the an array with all the keys |
|
| 81 | + * |
|
| 82 | + * @since 0.1.0 |
|
| 83 | + * |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function getKeys(); |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Is the Config valid? |
|
| 90 | - * |
|
| 91 | - * @since 0.1.0 |
|
| 92 | - * |
|
| 93 | - * @return boolean |
|
| 94 | - */ |
|
| 95 | - public function isValid(); |
|
| 88 | + /** |
|
| 89 | + * Is the Config valid? |
|
| 90 | + * |
|
| 91 | + * @since 0.1.0 |
|
| 92 | + * |
|
| 93 | + * @return boolean |
|
| 94 | + */ |
|
| 95 | + public function isValid(); |
|
| 96 | 96 | } |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Config Trait |
|
| 4 | - * |
|
| 5 | - * @package BrightNucleus\Config |
|
| 6 | - * @author Alain Schlesser <[email protected]> |
|
| 7 | - * @license GPL-2.0+ |
|
| 8 | - * @link http://www.brightnucleus.com/ |
|
| 9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | - */ |
|
| 3 | + * Config Trait |
|
| 4 | + * |
|
| 5 | + * @package BrightNucleus\Config |
|
| 6 | + * @author Alain Schlesser <[email protected]> |
|
| 7 | + * @license GPL-2.0+ |
|
| 8 | + * @link http://www.brightnucleus.com/ |
|
| 9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | namespace BrightNucleus\Config; |
| 13 | 13 | |
@@ -16,74 +16,74 @@ discard block |
||
| 16 | 16 | trait ConfigTrait |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Reference to the Config object. |
|
| 21 | - * |
|
| 22 | - * @since 0.1.2 |
|
| 23 | - * |
|
| 24 | - * @var ConfigInterface |
|
| 25 | - */ |
|
| 26 | - protected $config; |
|
| 19 | + /** |
|
| 20 | + * Reference to the Config object. |
|
| 21 | + * |
|
| 22 | + * @since 0.1.2 |
|
| 23 | + * |
|
| 24 | + * @var ConfigInterface |
|
| 25 | + */ |
|
| 26 | + protected $config; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Process the passed-in configuration file. |
|
| 30 | - * |
|
| 31 | - * @since 0.1.2 |
|
| 32 | - * |
|
| 33 | - * @param ConfigInterface $config The Config to process. |
|
| 34 | - */ |
|
| 35 | - protected function processConfig(ConfigInterface $config) |
|
| 36 | - { |
|
| 37 | - $this->config = $config; |
|
| 38 | - } |
|
| 28 | + /** |
|
| 29 | + * Process the passed-in configuration file. |
|
| 30 | + * |
|
| 31 | + * @since 0.1.2 |
|
| 32 | + * |
|
| 33 | + * @param ConfigInterface $config The Config to process. |
|
| 34 | + */ |
|
| 35 | + protected function processConfig(ConfigInterface $config) |
|
| 36 | + { |
|
| 37 | + $this->config = $config; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Check whether the Config has a specific key. |
|
| 42 | - * |
|
| 43 | - * @since 0.1.2 |
|
| 44 | - * |
|
| 45 | - * @param string $key The key to check. |
|
| 46 | - * @return bool Whether the key is known. |
|
| 47 | - */ |
|
| 48 | - protected function hasConfigKey($key) |
|
| 49 | - { |
|
| 50 | - return $this->config->hasKey($key); |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * Check whether the Config has a specific key. |
|
| 42 | + * |
|
| 43 | + * @since 0.1.2 |
|
| 44 | + * |
|
| 45 | + * @param string $key The key to check. |
|
| 46 | + * @return bool Whether the key is known. |
|
| 47 | + */ |
|
| 48 | + protected function hasConfigKey($key) |
|
| 49 | + { |
|
| 50 | + return $this->config->hasKey($key); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the Config value for a specific key. |
|
| 55 | - * |
|
| 56 | - * @since 0.1.2 |
|
| 57 | - * |
|
| 58 | - * @param string $key The key for which to get the value. |
|
| 59 | - * @return mixed Value of the key. |
|
| 60 | - */ |
|
| 61 | - protected function getConfigKey($key) |
|
| 62 | - { |
|
| 63 | - return $this->config->getKey($key); |
|
| 64 | - } |
|
| 53 | + /** |
|
| 54 | + * Get the Config value for a specific key. |
|
| 55 | + * |
|
| 56 | + * @since 0.1.2 |
|
| 57 | + * |
|
| 58 | + * @param string $key The key for which to get the value. |
|
| 59 | + * @return mixed Value of the key. |
|
| 60 | + */ |
|
| 61 | + protected function getConfigKey($key) |
|
| 62 | + { |
|
| 63 | + return $this->config->getKey($key); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
| 68 | - * |
|
| 69 | - * @since 0.1.4 |
|
| 70 | - * |
|
| 71 | - * @return array All the configuration settings. |
|
| 72 | - */ |
|
| 73 | - protected function getConfigArray() |
|
| 74 | - { |
|
| 75 | - return $this->config->getAll(); |
|
| 76 | - } |
|
| 66 | + /** |
|
| 67 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
| 68 | + * |
|
| 69 | + * @since 0.1.4 |
|
| 70 | + * |
|
| 71 | + * @return array All the configuration settings. |
|
| 72 | + */ |
|
| 73 | + protected function getConfigArray() |
|
| 74 | + { |
|
| 75 | + return $this->config->getAll(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get an array of all the keys that are known by the Config. |
|
| 80 | - * |
|
| 81 | - * @since 0.1.2 |
|
| 82 | - * |
|
| 83 | - * @return array Array of strings containing all the keys. |
|
| 84 | - */ |
|
| 85 | - protected function getConfigKeys() |
|
| 86 | - { |
|
| 87 | - return $this->config->getKeys(); |
|
| 88 | - } |
|
| 78 | + /** |
|
| 79 | + * Get an array of all the keys that are known by the Config. |
|
| 80 | + * |
|
| 81 | + * @since 0.1.2 |
|
| 82 | + * |
|
| 83 | + * @return array Array of strings containing all the keys. |
|
| 84 | + */ |
|
| 85 | + protected function getConfigKeys() |
|
| 86 | + { |
|
| 87 | + return $this->config->getKeys(); |
|
| 88 | + } |
|
| 89 | 89 | } |