/** * Creates a command instance from an array map representing the chain of * command. Will also iterate the creation of the command's children. * * Methods prefixed with a special character will have it's attributes set * as the following. * * $foo, endChain attribute will be set to true * ^foo, returnToBase attribute will be set to true * * N.b. Special characters are mutually exclusive. * * @param string $method * @param array $children * @return \Chainnn\Command */ public static function createFromMap($method, array $children = array()) { $flag = substr($method, 0, 1); $attr = array('endChain' => $flag === '$', 'returnToBase' => $flag === '^'); if (array_search(true, $attr, true)) { $method = substr($method, 1); } $command = new Command($method, $attr); foreach ($children as $childMethod => $childChildren) { if (is_int($childMethod)) { list($childMethod, $childChildren) = array($childChildren, array()); } $command->addChild(Command::createFromMap($childMethod, $childChildren)); } return $command; }
/** * Test the command will return to base by adding a child to it. */ public function testCommandWillReturnToBaseConstraint() { $this->setExpectedException('\\Chainnn\\Exception\\LogicException'); $parentCommand = new Command('parentMethod', array('returnToBase' => true)); $childCommand = new Command('childMethod'); $parentCommand->addChild($childCommand); }