DataSift\Storyplayer\ConfigLib\HardCodedList::addConfig PHP Méthode

addConfig() public méthode

add a new config object to the list
public addConfig ( object $config )
$config object the config object to add to the list
    public function addConfig($config)
    {
        // make sure the config is compatible first
        if (!$config instanceof $this->configType) {
            throw new E4xx_IncompatibleConfigClass($this->configType, get_class($config));
        }
        // if we get here, then we're good to go
        $name = $config->getName();
        $this->configs[$name] = $config;
        // keep the list sorted
        ksort($this->configs);
    }

Usage Example

 /**
  * @covers DataSift\Storyplayer\ConfigLib\HardCodedList::__construct
  * @covers DataSift\Storyplayer\ConfigLib\HardCodedList::addConfig
  * @expectedException DataSift\Storyplayer\ConfigLib\E4xx_IncompatibleConfigClass
  */
 public function testCanAddedConfigsMustBeCompatibleType()
 {
     // ----------------------------------------------------------------
     // setup the test
     $expectedName = 'test-config';
     $obj = new HardCodedList('DataSift\\Storyplayer\\ConfigLib\\StoryplayerConfig');
     // ----------------------------------------------------------------
     // perform the change
     $config = new WrappedConfig();
     $config->setName($expectedName);
     $obj->addConfig($config);
 }