Open Mondane opened 6 years ago
After some digging around, I came up with this:
A factory to create a 'FoundPipe':
<?php
declare(strict_types = 1);
namespace App\Container\Middleware;
use Psr\Container\ContainerInterface;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Expressive\MiddlewareFactory;
use ExpressivePrismic\Middleware;
class FoundPipeFactory
{
public function __invoke(ContainerInterface $container) : MiddlewarePipe
{
$factory = $container->get(MiddlewareFactory::class);
$pipeline = new MiddlewarePipe;
$pipeline->pipe($factory->prepare(Middleware\InjectPreviewScript::class));
$pipeline->pipe($factory->prepare(Middleware\ExperimentInitiator::class));
$pipeline->pipe($factory->prepare(Middleware\DocumentResolver::class));
$pipeline->pipe($factory->prepare(Middleware\PrismicTemplate::class));
return $pipeline;
}
}
The 'FoundPipe':
<?php
declare(strict_types=1);
namespace App\Middleware;
use Zend\Stratigility\MiddlewarePipeInterface;
interface FoundPipe extends MiddlewarePipeInterface
{
}
A pipe to provide in this library?
Hi @Mondane, your example of a 'Found Pipeline' is exactly what I do. Most content driven routes will normally use a very similar pipeline, so I'll set up a interface to target and create a factory for it. The reason the library doesn't include a default pipeline for any given project is because there are limitless ways in which you might want to process a request before finally rendering an HTML response - it made more sense to me to leave it out. It's probably a good idea to put this in the docs perhaps with an example.
Sorry it took a while to get back to you ;)
Could you provide an example which middleWare to instantiate in the route config?
After some searching, I came up with
But I'm not sure if this is correct.