Route option values should be retrievable from request attribute
weierophinney opened this issue · comments
- I was not able to find an open or closed issue matching what I'm seeing.
- This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
Provide a narrative description of what you are trying to accomplish.
Code to reproduce the issue
Given this route configuration
$app->post('/api/commands/register-user', [
\Prooph\ProophessorDo\Middleware\JsonPayload::class,
\Prooph\ProophessorDo\Middleware\JsonError::class,
\Prooph\HttpMiddleware\CommandMiddleware::class,
], 'command::register-user')
->setOptions([
'values' => [
'prooph_command_name' => \Prooph\ProophessorDo\Model\User\Command\RegisterUser::class,
],
]);
in \Prooph\HttpMiddleware\CommandMiddleware::class
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
$commandName = $request->getAttribute(self::NAME_ATTRIBUTE);
var_dump($commandName);
// null
Expected results
Route option values should set as request attribute
Actual results
Request attribute is not passed
This works with the aurarouter. Switching the router makes this bug appear.
ra/router 3.1.0 Powerful, flexible web routing for PSR-7 requests.
beberlei/assert v2.9.3 Thin assertion library for input validation in business models.
composer/semver 1.4.2 Semver library that offers utilities, version constraint parsing and validation.
container-interop/container-interop 1.2.0 Promoting the interoperability of container objects (DIC, SL, etc.)
doctrine/annotations v1.6.0 Docblock Annotations Parser
doctrine/cache v1.7.1 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.5.0 Collections Abstraction library
doctrine/common v2.8.1 Common Library for Doctrine projects
doctrine/dbal v2.6.3 Database Abstraction Layer
doctrine/inflector v1.3.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.1.0 A small, lightweight utility to instantiate objects in PHP without invoking their...
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
fig/http-message-util 1.1.2 Utility classes and constants for use with PSR-7 (psr/http-message)
filp/whoops 2.1.14 php error handling for cool kids
friendsofphp/php-cs-fixer v2.11.1 A tool to automatically fix PHP code style
guzzlehttp/guzzle 6.3.2 Guzzle is a PHP HTTP client library
guzzlehttp/promises v1.3.1 Guzzle promises library
guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides common utility methods
malukenho/docheader 0.1.7 A small library to check header docs
marc-mabe/php-enum v3.0.0 Simple and fast implementation of enumerations with native PHP>=5.6
myclabs/deep-copy 1.7.0 Create deep copies (clones) of your objects
nikic/fast-route v1.3.0 Fast request router for PHP
paragonie/random_compat v2.0.11 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest 1.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version 1.0.1 Library for handling version information and constraints
php-coveralls/php-coveralls v2.0.0 PHP client library for Coveralls API
php-cs-fixer/diff v1.3.0 sebastian/diff v2 backport support for PHP5.6
phpdocumentor/reflection-common 1.0.1 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock 4.3.0 With this component, a library can provide support for annotations via DocBlocks ...
phpdocumentor/type-resolver 0.4.0
phpspec/prophecy 1.7.5 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 5.3.0 Library that provides collection, processing, and rendering functionality for PHP...
phpunit/php-file-iterator 1.4.5 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 1.0.9 Utility class for timing
phpunit/php-token-stream 2.0.2 Wrapper around PHP's tokenizer extension.
phpunit/phpunit 6.5.7 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects 5.0.6 Mock Object library for PHPUnit
prooph/common v4.2.2 Common classes used across prooph packages
prooph/event-sourcing v5.3.0 PHP EventSourcing library
prooph/event-store v7.3.3 PHP EventStore Implementation
prooph/event-store-bus-bridge v3.1.0 Marry CQRS with Event Sourcing
prooph/event-store-http-middleware v0.2.0 PSR-15 EventStore HTTP Middleware
prooph/http-middleware v0.1.0 http middleware for prooph components
prooph/pdo-event-store v1.7.3 Prooph PDO EventStore
prooph/php-cs-fixer-config v0.2.1 PHP CS Fixer config for prooph components
prooph/service-bus v6.2.2 PHP Enterprise Service Bus Implementation supporting CQRS and DDD
proophsoftware/prooph-cli v0.2.0 prooph components command line tool for rapid development
psr/container 1.0.0 Common Container Interface (PHP FIG PSR-11)
psr/http-message 1.0.1 Common interface for HTTP messages
psr/http-server-handler 1.0.0 Common interface for HTTP server-side request handler
psr/http-server-middleware 1.0.0 Common interface for HTTP server-side middleware
psr/log 1.0.2 Common interface for logging libraries
ramsey/uuid 3.7.3 Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4...
react/promise v2.5.1 A lightweight implementation of CommonJS Promises/A for PHP
roave/security-advisories dev-master 4a272b6 Prevents installation of composer packages with known security vulnerabilities: n...
sandrokeil/interop-config 2.1.0 Provides interfaces and a concrete implementation to create instances depending o...
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
sebastian/comparator 2.1.3 Provides the functionality to compare PHP values for equality
sebastian/diff 2.0.1 Diff implementation
sebastian/environment 3.1.0 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 3.1.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state 2.0.0 Snapshotting of global state
sebastian/object-enumerator 3.0.3 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context 3.0.0 Provides functionality to recursively process PHP variables
sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP projects
symfony/config v4.0.6 Symfony Config Component
symfony/console v3.4.6 Symfony Console Component
symfony/debug v4.0.6 Symfony Debug Component
symfony/event-dispatcher v4.0.6 Symfony EventDispatcher Component
symfony/filesystem v4.0.6 Symfony Filesystem Component
symfony/finder v4.0.6 Symfony Finder Component
symfony/options-resolver v4.0.6 Symfony OptionsResolver Component
symfony/polyfill-mbstring v1.7.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php70 v1.7.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72 v1.7.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process v4.0.6 Symfony Process Component
symfony/stopwatch v4.0.6 Symfony Stopwatch Component
symfony/yaml v4.0.6 Symfony Yaml Component
theseer/tokenizer 1.1.0 A small library for converting tokenized PHP source code into XML and potentially...
webmozart/assert 1.3.0 Assertions to validate method input/output with nice error messages.
zendframework/zend-code 3.3.0 provides facilities to generate arbitrary code using an object oriented interface
zendframework/zend-config 3.1.0 provides a nested object property based user interface for accessing this configu...
zendframework/zend-config-aggregator 1.1.0 Lightweight library for collecting and merging configuration from different sources
zendframework/zend-diactoros 1.7.1 PSR HTTP Message implementations
zendframework/zend-escaper 2.5.2
zendframework/zend-eventmanager 3.2.0 Trigger and listen to events within a PHP application
zendframework/zend-expressive 3.0.1 PSR-15 Middleware Microframework
zendframework/zend-expressive-fastroute 3.0.1 FastRoute integration for Expressive
zendframework/zend-expressive-helpers 5.0.0 Helper/Utility classes for Expressive
zendframework/zend-expressive-router 3.0.2 Router subcomponent for Expressive
zendframework/zend-expressive-template 2.0.0 Template subcomponent for Expressive
zendframework/zend-expressive-zendviewrenderer 2.0.0 zend-view PhpRenderer integration for Expressive
zendframework/zend-filter 2.7.2 provides a set of commonly needed data filters
zendframework/zend-httphandlerrunner 1.0.1 Execute PSR-15 RequestHandlerInterface instances and emit responses they generate.
zendframework/zend-loader 2.5.1
zendframework/zend-mail 2.9.0 provides generalized functionality to compose and send both text and MIME-complia...
zendframework/zend-mime 2.7.0 Create and parse MIME messages and parts
zendframework/zend-servicemanager 3.3.2 Factory-Driven Dependency Injection Container
zendframework/zend-stdlib 3.1.0
zendframework/zend-stratigility 3.0.0 PSR-7 middleware foundation for building and dispatching middleware pipelines
zendframework/zend-validator 2.10.2 provides a set of commonly needed validators
zendframework/zend-view 2.10.0 provides a system of helpers, output filters, and variable escaping
zfcampus/zf-development-mode 3.1.0 Zend Framework development mode script
Originally posted by @basz at zendframework/zend-expressive-fastroute#58
There are differences between Aura router and FastRoute. I guess the options values are not passed as request attributes like in Aura router. I need to dig into the code but I think this is something specifically for Aura router. If I remember correctly, this is the exact reason that Prooph has chosen Aura router.
Something like this does work for me with FastRoute and should work with other routers as well:
$routeResult = $request->getAttribute(\Zend\Expressive\Router\RouteResult::class, false);
$matchedRoute = $routeResult->getMatchedRoute();
$matchedRoute->getOptions()['values']['prooph_command_name'];
Originally posted by @geerteltink at zendframework/zend-expressive-fastroute#58 (comment)
Ah, then I would expect prooph to also support this in their Handler
Originally posted by @basz at zendframework/zend-expressive-fastroute#58 (comment)