Beispiel #1
0
 /**
  * Get URL for named route
  * @param   string              $name   The name of the route
  * @param   array                       Associative array of URL parameter names and values
  * @throws  RuntimeException            If named route not found
  * @return  string                      The URL for the given route populated with the given parameters
  */
 public function urlFor($name, $params = array())
 {
     if (!$this->hasNamedRoute($name)) {
         throw new RuntimeException('Named route not found for name: ' . $name);
     }
     $pattern = $this->getNamedRoute($name)->getPattern();
     $search = $replace = array();
     foreach ($params as $key => $value) {
         $search[] = ':' . $key;
         $replace[] = $value;
     }
     $pattern = str_replace($search, $replace, $pattern);
     //Remove remnants of unpopulated, trailing optional pattern segments
     return preg_replace(array('@\\(\\/?:.+\\/??\\)\\??@', '@\\?|\\(|\\)@'), '', $this->request->getRootUri() . $pattern);
 }
 /**
  * Default Not Found handler
  * @return void
  */
 protected function defaultNotFound()
 {
     echo self::generateTemplateMarkup('404 Page Not Found', '<p>The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.</p><a href="' . $this->request->getRootUri() . '">Visit the Home Page</a>');
 }
Beispiel #3
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());
 }
Beispiel #4
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());
 }
Beispiel #5
0
 /**
  * Test request URI without htaccess
  *
  * Pre-conditions:
  * The HTTP request URI is /foo/index.php/foo/bar/. The mock HTTP request simulates
  * a scenario where the Slim app resides in a subdirectory of the document root directory
  * without htaccess URL rewriting.
  *
  * Post-conditions:
  * The Request root should be "/foo/index.php" and the resource "/foo/bar"
  */
 public function testRequestUriInSubDirectoryWitoutHtaccess()
 {
     $_SERVER['REQUEST_URI'] = '/foo/bootstrap.php/foo/bar/';
     $_SERVER['SCRIPT_NAME'] = '/foo/bootstrap.php';
     $r = new Slim_Http_Request();
     $this->assertEquals('/foo/bootstrap.php', $r->getRootUri());
     $this->assertEquals('/foo/bar/', $r->getResourceUri());
 }