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

Commit

Permalink
Merge pull request zendframework/zendframework#10 from weierophinney/…
Browse files Browse the repository at this point in the history
…feature/http-foundation-router

Merging router into feature/http-foundation
  • Loading branch information
ralphschindler committed Jul 26, 2011
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/Config.php
Expand Up @@ -30,7 +30,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Config implements \Countable, \Iterator
class Config implements \Countable, \Iterator, \ArrayAccess
{
/**
* Whether in-memory modifications to configuration data are allowed
Expand Down Expand Up @@ -304,6 +304,55 @@ public function valid()
return $this->_index < $this->_count;
}

/**
* offsetExists(): defined by ArrayAccess interface.
*
* @see ArrayAccess::offsetExists()
* @param mixed $offset
* @return boolean
*/
public function offsetExists($offset)
{
return $this->__isset($offset);
}

/**
* offsetGet(): defined by ArrayAccess interface.
*
* @see ArrayAccess::offsetGet()
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->__get($offset);
}

/**
* offsetSet(): defined by ArrayAccess interface.
*
* @see ArrayAccess::offsetSet()
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
$this->__set($offset, $value);
}

/**
* offsetUnset(): defined by ArrayAccess interface.
*
* @see ArrayAccess::offsetUnset()
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset)
{
$this->__unset($offset);
}

/**
* Returns the section name(s) loaded.
*
Expand Down
19 changes: 19 additions & 0 deletions test/ConfigTest.php
Expand Up @@ -316,6 +316,25 @@ public function testMerge()
$this->assertEquals(456, $stdConfig->{2});

}

public function testArrayAccess()
{
$config = new Config($this->_all, true);

$this->assertEquals('thisname', $config['name']);
$config['name'] = 'anothername';
$this->assertEquals('anothername', $config['name']);
$this->assertEquals('multi', $config['one']['two']['three']);

$this->assertTrue(isset($config['hostname']));
$this->assertTrue(isset($config['db']['name']));

unset($config['hostname']);
unset($config['db']['name']);

$this->assertFalse(isset($config['hostname']));
$this->assertFalse(isset($config['db']['name']));
}

/**
* Ensures that toArray() supports objects of types other than Zend_Config
Expand Down

0 comments on commit 1ecb5ed

Please sign in to comment.