예제 #1
0
 public function testProvide()
 {
     $dic = \jakulov\Container\DIContainer::getInstance(require __DIR__ . '/config.php');
     /** @var Service\TestService $testService */
     $testService = $dic->get('test');
     $this->assertEquals(null, $testService->requestTestService->someGlobalShit, 'Request is empty');
     /** @var Service\RequestTestService $request */
     $request = $dic->get('request_test');
     $this->assertEquals(spl_object_hash($testService->requestTestService), spl_object_hash($request));
     $request->someGlobalShit = 'A';
     $this->assertEquals('A', $testService->requestTestService->someGlobalShit);
     $newRequest = new \Service\RequestTestService();
     $newRequest->someGlobalShit = 'B';
     /** @var Service\RequestTestService $providedRequest */
     $providedRequest = $dic->provide('request_test', $newRequest)->get('request_test');
     $this->assertEquals(spl_object_hash($newRequest), spl_object_hash($providedRequest), 'Provided request not new?');
     $this->assertEquals('B', $testService->requestTestService->someGlobalShit);
 }
예제 #2
0
파일: App.php 프로젝트: jakulov/corpuscle
 /**
  * App constructor.
  * @param array $config
  */
 protected function __construct(array $config = [])
 {
     $this->DIContainer = DIContainer::getInstance($config);
 }
예제 #3
0
 /**
  * @return DIContainer
  */
 protected function getDIContainer()
 {
     return DIContainer::getInstance();
 }