Exemple #1
0
 public function testRunBasicMatchNoMethod()
 {
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $result = App\run($this->basicRoutes, ['on_error' => function ($conn) {
         $conn['response']['body'] = 'errored';
         return $conn;
     }]);
     $this->assertNotNull($result);
     $this->assertEquals($result['response']['status'], 405);
     $this->assertEquals($result['response']['body'], 'errored');
 }
Exemple #2
0
<?php

require '../vendor/autoload.php';
use FPWeb\App;
use FPWeb\Route;
// index handler
$index = function ($conn) {
    // TODO: make this process nicer
    $conn['response']['body'] = 'index';
    return $conn;
};
// create routes
$routes = [Route\get('/index', $index)];
// match request and run match
$response = App\run($routes, ['param_set' => [$_GET, $_POST], 'on_error' => function ($conn) {
    $conn['response']['body'] = 'Not Found';
    return $conn;
}]);
printf('<pre><code>%s</code></pre>', print_r($response, true));