Created
August 20, 2011 15:05
-
-
Save kriswallsmith/1159210 to your computer and use it in GitHub Desktop.
A universal constructor for Assetic filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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