Pipe improvements, misc cleanup
* Pipe improvements; better filter code, pipeline etc. * Moved commands in PDO plugin to dedicated namespace
This commit is contained in:
		@@ -2,6 +2,8 @@
 | 
			
		||||
 | 
			
		||||
use Spark\Commands\Command;
 | 
			
		||||
use Spark\Environment\Environment;
 | 
			
		||||
use Spark\Pipe\Filters\FilterInterface;
 | 
			
		||||
use Spark\Pipe\Filters\PhpFilter;
 | 
			
		||||
use Spark\Resource\ResourceType;
 | 
			
		||||
use Spark\SparkApplication;
 | 
			
		||||
 | 
			
		||||
@@ -87,7 +89,7 @@ function read_config($file=null) {
 | 
			
		||||
 | 
			
		||||
$FILTERS = [];
 | 
			
		||||
 | 
			
		||||
function register_filter(string $name, callable $filter) {
 | 
			
		||||
function register_filter(string $name, string|callable $filter) {
 | 
			
		||||
    global $FILTERS;
 | 
			
		||||
    $FILTERS[$name] = $filter;
 | 
			
		||||
}
 | 
			
		||||
@@ -98,8 +100,18 @@ function get_registered_filters(): array
 | 
			
		||||
    return array_keys($FILTERS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function get_filter(string $name): ?callable
 | 
			
		||||
function get_filter(string $name, array $args=[]): null|FilterInterface|callable
 | 
			
		||||
{
 | 
			
		||||
    global $FILTERS;
 | 
			
		||||
    return $FILTERS[$name]??null;
 | 
			
		||||
    $filter = $FILTERS[$name]??null;
 | 
			
		||||
    if (is_string($filter) && class_exists($filter)) {
 | 
			
		||||
        $filter = new $filter;
 | 
			
		||||
    }
 | 
			
		||||
    if (is_callable($filter)) {
 | 
			
		||||
        $filter = new PhpFilter($filter);
 | 
			
		||||
    }
 | 
			
		||||
    if ($filter instanceof FilterInterface) {
 | 
			
		||||
        $filter->setArguments($args);
 | 
			
		||||
    }
 | 
			
		||||
    return $filter;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user