-
-
Save asgrim/8b11e249177595b6cc535a0fd94ce19d to your computer and use it in GitHub Desktop.
Simplified Mezzio Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "asgrim/mezzio-simplified", | |
"description": "Simplified Mezzio project", | |
"type": "project", | |
"require": { | |
"php": "^7.4", | |
"mezzio/mezzio": "^3.2", | |
"laminas/laminas-diactoros": "^2.3", | |
"laminas/laminas-servicemanager": "^3.4", | |
"mezzio/mezzio-fastroute": "^3.0" | |
}, | |
"license": "MIT" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @noinspection TransitiveDependenciesUsageInspection */ | |
declare(strict_types=1); | |
require __DIR__ . '/../vendor/autoload.php'; | |
use Laminas\Diactoros\Response; | |
use Laminas\Diactoros\Response\TextResponse; | |
use Laminas\Diactoros\ServerRequestFactory; | |
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; | |
use Laminas\HttpHandlerRunner\RequestHandlerRunner; | |
use Laminas\ServiceManager\ServiceManager; | |
use Laminas\Stratigility\MiddlewarePipe; | |
use Mezzio\Application; | |
use Mezzio\MiddlewareContainer; | |
use Mezzio\MiddlewareFactory; | |
use Mezzio\Response\ServerRequestErrorResponseGenerator; | |
use Mezzio\Router\FastRouteRouter; | |
use Mezzio\Router\Middleware\DispatchMiddleware; | |
use Mezzio\Router\Middleware\RouteMiddleware; | |
use Mezzio\Router\RouteCollector; | |
use Psr\Http\Message\ResponseInterface; | |
use Psr\Http\Message\ServerRequestInterface; | |
use Psr\Http\Server\RequestHandlerInterface; | |
$container = new ServiceManager(); | |
$router = new FastRouteRouter(); | |
$middlewarePipe = new MiddlewarePipe(); | |
$app = new Application( | |
new MiddlewareFactory(new MiddlewareContainer($container)), | |
$middlewarePipe, | |
new RouteCollector($router), | |
new RequestHandlerRunner( | |
$middlewarePipe, | |
new SapiEmitter(), | |
static function () { | |
return ServerRequestFactory::fromGlobals(); | |
}, | |
new ServerRequestErrorResponseGenerator( | |
static function () : Response { | |
return new Response(); | |
}, | |
true | |
) | |
) | |
); | |
$app->pipe(new RouteMiddleware($router)); | |
$app->pipe(new DispatchMiddleware()); | |
$app->get('/hello', new class implements RequestHandlerInterface { | |
public function handle(ServerRequestInterface $request): ResponseInterface | |
{ | |
return new TextResponse('hello world'); | |
} | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment