예제 #1
0
 public function testDIMultiInstance()
 {
     $key1 = 'hello';
     $value1 = 'stdClass';
     $key2 = 'Night';
     $value2 = 'stdClass';
     //register key1 in first instance, key2 in second instance
     $this->orno->add($key1, $value1);
     $orno = new OrnoContainer();
     $orno->add($key2, $value2);
     $adapter = new OrnoAdapter($orno);
     $this->container->provider($adapter);
     $this->assertInstanceOf($value1, $this->container->get($key1));
     $this->assertInstanceOf($value2, $this->container->get($key2));
 }
예제 #2
0
파일: ContainerTest.php 프로젝트: orno/di
 public function testContainerResolvesRegisteredCallable()
 {
     $c = new Container();
     $c->add('OrnoTest\\Assets\\BazInterface', 'OrnoTest\\Assets\\Baz');
     $c->invokable('function', function (\OrnoTest\Assets\Foo $foo) {
         return $foo;
     })->withArgument('OrnoTest\\Assets\\Foo');
     $foo = $c->call('function');
     $this->assertInstanceOf('OrnoTest\\Assets\\Foo', $foo);
     $this->assertInstanceOf('OrnoTest\\Assets\\Bar', $foo->bar);
     $this->assertInstanceOf('OrnoTest\\Assets\\Baz', $foo->bar->baz);
     $this->assertInstanceOf('OrnoTest\\Assets\\BazInterface', $foo->bar->baz);
 }
예제 #3
0
 /**
  * @param Container $container
  */
 public static function setupHttpClient($container)
 {
     $container->add('httpClient', function () use($container) {
         $dnsResolverFactory = new Factory();
         $loop = $container->get('eventloop');
         $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);
         $factory = new HttpFactory();
         $client = $factory->create($loop, $dnsResolver);
         return $client;
     }, true);
 }
예제 #4
0
 /**
  * @param Container $container
  */
 public static function setupDB(Container $container)
 {
     $container->add('db', DB::class, true)->withArgument('config');
 }