예제 #1
0
 private function createHandler($url)
 {
     $environment = new Environment(true, true, 'test', __DIR__);
     $_SERVER = [];
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $session = new Session($environment);
     $request = new HTTPRequest($url, $session);
     $dependencyInjection = new DependencyInjection();
     $dependencyInjection->addInstance('environment', $environment);
     $dependencyInjection->addInstance('config', $this->createConfigContainer());
     $dependencyInjection->addInstance('eventManager', new EventManager());
     $dependencyInjection->addInstance('presenter.html', new HTML($environment));
     $dependencyInjection->addInstance('presenter.json', new JSON($environment));
     return new HTTPErrorHandler($dependencyInjection, $request);
 }
예제 #2
0
 public function testAddInstance()
 {
     $di = new DependencyInjection();
     $instance = new StandaloneClass('1', '2');
     $di->addInstance('class', $instance);
     $dependencyClass = $di->get('class');
     $this->assertEquals('1', $dependencyClass->getParam1());
     $this->assertEquals('2', $dependencyClass->getParam2());
 }
예제 #3
0
파일: Root.php 프로젝트: itephp/framework
 /**
  *
  * @param string $url
  */
 public function executeRequest($url)
 {
     //config
     $this->errorManager = new ErrorManager();
     $this->errorManager->addHandler(new CriticalErrorHandler($this->environment));
     $dependencyInjection = new DependencyInjection();
     $this->initConfig();
     $snippets = $this->getSnippets();
     $this->container = new Container($dependencyInjection, $snippets);
     $dependencyInjection->addInstance('container', $this->container);
     $dependencyInjection->addInstance('environment', $this->environment);
     $dependencyInjection->addInstance('config', $this->config);
     $this->registerServices($dependencyInjection);
     $this->registerEventManager($dependencyInjection);
     $this->registerEvents($dependencyInjection);
     $this->registerPresenters($dependencyInjection);
     //request
     $session = new Session($this->environment);
     $request = new HTTPRequest($url, $session);
     $dependencyInjection->addInstance('request', $request);
     $this->reconfigureErrorManager($dependencyInjection, $request);
     try {
         $dispatcher = $this->createHttpRouter($dependencyInjection, $request)->createDispatcher($url);
         $dispatcher->execute();
     } catch (RouteNotFoundException $e) {
         $this->errorManager->exception(new HTTPException(404, $e->getMessage()));
     } catch (\Exception $e) {
         $this->errorManager->exception($e);
     }
 }