k9u / request-mapper
Annotatable Request Mapper library for PHP
0.13.0
2020-08-03 22:14 UTC
Requires
- php: ^7.4
- doctrine/annotations: ^1.10
- psr/http-message: ^1.0
- symfony/config: ^5.1
- symfony/routing: ^5.1
Requires (Dev)
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.2
- squizlabs/php_codesniffer: ^3.5
- dev-master
- 0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-dependabot/composer/symfony/routing-tw-5.3
- dev-dependabot/composer/symfony/config-tw-5.3
- dev-dependabot/composer/doctrine/annotations-tw-1.13
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/phpmd/phpmd-tw-2.10
- dev-dependabot/composer/squizlabs/php_codesniffer-tw-3.6
This package is auto-updated.
Last update: 2024-11-29 06:22:04 UTC
README
Annotatable Request Mapper library for PHP.
Usage
use K9u\RequestMapper\Annotation\GetMapping; use My\App\Presentation\Blog; class BlogController { /** * @GetMapping("/blogs/{id}") */ public function show($id) { // snip(find blog by $id) $blog = [ 'id' => $id, 'title' => 'Hello world!', ... ]; return $blog; } }
use K9u\RequestMapper; $request = $serverRequestFactory->createServerRequest('GET', 'http://example.com/blogs/1', $_SERVER); $handlerResolver = new HandlerResolver('/path/to/src/Presentation'); $handler = $handlerResolver($request); // $handler->class = 'My\App\Presentation\Blog\BlogController' // $handler->method = 'show' // $handler->pathParams = ['id' => '1'] $handlerClassFactory = ...; /* @var HandlerClassFactoryInterface $handlerClassFactory */ $handlerMethodArgumentsResolver = ...; /* @var HandlerMethodArgumentsResolverInterface $handlerMethodArgumentsResolver */ $handlerInvoker = new HandlerInvoker($handlerClassFactory, $handlerMethodArgumentsResolver); $result = $handlerInvoker($handler, $request); var_export($result); // array ( // 'id' => 1, // 'title' => 'Hello world!', // ... // )