Пример #1
0
 /**
  * Load the RouteCollection from a test yml file and try a valid
  * route but with an invalid HTTP method
  */
 public function testYamlMethodFails()
 {
     // A POST request to a defined path should fail
     $request = WebRequest::create('/foo', 'POST', array('name' => 'Chris Noden'));
     $request->overrideGlobals();
     $obj = new WebRouter($request);
     $obj->setRouteCollectionFromFile(SYNERGY_TEST_FILES_DIR . DIRECTORY_SEPARATOR . 'test_routes.yml');
     // Test for the exception
     $this->setExpectedException('Symfony\\Component\\Routing\\Exception\\MethodNotAllowedException', '');
     $obj->match();
 }
Пример #2
0
 /**
  * Our main method : let's go and run our web project
  *
  * @return void
  */
 protected function launch()
 {
     if ($this->deliverResponse && !$this->isDev && $this->getCacheFile() && $this->request->getMethod() == 'GET') {
         return;
     }
     $this->loadBootstrap();
     $this->setAbsoluteStubUrl();
     /**
      * @var WebRouter $router
      */
     $router = new WebRouter($this->request);
     // use the best routes config
     if ($this->getOption('synergy:routes') && file_exists($this->getOption('synergy:routes'))) {
         $filename = $this->getOption('synergy:routes');
     }
     if (isset($filename)) {
         Logger::debug('RouteCollection from file: ' . $filename);
         $router->setRouteCollectionFromFile($filename);
     }
     // add our _synergy_ route
     $router = $this->addSynergyRoute($router);
     // Match the route
     $router->match();
     /**
      * Get the ControllerEntity
      */
     $this->controller = $router->getController();
     $this->controller->setProject($this);
     $this->controller->setRequest($this->request);
     // Call the action
     try {
         $this->response = $this->controller->callControllerAction();
     } catch (\Exception $ex) {
         $this->response = $this->errorResponse($ex->getMessage(), $ex->getCode());
     }
     if ($this->deliverResponse === true) {
         // Deal with any response object that was returned
         if ($this->response instanceof WebResponse) {
             $this->handleWebResponse($this->response);
         } elseif ($this->response instanceof TemplateAbstract) {
             $this->handleWebTemplate($this->response);
         } elseif ($this->response instanceof WebAsset) {
             $this->response->deliver();
         } elseif (is_string($this->response)) {
             $render = WebResponse::create($this->response);
             $render->send();
         } else {
             $this->handleNotFoundException($this->response);
         }
     }
 }