Example #1
0
 public function testProvidersSingletonLazy()
 {
     // Arrange
     $injector = new Injector(null);
     $injector->providers(['BASE_URL' => ValueProvider::init('http://sysvyz.org/')->singleton()->lazy()]);
     $this->assertEquals($injector->{'BASE_URL'}, 'http://sysvyz.org/');
 }
Example #2
0
 /**
  *
  */
 public function testInvoker()
 {
     $injector = new Injector();
     $injector->provide('%VALUE%', ValueProvider::init(5));
     $obj = $injector->{InvokableObject::class};
     $invoker = new Invoker($injector);
     $res = $invoker->invoke($obj, 'execute');
     $this->assertEquals($res, 30);
 }
Example #3
0
 public function testProvidersLazy()
 {
     // Arrange
     $injector = new Injector(null);
     $injector->providers([Controller::class => ClassProvider::init(ControllerA::class)->lazy(), '%BASE_URL%' => ValueProvider::init('http://sysvyz.org/')]);
     /** @var ControllerA $ctrl */
     $ctrl = $injector->get(Controller::class);
     $this->assertInstanceOf(ControllerA::class, $ctrl);
     $this->assertSame($ctrl->requestService, $ctrl->serviceZ->requestService);
     $this->assertNotSame($ctrl->requestService, $ctrl->serviceZ->serviceY->requestService);
     $this->assertNotEquals($ctrl->requestService->url, $ctrl->serviceZ->serviceY->requestService->url);
 }
Example #4
0
 private function buildLazy($count)
 {
     $t = microtime(true);
     $injector = new Injector();
     $injector->provide(ControllerA::class, ClassProvider::init(ControllerA::class)->lazy());
     $injector->provide('%BASE_URL%', ValueProvider::init('%BASE_URL%'));
     $arr = [];
     for ($i = 0; $i < $count; $i++) {
         $arr[] = $injector->get(ControllerA::class);
     }
     return microtime(true) - $t;
 }
Example #5
0
 public static function _DI_PROVIDERS()
 {
     return ['%BASE_URL%' => ValueProvider::init('http://www.sysvyz.org'), ServiceY::class => ClassProvider::init(ServiceY::class)] + parent::_DI_PROVIDERS();
 }