protected function parseDefinition($service) { if (is_string($service) && 0 === strpos($service, '@')) { return substr($service, 1); } $definition = new sfServiceDefinition($service['class']); if (isset($service['shared'])) { $definition->setShared($service['shared']); } if (isset($service['constructor'])) { $definition->setConstructor($service['constructor']); } if (isset($service['file'])) { $definition->setFile($service['file']); } if (isset($service['arguments'])) { $definition->setArguments($this->resolveServices($service['arguments'])); } if (isset($service['configurator'])) { if (is_string($service['configurator'])) { $definition->setConfigurator($service['configurator']); } else { $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1])); } } if (isset($service['calls'])) { foreach ($service['calls'] as $call) { $definition->addMethodCall($call[0], $this->resolveServices($call[1])); } } return $definition; }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(21); // __construct() $t->diag('__construct()'); $def = new sfServiceDefinition('stdClass'); $t->is($def->getClass(), 'stdClass', '__construct() takes the class name as its first argument'); $def = new sfServiceDefinition('stdClass', array('foo')); $t->is($def->getArguments(), array('foo'), '__construct() takes an optional array of arguments as its second argument'); // ->setConstructor() ->getConstructor() $t->diag('->setConstructor() ->getConstructor()'); $def = new sfServiceDefinition('stdClass'); $t->is(spl_object_hash($def->setConstructor('foo')), spl_object_hash($def), '->setConstructor() implements a fluent interface'); $t->is($def->getConstructor(), 'foo', '->getConstructor() returns the constructor name'); // ->setClass() ->getClass() $t->diag('->setClass() ->getClass()'); $def = new sfServiceDefinition('stdClass'); $t->is(spl_object_hash($def->setClass('foo')), spl_object_hash($def), '->setClass() implements a fluent interface'); $t->is($def->getClass(), 'foo', '->getClass() returns the class name'); // ->setArguments() ->getArguments() ->addArgument() $t->diag('->setArguments() ->getArguments() ->addArgument()'); $def = new sfServiceDefinition('stdClass'); $t->is(spl_object_hash($def->setArguments(array('foo'))), spl_object_hash($def), '->setArguments() implements a fluent interface'); $t->is($def->getArguments(), array('foo'), '->getArguments() returns the arguments'); $t->is(spl_object_hash($def->addArgument('bar')), spl_object_hash($def), '->addArgument() implements a fluent interface'); $t->is($def->getArguments(), array('foo', 'bar'), '->addArgument() adds an argument'); // ->setMethodCalls() ->getMethodCalls() ->addMethodCall() $t->diag('->setMethodCalls() ->getMethodCalls() ->addMethodCall()');