Ejemplo n.º 1
0
 /**
  * Scalr-Evironment middleware handler
  *
  * It extracts :environment group parameter from the route
  * and sets application setting
  *
  * @param   Route $route A route
  * @throws  ApiErrorException
  */
 public function handleEnvironment($route)
 {
     $params = $route->getParams();
     if (!is_numeric($params['environment']) || $params['environment'] <= 0) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Environment has not been provided with the request");
     }
     $this->settings[self::SETTING_SCALR_ENVIRONMENT] = (int) $params['environment'];
     unset($params['environment']);
     $route->setParams($params);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function testMatches()
 {
     $route = $this->getRouteFixture();
     $this->assertFalse($route->matches('/api'));
     $this->assertFalse($route->matches('/api/foo'));
     $this->assertFalse($route->matches('/api/path/:id'));
     $this->assertTrue($route->matches('/api/path/123'));
     $this->assertCount(1, $route->getParams());
     $this->assertArrayHas(123, 'id', $route->getParams());
     $this->assertTrue($route->matches('/api/path/167'));
     $this->assertCount(1, $route->getParams());
     $this->assertArrayHas(167, 'id', $route->getParams());
     $this->assertFalse($route->matches('/api/path/892/23'));
     $this->assertCount(0, $route->getParams());
     $route2 = new Route('/api/path/(:namepath)+', function () {
     }, ['namepath' => '[a-z/-]+']);
     $route2->setMethods([Request::METHOD_GET]);
     $pathName = 'news/recent/open-stack-journey';
     $this->assertTrue($route2->matches('/api/path/' . $pathName));
     $this->assertArrayHas($pathName, 'namepath', $route2->getParams());
     $pathName = '_0news/recent';
     $this->assertFalse($route2->matches('/api/path/' . $pathName));
 }
Ejemplo n.º 3
0
 /**
  * ApiVersion middleware handler
  *
  * It extracts :apiversion group parameter from the route
  * and sets application setting
  *
  * @param   Route   $route  A route
  */
 public function handleApiVersion($route)
 {
     $params = $route->getParams();
     if (!is_numeric($params['apiversion'])) {
         $this->halt(400, 'Invalid API version');
     }
     $this->settings[self::SETTING_API_VERSION] = (int) $params['apiversion'];
     unset($params['apiversion']);
     $route->setParams($params);
 }