Beispiel #1
0
 public function testAdditionalParamsArePassedToCallback()
 {
     $container = new jjok\DI\Container(array('function' => function ($self) {
         return func_get_args();
     }));
     $this->assertCount(1, $container->call('function'));
     $this->assertCount(2, $container->call('function', 'param'));
     $this->assertCount(3, $container->call('function', 'param', 'another param'));
 }
Beispiel #2
0
Datei: index.php Projekt: jjok/di
    /**
     * Set the test parameter.
     * @param string $param
     */
    public function __construct($param)
    {
        $this->param = $param;
    }
}
class SomeClass
{
    /**
     * A test object dependency.
     * @var SomeDependency
     */
    protected $dependency;
    /**
     * Set the test dependency.
     * @param SomeDependency $dependency
     */
    public function __construct(SomeDependency $dependency)
    {
        $this->dependency = $dependency;
    }
}
$container = new \jjok\DI\Container(array('SomeDependency' => function ($self, $param) {
    return new SomeDependency($param);
}, 'SomeClass' => function ($self) {
    return new SomeClass($self->call('SomeDependency', 'some-param'));
}));
var_dump($container->call('SomeClass'));