1<?php 2 3/* 4 * This file is part of the Assetic package, an OpenSky project. 5 * 6 * (c) 2010-2014 OpenSky Project Inc 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Assetic\Filter; 13 14use Assetic\Asset\AssetInterface; 15use Assetic\Factory\AssetFactory; 16 17/** 18 * A filter that wraps callables. 19 * 20 * @author Kris Wallsmith <kris.wallsmith@gmail.com> 21 */ 22class CallablesFilter implements FilterInterface, DependencyExtractorInterface 23{ 24 private $loader; 25 private $dumper; 26 private $extractor; 27 28 /** 29 * @param callable|null $loader 30 * @param callable|null $dumper 31 * @param callable|null $extractor 32 */ 33 public function __construct($loader = null, $dumper = null, $extractor = null) 34 { 35 $this->loader = $loader; 36 $this->dumper = $dumper; 37 $this->extractor = $extractor; 38 } 39 40 public function filterLoad(AssetInterface $asset) 41 { 42 if (null !== $callable = $this->loader) { 43 $callable($asset); 44 } 45 } 46 47 public function filterDump(AssetInterface $asset) 48 { 49 if (null !== $callable = $this->dumper) { 50 $callable($asset); 51 } 52 } 53 54 public function getChildren(AssetFactory $factory, $content, $loadPath = null) 55 { 56 if (null !== $callable = $this->extractor) { 57 return $callable($factory, $content, $loadPath); 58 } 59 60 return array(); 61 } 62} 63