Skip to content

Commit

Permalink
Add support for setting sections
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed May 5, 2015
1 parent fef7f51 commit 7c3de1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ConfigProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public function getSection($name);
*/
public function addSection(ConfigSectionInterface $section);

/**
* Same as addSection, however, will replace an existing section if one exists
*
* @param ConfigSectionInterface $section Section container to add
*
* @return $this
*/
public function setSection(ConfigSectionInterface $section);

/**
* Check to see if a section exists within the configuration
*
Expand Down
13 changes: 13 additions & 0 deletions src/Provider/AbstractConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ public function addSection(ConfigSectionInterface $section)
return $this;
}

/**
* Same as addSection, however, will replace an existing section if one exists
*
* @param ConfigSectionInterface $section Section container to add
*
* @return $this
*/
public function setSection(ConfigSectionInterface $section)
{
$this->_sections[$section->getName()] = $section;
return $this;
}

/**
* Remove a section from the configuration
*
Expand Down
14 changes: 14 additions & 0 deletions tests/ConfigProviderBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ public function testSectionAdd()
$provider->addSection($section);
}

/**
* @depends testValidProvider
*/
public function testSectionSet()
{
$section = new \Packaged\Config\Provider\ConfigSection("db");
$provider = $this->getConfigProvider();
$this->assertInstanceOf(
'\Packaged\Config\ConfigProviderInterface',
$provider->setSection($section)
);
$provider->setSection($section);
}

/**
* @depends testValidProvider
*/
Expand Down

0 comments on commit 7c3de1d

Please sign in to comment.