I want to connect to different database according to URL. I try to set request attribute and get that attribute in *Factory.php
.
I edit autoload/pipeline.php
:
<?php
$app->pipe(UrlHelperMiddleware::class);
$app->pipe(\App\Action\Choose::class);
$app->pipeDispatchMiddleware();
in Choose.php
I implement process()
like this:
<?php
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
/** @var RouteResult $route */
$route = $request->getAttribute(RouteResult::class);
if ($route->getMatchedRouteName() == 'FirstRoute' or $route->getMatchedRouteName() == 'SecondRoute') {
$request = $request->withAttribute('DB_NAME', $route->getMatchedParams()['param']);
}
return $delegate->process($request);
}
The main problem is in *Factory.php
I don't access to request.
Any try to access to Interop\Http\ServerMiddleware\MiddlewareInterface
or Psr\Http\Message\ServerRequestInterface
in *Factory.php raises same error.
Is there any way pass parameter from pipeline middleware to factory class?