Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created August 20, 2011 15:05
Show Gist options
  • Select an option

  • Save kriswallsmith/1159210 to your computer and use it in GitHub Desktop.

Select an option

Save kriswallsmith/1159210 to your computer and use it in GitHub Desktop.
A universal constructor for Assetic filters
<?php
use Assetic\Asset\AssetInterface;
use Assetic\Filter\FilterInterface;
class UniversalFilter implements FilterInterface
{
static private $factories = array();
private $delegate;
/**
* Registers a callable that creates a new filter.
*
* @param string $name The filter name
* @param callable $callable The factory callable
*/
static public function registerFactory($name, $callable)
{
self::$factories[$name] = $callable;
}
/**
* Constructor.
*
* @param string $name The filter name
* @param array $options The filter options
*/
public function __construct($name, array $options = array())
{
if (!isset(self::$factories[$name])) {
throw new \InvalidArgumentException('Unrecognized filter: '.$name);
}
$this->delegate = call_user_func(self::$factories[$name], $options);
}
public function filterLoad(AssetInterface $asset)
{
$this->delegate->filterLoad($asset);
}
public function filterDump(AssetInterface $asset)
{
$this->delegate->filterDump($asset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment