예제 #1
0
파일: example.php 프로젝트: boan2010/unbox
 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);
 }
예제 #2
0
파일: test.php 프로젝트: boan2010/unbox
    }, [$container->ref('cache.path')]);
    $container->register(UserRepository::class, function (CacheProvider $cp) {
        return new UserRepository($cp);
    }, ['cp' => $container->ref('cache')]);
    $repo = $container->get(UserRepository::class);
    ok($repo instanceof UserRepository);
    ok($repo->cache instanceof CacheProvider);
    eq($repo->cache->path, '/tmp/cache');
});
test('can act as a factory', function () {
    $container = new Container();
    $container->register(CacheProvider::class, function () {
        return new FileCache('/tmp/cache');
    });
    $repo = $container->create(UserRepository::class);
    ok($repo instanceof UserRepository);
    $another = $container->create(UserRepository::class);
    ok($repo !== $another);
});
test('can override factory maps', function () {
    $container = new Container();
    $container->set('cache.path', '/tmp/cache');
    $container->register(CacheProvider::class, FileCache::class, [$container->ref('cache.path')]);
    $repo = $container->create(UserRepository::class);
    eq($repo->cache->path, '/tmp/cache');
    $repo = $container->create(UserRepository::class, [new FileCache('/my/path')]);
    eq($repo->cache->path, '/my/path');
});
configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__) . '/src');
exit(run());
// exits with errorlevel (for CI tools etc.)