Ejemplo n.º 1
0
 protected function addRoute($route, $pathStr)
 {
     $method = "any";
     if (strpos($pathStr, "@") !== false) {
         list($pathStr, $method) = explode("@", $pathStr);
     }
     $func = $this->processCallback($pathStr);
     $r = new \Slim\Route($route, $func);
     $r->setHttpMethods(strtoupper($method));
     array_push($this->routes, $r);
 }
Ejemplo n.º 2
0
 public function addRoutes($routes)
 {
     foreach ($routes as $route => $path) {
         $method = "any";
         if (strpos($path, "@") !== false) {
             list($path, $method) = explode("@", $path);
         }
         $func = $this->processCallback($path);
         $r = new \Slim\Route($route, $func);
         $r->setHttpMethods(strtoupper($method));
         array_push($this->routes, $r);
     }
 }
Ejemplo n.º 3
0
 public function testSetHttpMethods()
 {
     $route = new \Slim\Route('/foo', function () {
     });
     $route->setHttpMethods('GET', 'POST');
     $this->assertAttributeEquals(array('GET', 'POST'), 'methods', $route);
 }
Ejemplo n.º 4
0
 /**
  * Test that a Route manages the HTTP methods that it supports
  *
  * Case A: Route initially supports no HTTP methods
  * Case B: Route can set its supported HTTP methods
  * Case C: Route can append supported HTTP methods
  * Case D: Route can test if it supports an HTTP method
  * Case E: Route can lazily declare supported HTTP methods with `via`
  */
 public function testHttpMethods()
 {
     //Case A
     $r = new \Slim\Route('/foo', function () {
     });
     $this->assertEmpty($r->getHttpMethods());
     //Case B
     $r->setHttpMethods('GET');
     $this->assertEquals(array('GET'), $r->getHttpMethods());
     //Case C
     $r->appendHttpMethods('POST', 'PUT');
     $this->assertEquals(array('GET', 'POST', 'PUT'), $r->getHttpMethods());
     //Case D
     $this->assertTrue($r->supportsHttpMethod('GET'));
     $this->assertFalse($r->supportsHttpMethod('DELETE'));
     //Case E
     $viaResult = $r->via('DELETE');
     $this->assertTrue($viaResult instanceof \Slim\Route);
     $this->assertTrue($r->supportsHttpMethod('DELETE'));
 }