Ejemplo n.º 1
0
 /**
  * Match if current Route match to the request url, method and type
  *
  * @param Route $route
  * @return bool
  */
 private function match(Route $route)
 {
     if (!in_array($this->routeRequest->getRequestMethod(), $route->getMethods())) {
         return false;
     }
     if (!$this->routeRequest->isAjax() && 'ajax' == $route->getType()) {
         return false;
     }
     if (!preg_match($route->getPattern(), $this->routeRequest->getRequestUrl())) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function shouldUseMethodOverwrite()
 {
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'DELETE';
     $request = new RouteRequest();
     $this->assertEquals('DELETE', $request->getRequestMethod());
 }
Ejemplo n.º 3
0
    ini_set('memory_limit', $config->read('memory_limit'));
    if (empty($_POST['name']) || false === $libraryService->validatePackage($_POST['name'])) {
        echo json_encode(['status' => 'error', 'message' => 'Wrong package name or package doesn\'t exist.']);
        return;
    }
    try {
        $libraryService->addPackage($_POST['name']);
        echo json_encode(['status' => 'success']);
    } catch (SnippetException $e) {
        echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
    }
}));
/**
 * Get available php versions
 */
$routing->attach(new Route('GET  /get_php_versions.json [ajax]', function () use($config) {
    $phpPaths = $config->read('php_commands');
    $versions = empty($phpPaths) ? [] : array_keys($phpPaths);
    echo json_encode(compact('versions'));
}));
try {
    $request = new RouteRequest();
    (new Router($request, $routing))->run();
} catch (RouteNotFoundException $e) {
    header("HTTP/1.0 404 Not Found");
    if (true === $request->isAjax()) {
        echo json_encode(['error' => 'Not Found']);
    } else {
        echo "<h1>404. Not Found.</h1>";
    }
}