* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class FilterChain implements FilterChainInterface, LoggerAwareInterface { /** @var array */ protected $filters; /** @var \PSX\Http\FilterChainInterface */ protected $filterChain; /** @var \Psr\Log\LoggerInterface */ protected $logger; /** * @param array|\Traversable $filters * @param FilterChainInterface|null $filterChain */ public function __construct($filters = [], FilterChainInterface $filterChain = null) { $this->filters = []; $this->filterChain = $filterChain; foreach ($filters as $filter) { $this->on($filter); } } /** * @inheritdoc */ public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } /** * @inheritdoc */ public function on($filter) { if ($filter instanceof FilterInterface) { $this->filters[] = $filter; } elseif ($filter instanceof \Closure) { $this->filters[] = $filter; } elseif (is_callable($filter)) { $this->filters[] = $filter; } else { throw new \InvalidArgumentException('Invalid filter must be either a \Closure or ' . FilterInterface::class); } } /** * @inheritdoc */ public function handle(RequestInterface $request, ResponseInterface $response) { $filter = array_shift($this->filters); if ($filter === null) { // if we have no filters check whether we have a parent filter chain // which should be called next if ($this->filterChain !== null) { $this->filterChain->handle($request, $response); } } elseif ($filter instanceof FilterInterface) { if ($this->logger !== null) { $this->logger->info('Filter execute ' . get_class($filter)); } $filter->handle($request, $response, $this); } elseif ($filter instanceof \Closure) { $filter($request, $response, $this); } elseif (is_callable($filter)) { call_user_func_array($filter, array($request, $response, $this)); } else { throw new \RuntimeException('Invalid filter value'); } } } __halt_compiler();----SIGNATURE:----hIWVRKv54nlPnj7gIAPNXSqS2+MGxHH9y2b089dLqixjvZ2ctDiVRI1/6eo3l5BKzg/lMKh+fW5qhM8HgpE76o30RzDH/+OofH8YerAe9kmKj4uUQKG9cnmrddHPL7IXguFuA5g0BsHl/wOeEMTWdAVb5XD4tigS9ZE08Bii/NX3vDybgQLC++SVflPMz5r2IOd3q0RqHaFSNyVodhARbjPDBQwwCGATDjhStp6wL0n0NRIAzI6xE8lRbkRCtGl0BZ0klO9KXfz2VjoFPGx7gUrIkAW+krtG2og5MkKg6KMkxIZIF+3VX0yBCGf3Q9dS/ksMYlIeeQrrhXJNNIqimLgJBwvE5jLcnWqBoh9NUWgfhLCTCK84oPbZoFl5yxRQ3P6h/X6mdV/Q/9qSpkbZi//bMueuXl+pk6MvhdijJTKlSY4OUghhc3Q9ouQvXID3hYLLuOGJUiJRWYGdiAriBTJ8ZZgHmqXtiUdsEA0Fpmwy+DceHQb4HnSKOevas6JTxUTdlHn1iEoLTihtiB+yqDsJ3c0WLqKCHn7BAw5T9QEFPuESTkIvE9sUCcCjVTVqkKbbLeVnuDl2hGsoyQmi4jxILX3qsmpgMrd4VRWrvHC0RMuhkUxIAO1BB+mkVabuSOvi4PF2IHbvbOOtB/NU2aeFrS67Zj0itRGrKCoi/lE=----ATTACHMENT:----MjE1MjA3MDQwNDEyNjc4NyAyMDE0NDI0ODcxMDQ4Mzk5IDIwNzEwMTM1MDA1NzE5NTQ=