This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Path segregation - pipeline middleware - config-driven #652
Copy link
Copy link
Open
Description
Good morning,
I've an expressive application with a config-driven pipeline. That application exposes different UI levels such as /admin, /reseller and /client, among others...
Right now, I've a specific pipeline middleware that I want to execute only for specific paths:
...
protected function getPipeline()
{
return [
[
'path' => '/admin',
'middleware' => \Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class
],
[
'path' => 'reseller',
'middleware' => \Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class
],
[
'path' => '/client',
'middleware' => \Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class
],
];
}
...
This is working but, I would rather be able to do something like this:
...
protected function getPipeline()
{
return [
[
'paths' => ['/admin', '/reseller', '/client'],
'middleware' => \Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class
],
}
}
...
Of course, I could use a custom delegator but I think this could be integrated in the default \Zend\Expressive\Container\ApplicationConfigInjectionDelegator
delegator as follows:
...
public static function injectPipelineFromConfig(Application $application, array $config) : void
{
if (empty($config['middleware_pipeline'])) {
return;
}
// Create a priority queue from the specifications
$queue = array_reduce(
array_map(self::createCollectionMapper(), $config['middleware_pipeline']),
self::createPriorityQueueReducer(),
new SplPriorityQueue()
);
foreach ($queue as $spec) {
$paths = $spec['path'] ?? ($spec['paths'] ?? '/');
foreach((array) $paths as $path) {
$application->pipe($path, $spec['middleware']);
}
}
}
...
instead of
....
public static function injectPipelineFromConfig(Application $application, array $config) : void
{
if (empty($config['middleware_pipeline'])) {
return;
}
// Create a priority queue from the specifications
$queue = array_reduce(
array_map(self::createCollectionMapper(), $config['middleware_pipeline']),
self::createPriorityQueueReducer(),
new SplPriorityQueue()
);
foreach ($queue as $spec) {
$path = $spec['path'] ?? '/';
$application->pipe($path, $spec['middleware']);
}
}
....
Thank you.
Metadata
Metadata
Assignees
Labels
No labels