protected function parseDefinition($id, $service, $file) { if (is_string($service) && 0 === strpos($service, '@')) { $this->container->setAlias($id, substr($service, 1)); return; } $definition = new Definition(); if (isset($service['class'])) { $definition->setClass($service['class']); } if (isset($service['shared'])) { $definition->setShared($service['shared']); } if (isset($service['factory_method'])) { $definition->setFactoryMethod($service['factory_method']); } if (isset($service['factory_service'])) { $definition->setFactoryService($service['factory_service']); } 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])); } } if (isset($service['annotations'])) { foreach ($service['annotations'] as $annotation) { $name = $annotation['name']; unset($annotation['name']); $definition->addAnnotation($name, $annotation); } } $this->container->setDefinition($id, $definition); }
$t = new LimeTest(21); // __construct() $t->diag('__construct()'); $def = new Definition('stdClass'); $t->is($def->getClass(), 'stdClass', '__construct() takes the class name as its first argument'); $def = new Definition('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 Definition('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 Definition('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 Definition('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()'); $def = new Definition('stdClass'); $t->is(spl_object_hash($def->setMethodCalls(array(array('foo', array('foo'))))), spl_object_hash($def), '->setMethodCalls() implements a fluent interface'); $t->is($def->getMethodCalls(), array(array('foo', array('foo'))), '->getMethodCalls() returns the methods to call'); $t->is(spl_object_hash($def->addMethodCall('bar', array('bar'))), spl_object_hash($def), '->addMethodCall() implements a fluent interface'); $t->is($def->getMethodCalls(), array(array('foo', array('foo')), array('bar', array('bar'))), '->addMethodCall() adds a method to call');
public function testSetGetClass() { $def = new Definition('stdClass'); $this->assertEquals(spl_object_hash($def->setClass('foo')), spl_object_hash($def), '->setClass() implements a fluent interface'); $this->assertEquals($def->getClass(), 'foo', '->getClass() returns the class name'); }