Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Middleware in TYPO3

Slide 3

Slide 3 text

Daniel Möbius CMS-Developer

Slide 4

Slide 4 text

Agenda Bisherige Möglichkeiten Middlware Live-Demo TypeNum eID PSR-7 PSR-15 Konfiguration Frontend-Entries Backend-Entries Service Zielstellung

Slide 5

Slide 5 text

Zielstellung

Slide 6

Slide 6 text

Zielstellung • Schnittstellen • Response-Manipulation • … Anforderungen

Slide 7

Slide 7 text

Möglichkeiten

Slide 8

Slide 8 text

Möglichkeiten abstract class AbstractApiController extends ActionController { /**@var \TYPO3\CMS\Extbase\Mvc\View\JsonView*/ protected $view; /**@var string*/ protected $resourceArgumentName; /**@var RepositoryInterface*/ protected $resourceRepository; /**@var Web\Request*/ protected $request; /** * AbstractApiController constructor. */ public function __construct() { parent::__construct(); $this->defaultViewObjectName = JsonView::class; } Page-Type

Slide 9

Slide 9 text

Möglichkeiten protected function resolveActionMethodName() { parent::resolveActionMethodName(); $actionName = ‚'; switch ($this->request->getMethod()) { case 'POST': $actionName = 'create'; if( $this->request->hasArgument('method') && $this->request ->getArgument(‚method') === ‚edit' ){ $actionName= 'update'; } break; default: $this->throwStatus(400, null, 'Bad Request.'); } return $actionName . ‚Action'; } Page-Type

Slide 10

Slide 10 text

Möglichkeiten api = PAGE api { typeNum = 9000 config { disableAllHeaderCode = 1 debug = 0 no_cache = 1 additionalHeaders { 10 { header = Content-Type: application/json replace = 1 } } } 10 < tt_content.list.20.dmtodos_tds } Page-Type

Slide 11

Slide 11 text

Möglichkeiten $GLOBALS[‚TYPO3_CONF_VARS']['FE']['eID_include']['ServiceCenter'] = ‚EXT:service_center/Classes/Eid/ServiceCenterEid.php‘; eID

Slide 12

Slide 12 text

Möglichkeiten main(); eID

Slide 13

Slide 13 text

Middleware

Slide 14

Slide 14 text

Middleware PSR-7 HTTP/1.1 200 OK Content-Type: text/plain This is the response body Psr\Http\Message\RequestInterface Psr\Http\Message\ResponseInterface $message = $message ->withHeader('foo', 'bar') ->withAddedHeader('foo', 'baz'); $header = $message->getHeaderLine('foo'); // $header contains: 'bar,baz' $header = $message->getHeader('foo'); // ['bar', 'baz']

Slide 15

Slide 15 text

Middleware Middleware Middleware App Request Response PSR-15

Slide 16

Slide 16 text

Middleware PSR-15 namespace Psr\Http\Server; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; /** * Participant in processing a server request and response. * * An HTTP middleware component participates in processing an HTTP message: * by acting on the request, generating the response, or forwarding the * request to a subsequent middleware and possibly acting on its response. */ interface MiddlewareInterface { /** * Process an incoming server request. * * Processes an incoming server request in order to produce a response. * If unable to produce the response itself, it may delegate to the provided * request handler to do so. */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface; }

Slide 17

Slide 17 text

Middleware TYPO3-Konfiguration [ 'identifier' => [ 'target' => \Vendor\Extension\Middleware\Service::class, 'before' => [ 'typo3/cms-frontend/eid' ], ], ], 'backend' => [ 'identifier' => [ 'target' => \Vendor\Extension\Middleware\Service::class, 'after' => [ 'typo3/cms-backend/authentication' ] ], ], ];

Slide 18

Slide 18 text

Middleware TYPO3-Konfiguration [ 'identifier' => [ 'disabled' => true ] ];

Slide 19

Slide 19 text

Middleware Frontend-Entries

Slide 20

Slide 20 text

Middleware Backend-Entries

Slide 21

Slide 21 text

Middleware Service handle($request); … return new HtmlResponse($content, $statusCode, $header); } }

Slide 22

Slide 22 text

Live-Demo

Slide 23

Slide 23 text

Fazit

Slide 24

Slide 24 text

Danke! GitHub: https://github.com/danmoebius E-Mail: [email protected]