Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 40 changed files with 100 additions and 68 deletions.
28 changes: 15 additions & 13 deletions src/Config.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand All @@ -30,7 +30,7 @@ class Config implements Countable, Iterator, ArrayAccess
/**
* Whether modifications to configuration data are allowed.
*
* @var boolean
* @var bool
*/
protected $allowModifications;

Expand All @@ -52,7 +52,7 @@ class Config implements Countable, Iterator, ArrayAccess
* Used when unsetting values during iteration to ensure we do not skip
* the next element.
*
* @var boolean
* @var bool
*/
protected $skipNextIteration;

Expand All @@ -63,15 +63,15 @@ class Config implements Countable, Iterator, ArrayAccess
* on construction.
*
* @param array $array
* @param boolean $allowModifications
* @param bool $allowModifications
*/
public function __construct(array $array, $allowModifications = false)
{
$this->allowModifications = (boolean) $allowModifications;
$this->allowModifications = (bool) $allowModifications;

foreach ($array as $key => $value) {
if (is_array($value)) {
$this->data[$key] = new self($value, $this->allowModifications);
$this->data[$key] = new static($value, $this->allowModifications);
} else {
$this->data[$key] = $value;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public function __set($name, $value)
if ($this->allowModifications) {

if (is_array($value)) {
$value = new self($value, true);
$value = new static($value, true);
}

if (null === $name) {
Expand Down Expand Up @@ -185,7 +185,7 @@ public function toArray()
* isset() overloading
*
* @param string $name
* @return boolean
* @return bool
*/
public function __isset($name)
{
Expand Down Expand Up @@ -276,7 +276,7 @@ public function rewind()
* valid(): defined by Iterator interface.
*
* @see Iterator::valid()
* @return boolean
* @return bool
*/
public function valid()
{
Expand All @@ -288,7 +288,7 @@ public function valid()
*
* @see ArrayAccess::offsetExists()
* @param mixed $offset
* @return boolean
* @return bool
*/
public function offsetExists($offset)
{
Expand Down Expand Up @@ -354,17 +354,19 @@ public function merge(self $merge)
$this->data[$key]->merge($value);
} else {
if ($value instanceof self) {
$this->data[$key] = new self($value->toArray(), $this->allowModifications);
$this->data[$key] = new static($value->toArray(), $this->allowModifications);
} else {
$this->data[$key] = $value;
}
}
} else {
if ($value instanceof self) {
$this->data[$key] = new self($value->toArray(), $this->allowModifications);
$this->data[$key] = new static($value->toArray(), $this->allowModifications);
} else {
$this->data[$key] = $value;
}

$this->count++;
}
}

Expand Down Expand Up @@ -394,7 +396,7 @@ public function setReadOnly()
/**
* Returns whether this Config object is read only or not.
*
* @return boolean
* @return bool
*/
public function isReadOnly()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ExceptionInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/RuntimeException.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Factory.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down Expand Up @@ -43,7 +43,7 @@ class Factory
* Read a config from a file.
*
* @param string $filename
* @param boolean $returnConfigObject
* @param bool $returnConfigObject
* @return array|Config
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function fromFile($filename, $returnConfigObject = false)
* Read configuration from multiple files and merge them.
*
* @param array $files
* @param boolean $returnConfigObject
* @param bool $returnConfigObject
* @return array|Config
*/
public static function fromFiles(array $files, $returnConfigObject = false)
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Constant.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Filter.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/ProcessorInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Queue.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Token.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Translator.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
27 changes: 24 additions & 3 deletions src/Reader/Ini.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down Expand Up @@ -131,8 +131,8 @@ protected function process(array $data)
foreach ($data as $section => $value) {
if (is_array($value)) {
if (strpos($section, $this->nestSeparator) !== false) {
$section = explode($this->nestSeparator, $section, 2);
$config[$section[0]][$section[1]] = $this->processSection($value);
$sections = explode($this->nestSeparator, $section);
$config = array_merge_recursive($config, $this->buildNestedSection($sections, $value));
} else {
$config[$section] = $this->processSection($value);
}
Expand All @@ -144,6 +144,27 @@ protected function process(array $data)
return $config;
}

/**
* Process a nested section
*
* @param array $sections
* @param mixed $value
* @return array
*/
private function buildNestedSection($sections, $value)
{
if(count($sections) == 0) {
return $this->processSection($value);
}

$nestedSection = array();

$first = array_shift($sections);
$nestedSection[$first] = $this->buildNestedSection($sections, $value);

return $nestedSection;
}

/**
* Process a section.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Json.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/ReaderInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand All @@ -29,7 +29,7 @@ public function fromFile($filename);
* Read from a string and create an array
*
* @param string $string
* @return array|boolean
* @return array|bool
*/
public function fromString($string);
}
2 changes: 1 addition & 1 deletion src/Reader/Xml.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Yaml.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderPluginManager.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/AbstractWriter.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand All @@ -28,7 +28,7 @@ abstract class AbstractWriter implements WriterInterface
* @see WriterInterface::toFile()
* @param string $filename
* @param mixed $config
* @param boolean $exclusiveLock
* @param bool $exclusiveLock
* @return void
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/Ini.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ public function setRenderWithoutSectionsFlags($withoutSections)
/**
* Return whether the writer should render without sections.
*
* @return boolean
* @return bool
*/
public function shouldRenderWithoutSections()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/Json.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/PhpArray.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/WriterInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/
Expand All @@ -22,7 +22,7 @@ interface WriterInterface
*
* @param string $filename
* @param mixed $config
* @param boolean $exclusiveLock
* @param bool $exclusiveLock
* @return void
*/
public function toFile($filename, $config, $exclusiveLock = true);
Expand Down

0 comments on commit 57cb4a0

Please sign in to comment.