Contenu connexe Similaire à Zend\Expressive - höher, schneller, weiter (20) Zend\Expressive - höher, schneller, weiter3. 3
1 PSR-7 / Middleware
2
Middleware für Aktionen3
ZendExpressive Überblick
Middleware für die Pipeline4
Und was ist mit Tee MVC?5
7. 7
<?php
namespace PsrHttpMessage;
interface MessageInterface
{
public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body);
}
PSR-7
MESSAGEINTERFACE
20. 20
ROUTER DI CONTAINER TEMPLATE
RENDERER
ERROR
HANDLER
Aura.Router
FastRoute
ZendRouter
Weitere Router
Aura.DI
Pimpleinterop
Zend
ServiceManager
Weitere
DI Container
Plates
Twig
ZendView
Weitere
TemplateEngine
Whoops
Weiterer
ErrorHandler
ZENDEXPRESSIVE
ZUTATEN
21. 21
PERFORMANCE
MESSDATEN
Gemessen im April 2016 mit der ZendExpressive Skeleton 1.0.1
AD = Aura.DI, AR = Aura.Router, FR = FastRoute, ZR = ZendRouter, ZS = ZendServiceManager, ZV = ZendView
Laufzeit (ms) 31,8 106,5 43,8 31,9 103,8 44,9 42,7 117,2 56,1 35,6 31,3
Router FR FR FR AR AR AR ZR ZR ZR FR FR
DI Container ZS ZS ZS ZS ZS ZS ZS ZS ZS AD Pimple
Renderer Plates Twig ZV Plates Twig ZV Plates Twig ZV Plates Plates
23. 23
PERFORMANCE
FAZIT
AD = Aura.DI, AR = Aura.Router, FR = FastRoute, ZR = ZendRouter, ZS = ZendServiceManager, ZV = ZendView
FR
SCHNELLSTE
VARIANTE
PlatesPimple
PS: Traue keiner Statistik, die du nicht selber gefälscht hast! ;)
ZR
REINE ZF
VARIANTE
ZVZS
26. 26
VERZEICHNISSTRUKTUR
config
autoload
data
cache
public
src
Application
Action
templates
application
error
layout
test
ApplicationTest
Action
vendor
composer.json
config
autoload
data
cache
modules
Application
config
src
Action
templates
application
error
layout
test
Action
public
vendor
composer.json
MODULAR
EINFACH
27. 27
CONFIGMANAGER
$ composer require mtymek/expressive-config-manager
<?php
// Datei /config/config.php
use ZendExpressiveConfigManagerConfigManager;
use ZendExpressiveConfigManagerPhpFileProvider;
$configManager = new ConfigManager([
ApplicationConfigProvider::class,
new PhpFileProvider(
'config/autoload/{{,*.}global,{,*.}local}.php'
),
]);
return new ArrayObject(
$configManager->getMergedConfig()
);
29. 29
COMPONENT
INSTALLER
$ composer require ⏎
zendframework/zend-component-installer
$ composer require zendframework/zend-db
<?php
// Datei /config/config.php
use ZendExpressiveConfigManagerConfigManager;
use ZendExpressiveConfigManagerPhpFileProvider;
$configManager = new ConfigManager([
ZendDbConfigProvider::class,
ApplicationConfigProvider::class,
new PhpFileProvider(
'config/autoload/{{,*.}global,{,*.}local}.php'
),
]);
return new ArrayObject(
$configManager->getMergedConfig()
);
34. 34
ZENDVIEW
TEMPLATE
<?php foreach ($this->pizzas as $pizza) : ?>
<?php
$urlShow = $this->url(
'pizza-show', ['id' => $pizza['id']]
);
?>
<div class="col-md-4">
<div class="thumbnail text-center">
<a href="<?= $urlShow; ?>">
<img src="<?= $pizza['image'] ?>"
title="<?= $pizza['name'] ?>">
</a>
</div>
</div>
<?php endforeach ?>
35. 35
return [
'routes' => [
[
'name' => 'pizza-intro',
'path' => '/pizza',
'middleware' =>
PizzaActionShowIntroAction::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'pizza-handle-delete',
'path' => '/pizza/delete/:id',
'middleware' =>
PizzaActionDeletePizzaAction::class,
'allowed_methods' => ['POST'],
'options' => [
'constraints' => [
'id' => '[1-9][0-9]*',
],
],
],
],
];
ZENDROUTER
ROUTING
36. 36
namespace PizzaRestAction;
class GetIdAction
{
use PizzaRepositoryAwareTrait;
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null
) {
$pizza = $this->pizzaRepository->getSinglePizza(
$request->getAttribute('id')
);
if (!$pizza) {
return new JsonResponse(
['err' => 'Not found']
);
}
return new JsonResponse($pizza);
}
}
RESTAKTION
40. 40
use ZendExpressiveContainerApplicationFactory;
use ZendExpressiveHelper;
return [
'middleware_pipeline' => [
'always' => [
'middleware' => [
HelperServerUrlMiddleware::class,
],
'priority' => 10000,
],
'routing' => [
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
HelperUrlHelperMiddleware::class,
ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [],
'error' => true,
'priority' => -10000,
],
],
];
DEFAULT
KONFIGURATION
41. 41
use I18nMiddlewareLocalizationMiddleware;
use UserAuthorizationAuthenticationMiddleware;
use UserAuthorizationAuthorizationMiddleware;
use ZendExpressiveContainerApplicationFactory;
use ZendExpressiveHelper;
return [
'middleware_pipeline' => [
'always' => [ /* ... */ ],
'routing' => [
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
HelperUrlHelperMiddleware::class,
LocalizationMiddleware::class,
AuthenticationMiddleware::class,
AuthorizationMiddleware::class,
ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [ /* ... */ ],
],
];
KOMPLEXERE
KONFIGURATION
42. 42
namespace UserAuthorization;
class AuthorizationMiddleware
{
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next
) {
$permission = $result->getMatchedRouteName();
if (!$this->rbac->isGranted($this->role, $permission)) {
if ($this->role == GuestRole::NAME) {
throw new RuntimeException(
'Nicht angemeldet', 401
);
} else {
throw new RuntimeException('Kein Zugriff', 403);
}
}
return $next($request, $response);
}
}
AUTHORIZATION
MIDDLEWARE
50. 50
1
Digging In
von Zach Dischner
Flickr CC BY 2.0 5
Pipes
von Leonid Mamchenkov
Flickr CC BY 2.0
17
Monument valley
von Moyan Brenn
Flickr CC BY 2.0
30
»and... action«
von Latin Snake
Flickr CC BY 2.0
44
Und was ist mit Tee?
aus der Giotto Werbung
YouTube
37
Pipeline
von jasonwoodhead23
Flickr CC BY 2.0
4
A flowery meadow
von Michael Figiel
Flickr CC BY 2.0
BILDNACHWEIS
49
free high res texture 380
von Caleb Kimbrough
Flickr CC BY 2.0