Compare commits
3 Commits
52ae66976a
...
6aa311b35d
Author | SHA1 | Date |
---|---|---|
Adrian | 6aa311b35d | |
Adrian | 3cbbc0cf24 | |
Adrian | e3b16644dd |
|
@ -7,6 +7,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"xtreamwayz/pimple-container-interop": "^1.0",
|
"xtreamwayz/pimple-container-interop": "^1.0",
|
||||||
"zendframework/zend-expressive": "^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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?php return [
|
|
||||||
'middleware_pipeline' => [
|
|
||||||
Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE,
|
|
||||||
Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
|
|
||||||
],
|
|
||||||
'routes' => [
|
|
||||||
[
|
|
||||||
'path' => '/',
|
|
||||||
'middleware' => new Test\App\HomeAction,
|
|
||||||
'allowed_methods' => [ 'GET' ],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php return new ArrayObject([
|
||||||
|
'middleware_pipeline' => [
|
||||||
|
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',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Test\App\HomeAction;
|
||||||
|
use Test\App\HomeFactory;
|
||||||
|
use Xtreamwayz\Pimple\Container;
|
||||||
|
use Zend\Expressive\Application;
|
||||||
|
use Zend\Expressive\Container\ApplicationFactory;
|
||||||
|
use Zend\Expressive\Helper\UrlHelper;
|
||||||
|
use Zend\Expressive\Helper\UrlHelperFactory;
|
||||||
|
use Zend\Expressive\Helper\UrlHelperMiddleware;
|
||||||
|
use Zend\Expressive\Helper\UrlHelperMiddlewareFactory;
|
||||||
|
use Zend\Expressive\Router\FastRouteRouter;
|
||||||
|
use Zend\Expressive\Router\RouterInterface;
|
||||||
|
|
||||||
|
$c = new Container;
|
||||||
|
|
||||||
|
$c['config'] = require 'config/config.php';
|
||||||
|
|
||||||
|
$c[RouterInterface::class] = function () { return new FastRouteRouter; };
|
||||||
|
$c[UrlHelper::class] = new UrlHelperFactory;
|
||||||
|
$c[UrlHelperMiddleware::class] = new UrlHelperMiddlewareFactory;
|
||||||
|
$c[HomeAction::class] = new HomeFactory;
|
||||||
|
$c[Application::class] = new ApplicationFactory;
|
||||||
|
|
||||||
|
return $c;
|
|
@ -1,18 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Xtreamwayz\Pimple\Container;
|
|
||||||
use Zend\Expressive\Application;
|
use Zend\Expressive\Application;
|
||||||
use Zend\Expressive\Container\ApplicationFactory;
|
|
||||||
|
|
||||||
chdir(dirname(__DIR__));
|
chdir(dirname(__DIR__));
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
$c = new Container;
|
$c = require 'config/container.php';
|
||||||
|
|
||||||
$c['config'] = new ArrayObject(require 'config/autoload/full.global.php');
|
$app = $c->get(Application::class);
|
||||||
|
|
||||||
$c[Application::class] = new ApplicationFactory;
|
|
||||||
|
|
||||||
$app = $c[Application::class];
|
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
@ -4,11 +4,20 @@ namespace Test\App;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
use Zend\Expressive\Helper\UrlHelper;
|
||||||
|
|
||||||
class HomeAction
|
class HomeAction
|
||||||
{
|
{
|
||||||
|
private $urlhelper;
|
||||||
|
|
||||||
|
public function __construct(UrlHelper $urlhelper)
|
||||||
|
{
|
||||||
|
$this->urlhelper = $urlhelper;
|
||||||
|
}
|
||||||
|
|
||||||
public function __invoke(Request $req, Response $res, callable $next)
|
public function __invoke(Request $req, Response $res, callable $next)
|
||||||
{
|
{
|
||||||
$res->getBody()->write("Hello World!");
|
$result = sprintf("Hello World!<br/>\n%s", var_export($this->urlhelper->generate('other'), true));
|
||||||
|
$res->getBody()->write($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\App;
|
||||||
|
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
use Zend\Expressive\Helper\UrlHelper;
|
||||||
|
|
||||||
|
class HomeFactory
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $c)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$urlhelper = $c->get(UrlHelper::class);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
trigger_error("Ex: $e");
|
||||||
|
}
|
||||||
|
return new HomeAction($urlhelper);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue