Esempio n. 1
0
 public function run($path, $params)
 {
     list($controller, $action) = explode("/", $path);
     $class = ucfirst($controller) . "Controller";
     $method = $action;
     $this->container->call([$this->container->create($class), $method], $params);
 }
Esempio n. 2
0
    });
    $conf_by_name = null;
    $container->configure(function ($cache) use(&$conf_by_name) {
        $conf_by_name = $cache;
    });
    eq($container->get(FileCache::class)->path, "/tmp/foo");
    eq($container->get("cache")->path, "/tmp/bar");
    eq($by_type->path, "/tmp/foo");
    eq($by_name->path, "/tmp/bar");
    eq($conf_by_type->path, "/tmp/foo");
    eq($conf_by_name->path, "/tmp/bar");
});
test('can call all the things', function () {
    $container = new Container();
    $container->set('foo', 'bar');
    eq($container->call('test_func'), 'bar', 'can call function');
    eq($container->call([Foo::class, 'bat']), 'bar', 'can call static method');
    $foo = new Foo();
    eq($container->call([$foo, 'bar']), 'bar', 'can call instance method');
    eq($container->call($foo), 'bar', 'can call __invoke()');
    eq($container->call(function ($foo) {
        return $foo;
    }), 'bar', 'can call Closure');
    eq($container->call(function ($nope = 'nope') {
        return $nope ? 'yep' : 'whoa';
    }), 'yep', 'can supply default argument');
});
test('can resolve dependencies by name', function () {
    $container = new Container();
    $container->set('cache.path', '/tmp/cache');
    $container->register(CacheProvider::class, function (Container $c) {