示例#1
0
 /**
  * Call
  *
  * Iterate each matching Route until all Routes are exhausted.
  * Return an array of HTTP status, header, and body.
  *
  * @param   array   $env    Key-value array of environment properties
  * @return  array           [status, header, body]
  */
 public function call(&$env)
 {
     try {
         if (isset($env['slim.flash'])) {
             $this->view()->setData('flash', $env['slim.flash']);
         }
         $this->applyHook('slim.before');
         ob_start();
         $this->applyHook('slim.before.router');
         $dispatched = false;
         $httpMethodsAllowed = array();
         foreach ($this->router as $route) {
             if ($route->supportsHttpMethod($env['REQUEST_METHOD'])) {
                 try {
                     $this->applyHook('slim.before.dispatch');
                     $dispatched = $route->dispatch();
                     $this->applyHook('slim.after.dispatch');
                     if ($dispatched) {
                         break;
                     }
                 } catch (Slim_Exception_Pass $e) {
                     continue;
                 }
             } else {
                 $httpMethodsAllowed = array_merge($httpMethodsAllowed, $route->getHttpMethods());
             }
         }
         if (!$dispatched) {
             if ($httpMethodsAllowed) {
                 $this->response['Allow'] = implode(' ', $httpMethodsAllowed);
                 $this->halt(405, 'HTTP method not allowed for the requested resource. Use one of these instead: ' . implode(', ', $httpMethodsAllowed));
             } else {
                 $this->notFound();
             }
         }
         $this->applyHook('slim.after.router');
         $this->response->write(ob_get_clean());
         $this->applyHook('slim.after');
         $this->stop();
     } catch (Slim_Exception_Stop $e) {
         $this->response()->write(ob_get_contents());
         return $this->response->finalize();
     } catch (Slim_Exception_RequestSlash $e) {
         $this->response->redirect($this->request->getPath() . '/', 301);
         return $this->response->finalize();
     } catch (Exception $e) {
         if ($this->config('debug')) {
             throw $e;
         } else {
             try {
                 $this->error($e);
             } catch (Slim_Exception_Stop $e) {
             }
             return $this->response->finalize();
         }
     }
 }
示例#2
0
 /**
  * Call
  *
  * Iterate each matching Route until all Routes are exhausted.
  *
  * @return void
  */
 public function call()
 {
     try {
         if (isset($this->environment['slim.flash'])) {
             $this->view()->setData('flash', $this->environment['slim.flash']);
         }
         $this->applyHook('slim.before');
         ob_start();
         $this->applyHook('slim.before.router');
         $dispatched = false;
         $httpMethodsAllowed = array();
         $this->router->getMatchedRoutes();
         foreach ($this->router as $route) {
             if ($route->supportsHttpMethod($this->environment['REQUEST_METHOD'])) {
                 try {
                     $this->applyHook('slim.before.dispatch');
                     $dispatched = $this->router->dispatch($route);
                     $this->applyHook('slim.after.dispatch');
                     if ($dispatched) {
                         break;
                     }
                 } catch (Slim_Exception_Pass $e) {
                     continue;
                 }
             } else {
                 $httpMethodsAllowed = array_merge($httpMethodsAllowed, $route->getHttpMethods());
             }
         }
         if (!$dispatched) {
             if ($httpMethodsAllowed) {
                 $this->response['Allow'] = implode(' ', $httpMethodsAllowed);
                 // This implementation discards the httpMethodsAllowed info.
                 // Maybe we should save it somewhere for use by methodNotAllowed?
                 $this->methodNotAllowed();
             } else {
                 $this->notFound();
             }
         }
         $this->applyHook('slim.after.router');
         $this->stop();
     } catch (Slim_Exception_Stop $e) {
         $this->response()->write(ob_get_clean());
         $this->applyHook('slim.after');
     } catch (Slim_Exception_RequestSlash $e) {
         $this->response->redirect($this->request->getPath() . '/', 301);
     } catch (Exception $e) {
         if ($this->config('debug')) {
             throw $e;
         } else {
             try {
                 $this->error($e);
             } catch (Slim_Exception_Stop $e) {
             }
         }
     }
 }
示例#3
0
 /**
  * Test get [script name, root uri, path, path info, resource uri] in root directory with htaccess
  */
 public function testAppPathsInRootDirectoryWithHtaccess()
 {
     $env = Slim_Environment::mock(array('SCRIPT_NAME' => '', 'PATH_INFO' => '/bar/xyz'));
     $req = new Slim_Http_Request($env);
     $this->assertEquals('', $req->getScriptName());
     $this->assertEquals('', $req->getRootUri());
     $this->assertEquals('/bar/xyz', $req->getPath());
     $this->assertEquals('/bar/xyz', $req->getPathInfo());
     $this->assertEquals('/bar/xyz', $req->getResourceUri());
 }
示例#4
0
 /**
  * Test get [script name, root uri, path, path info, resource uri] in root directory with htaccess
  */
 public function testAppPathsInRootDirectoryWithHtaccess()
 {
     Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/bar/xyz', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w')));
     $env = Slim_Environment::getInstance();
     $req = new Slim_Http_Request($env);
     $this->assertEquals('', $req->getScriptName());
     $this->assertEquals('', $req->getRootUri());
     $this->assertEquals('/bar/xyz', $req->getPath());
     $this->assertEquals('/bar/xyz', $req->getPathInfo());
     $this->assertEquals('/bar/xyz', $req->getResourceUri());
 }