-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipelineFactory.php
39 lines (34 loc) · 1.22 KB
/
PipelineFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Bermuda\Pipeline;
use Psr\Container\ContainerInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
/**
* Class PipelineFactory
* @package Bermuda\Pipeline
*/
class PipelineFactory implements PipelineFactoryInterface
{
public const containerMiddlewareId = '\Bermuda\Pipeline\PipelineFactory@middlewareId';
public const containerFallbackHandlerId = '\Bermuda\Pipeline\PipelineFactory@fallbackHandlerId';
/**
* @param ContainerInterface $container
* @return Pipeline
*/
public function __invoke(ContainerInterface $container): PipelineInterface
{
return $this->make(
$container->has(self::containerMiddlewareId) ?
$container->get(self::containerMiddlewareId) : null,
$container->has(self::containerFallbackHandlerId) ?
$container->get(self::containerFallbackHandlerId) : null
);
}
/**
* @inheritDoc
*/
public function make(?iterable $middleware = [], ?RequestHandlerInterface $fallbackHandler = null): PipelineInterface
{
return !empty($middleware) ? Pipeline::makeOf($middleware, $fallbackHandler) : new Pipeline($fallbackHandler);
}
}