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
Member

@l0gicgate l0gicgate 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
Copy link

@coveralls coveralls 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
@l0gicgate l0gicgate mentioned this pull request Aug 6, 2019
@l0gicgate l0gicgate deleted the FixInvocationStrategy branch Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants