コード例 #1
0
 public function testRoutenameWouldbeResolveAsTemplateName()
 {
     $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/test'));
     $response = new Response();
     $dispatcher = new Dispatcher(call_user_func(function () {
         (yield '/test' => function () {
             return ['key' => 'var'];
         });
     }), $this->view, $this->stringRouter, $this->arrayRouter);
     $result = $dispatcher->dispatch($request, $response);
     $response = $result->getResponse();
     $this->assertInstanceof(ResponseInterface::class, $response);
     $this->assertSame('var', (string) $response->getBody());
 }
コード例 #2
0
<?php

use Backbeard\Dispatcher;
return (new Zend\ServiceManager\ServiceManager())->setService('Config', include 'parameters.php')->setFactory('application', function ($sm) {
    return function ($req, $res, $next) use($sm) {
        $routingFactory = $sm->get('routing-factory');
        $view = $sm->get('view');
        $stringRouter = $sm->get('string-router');
        $dispatcher = new Dispatcher($routingFactory($sm), $view, $stringRouter);
        $dispatchResult = $dispatcher->dispatch($req, $res);
        if ($dispatchResult->isDispatched() !== false) {
            return $dispatchResult->getResponse();
        }
        return $next($req, $res);
    };
})->setFactory('routing-factory', function ($sm) {
    return function ($sm) {
        (yield '/' => function () {
            return 'hello';
        });
    };
})->setFactory('view', function ($sm) {
    return new Backbeard\View\SfpStreamView(new SfpStreamView\View(getcwd() . '/views'));
})->setFactory('string-router', function ($sm) {
    return new Backbeard\Router\StringRouter(new \FastRoute\RouteParser\Std());
})->setFactory('ErrorHandler', function ($sm) {
    $displayErrors = $sm->get('Config')['env'] !== 'production';
    return new Application\ErrorHandler('views', $displayErrors);
});
コード例 #3
0
ファイル: DispatcherTest.php プロジェクト: sasezaki/backbeard
 public function testValidationThroughWhenNotMatchedRouting()
 {
     $request = ServerRequestFactory::fromGlobals(['REQUEST_METHOD' => 'GET'])->withUri(new Uri('/entry'));
     $response = new Response();
     $dispatcher = new Dispatcher(call_user_func(function () {
         $error = (yield function (ServerRequestInterface $request) {
             return $request->getMethod() === 'POST' && $request->getUri()->getPath() === '/entry';
         } => function () {
             return new ValidationError(['foo']);
         });
         (yield '/entry' => function () use($error) {
             return 'error is ' . gettype($error);
         });
     }), $this->view, $this->stringRouter, $this->arrayRouter);
     $result = $dispatcher->dispatch($request, $response);
     $response = $result->getResponse();
     $this->assertSame('error is NULL', (string) $response->getBody());
 }