Exemplo n.º 1
0
function wrapPipeline(array $request, array $routes, array $options)
{
    $match = Route\match($request, $routes);
    $routedHandler = null;
    $successful = false;
    switch ($match[0]) {
        case Route\NOT_FOUND:
            $routedHandler = [createStatusHandler(404)];
            break;
        case Route\METHOD_NOT_ALLOWED:
            $routedHandler = [createStatusHandler(405)];
            break;
        case Route\FOUND:
            $successful = true;
            $routedHandler = [$match[1]['callback']];
            break;
    }
    $pipeline = isset($options['pipeline']) ? $options['pipeline'] : [];
    $handlers = [$routedHandler];
    if (!$successful && isset($options['on_error'])) {
        $optional = [$options['on_error']];
        $handlers = array_merge($handlers, [$optional]);
    }
    return array_merge($pipeline, $handlers);
}
Exemplo n.º 2
0
 public function testMatchBasicNoMatch()
 {
     $request = $this->basicRequest;
     $request['uri'] = 'no-match';
     $result = Route\match($request, $this->basicRoutes);
     $this->assertNotNull($result);
     $this->assertEquals($result[0], Route\NOT_FOUND);
 }