32 lines
586 B
PHP
32 lines
586 B
PHP
<?php
|
|
|
|
namespace Spark\Pipe\Filters;
|
|
|
|
class PhpFilter implements FilterInterface
|
|
{
|
|
private $method;
|
|
|
|
private array $args = [];
|
|
|
|
private static $defaultArgs = [
|
|
];
|
|
|
|
public function __construct(string|callable $method)
|
|
{
|
|
$this->method = $method;
|
|
}
|
|
|
|
public function setArguments(array $args)
|
|
{
|
|
$this->args = array_merge(self::$defaultArgs, $args);
|
|
}
|
|
|
|
public function pipe(?string $chunk)
|
|
{
|
|
if ($chunk === null) {
|
|
return;
|
|
}
|
|
return call_user_func($this->method, $chunk);
|
|
}
|
|
|
|
} |