diff --git a/composer.json b/composer.json index b518a01..c2f3f31 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "xtreamwayz/pimple-container-interop": "^1.0", "zendframework/zend-expressive": "^1.0", - "zendframework/zend-expressive-fastroute": "^1.2" + "zendframework/zend-expressive-fastroute": "^1.2", + "zendframework/zend-expressive-helpers": "^2.1" } } diff --git a/config/autoload/full.global.php b/config/autoload/full.global.php deleted file mode 100644 index 00c071f..0000000 --- a/config/autoload/full.global.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE, - Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE, - ], - 'routes' => [ - [ - 'path' => '/', - 'middleware' => new Test\App\HomeAction, - 'allowed_methods' => [ 'GET' ], - ], - ], -]; diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..754627a --- /dev/null +++ b/config/config.php @@ -0,0 +1,21 @@ + [ + Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE, + ['middleware' => Zend\Expressive\Helper\UrlHelperMiddleware::class], + Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE, + ], + 'routes' => [ + [ + 'path' => '/', + 'middleware' => Test\App\HomeAction::class, + 'allowed_methods' => [ 'GET' ], + 'name' => 'home', + ], + [ + 'path' => '/test/another/path', + 'middleware' => Test\App\HomeAction::class, + 'allowed_methods' => [ 'GET' ], + 'name' => 'other', + ], + ], +]); diff --git a/config/container.php b/config/container.php new file mode 100644 index 0000000..c516330 --- /dev/null +++ b/config/container.php @@ -0,0 +1,25 @@ +get(Application::class); $app->run(); diff --git a/src/App/HomeAction.php b/src/App/HomeAction.php index 7b8e0a8..4e12097 100644 --- a/src/App/HomeAction.php +++ b/src/App/HomeAction.php @@ -4,11 +4,20 @@ namespace Test\App; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Expressive\Helper\UrlHelper; class HomeAction { + private $urlhelper; + + public function __construct(UrlHelper $urlhelper) + { + $this->urlhelper = $urlhelper; + } + public function __invoke(Request $req, Response $res, callable $next) { - $res->getBody()->write("Hello World!"); + $result = sprintf("Hello World!
\n%s", var_export($this->urlhelper->generate('other'), true)); + $res->getBody()->write($result); } } diff --git a/src/App/HomeFactory.php b/src/App/HomeFactory.php new file mode 100644 index 0000000..33ea90e --- /dev/null +++ b/src/App/HomeFactory.php @@ -0,0 +1,19 @@ +get(UrlHelper::class); + } catch (\Exception $e) { + trigger_error("Ex: $e"); + } + return new HomeAction($urlhelper); + } +}