Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - Add Possibility For Custom RequestHandler Invocation Strategies #2774

Merged
merged 5 commits into from Aug 4, 2019

Conversation

@l0gicgate
Copy link
Contributor

commented Aug 4, 2019

This effectively closes #2772 and #2773

Added a new interface for invocation strategies that can handle request handlers:

  • RequestHandlerInvocationStrategyInterface

The current RequestHandler strategy now implements that interface which enables to check within the Route::run() method that the user set strategy can handle request handlers. In the event that it doesn't, a new RequestHandler strategy is instantiated.

Also added feature to the existing RequestHandler strategy (requested in #2772/#2773) to append route arguments as attributes to the incoming request object. By default it is set to false. If you want to enable this feature:

To enable the feature for all the routes:

use Slim\Factory\AppFactory;
use Slim\Handlers\Strategies\RequestHandler;

$app = AppFactory::create();

/**
  * The RequestHandler constructor now takes an argument
  * Setting it to true will enable appending the route arguments as attributes to the request
  * @param bool $appendRouteArgumentsToRequestAttributes
 */
$strategy = new RequestHandler(true);
$app->getRouteCollectorProxy()->setDefaultInvocationStrategy($strategy);

To enable the feature on a per route basis:

use Slim\Factory\AppFactory;
use Slim\Handlers\Strategies\RequestHandler;

$app = AppFactory::create();

/**
  * The RequestHandler constructor now takes an argument
  * Setting it to true will enable appending the route arguments as attributes to the request
  * @param bool $appendRouteArgumentsToRequestAttributes
 */
$strategy = new RequestHandler(true);

$route = $app->get(...);
$route->setInvocationStrategy($strategy);
@coveralls

This comment has been minimized.

Copy link

commented Aug 4, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling c9ce864 on l0gicgate:FixInvocationStrategy into 84c96a3 on slimphp:4.x.

@l0gicgate l0gicgate requested a review from adriansuter Aug 4, 2019

@l0gicgate l0gicgate merged commit 6b4f467 into slimphp:4.x Aug 4, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 100.0%
Details

@l0gicgate l0gicgate referenced this pull request Aug 6, 2019

Merged

4.1 - Release #2782

@l0gicgate l0gicgate deleted the l0gicgate:FixInvocationStrategy branch Aug 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.