Beispiel #1
0
 /**
  * @param Request $request
  * @return bool
  */
 public function match(Request $request)
 {
     $pattern = $request->getRelativeUri();
     return $this->matchesPattern($pattern, $request->getRequestMethod());
 }
Beispiel #2
0
 /**
  * @param Request $request
  * @return bool
  */
 public function match(Request $request)
 {
     $regex = "@" . self::ADMIN_PATTERN . "@";
     return (bool) preg_match($regex, $request->getRelativeUri());
 }
Beispiel #3
0
 /**
  * @param Request $request
  * @return bool
  */
 public function match(Request $request)
 {
     return $this->matchesPattern($request->getRelativeUri());
 }
Beispiel #4
0
 */
use Wrr\JsonResponse;
use Wrr\Router;
use Wrr\DefaultRoute;
use Wrr\DefaultResponse;
require_once __DIR__ . '/../../../vendor/autoload.php';
/*
 * make a wildcard route that covers everything and will result in a sane default
 */
$router = new Router();
$router->registerRoute(new DefaultRoute('^/', function () {
    return "Wrr!... You've been served! ";
}));
// catch all
include_once 'RestController.php';
$controller = new RestController($router, \Wrr\Request::populateFromGlobals());
$jsonResponse = new JsonResponse();
$router->registerRoute(new \Wrr\RestRoute('rest', function () use($controller) {
    return $controller->dispatch();
}, "GET", $jsonResponse));
$defaultResponse = new DefaultResponse();
$router->registerRoute(new \Wrr\RestRoute('rest', function () {
    return array("Brocks status", "Brock is Cool!");
}, "POST", $jsonResponse));
try {
    $response = $router->setRequest(\Wrr\Request::populateFromGlobals())->route();
    $response->addHeader('X-Meta: Response Built by Wrr!')->deliverPayload();
} catch (Exception $e) {
    $response = new \Wrr\DefaultResponse();
    $response->addBodyFragment($e->getMessage())->setResponseCode($e->getCode() ? $e->getCode() : 500)->deliverPayLoad();
}