48 $this->root = rtrim(
$root,
'/');
50 $this->output =
'assetic/*';
51 $this->workers =
array();
91 $this->workers[] = $worker;
155 if (!is_array($inputs)) {
156 $inputs =
array($inputs);
159 if (!is_array($filters)) {
160 $filters =
array($filters);
190 $extensions =
array();
193 foreach ($inputs as $input) {
194 if (is_array($input)) {
196 $asset->add(call_user_func_array(
array($this,
'createAsset'), $input));
199 $extensions[pathinfo($input, PATHINFO_EXTENSION)] =
true;
204 foreach ($filters as $filter) {
205 if (
'?' != $filter[0]) {
206 $asset->ensureFilter($this->
getFilter($filter));
208 $asset->ensureFilter($this->
getFilter(substr($filter, 1)));
215 foreach (
$options[
'vars'] as $var) {
216 if (
false !== strpos(
$options[
'output'],
'{'.$var.
'}')) {
220 $toAdd[] =
'{'.$var.
'}';
224 $options[
'output'] = str_replace(
'*',
'*.'.implode(
'.', $toAdd),
$options[
'output']);
229 if (1 == count($extensions) && !pathinfo(
$options[
'output'], PATHINFO_EXTENSION) && $extension = key($extensions)) {
230 $options[
'output'] .=
'.'.$extension;
234 $asset->setTargetPath(str_replace(
'*',
$options[
'name'],
$options[
'output']));
242 foreach (array_diff(array_keys(
$options),
array(
'output',
'debug',
'root')) as $key) {
248 return substr(sha1(serialize($inputs).serialize($filters).serialize(
$options)), 0, 7);
255 $mtime = max($mtime, $leaf->getLastModified());
257 if (!$filters = $leaf->getFilters()) {
261 $prevFilters =
array();
262 foreach ($filters as $filter) {
263 $prevFilters[] = $filter;
270 $clone = clone $leaf;
271 $clone->clearFilters();
272 foreach (array_slice($prevFilters, 0, -1) as $prevFilter) {
273 $clone->ensureFilter($prevFilter);
277 foreach ($filter->getChildren($this, $clone->getContent(), $clone->getSourceDirectory()) as $child) {
305 if (
'@' == $input[0]) {
309 if (
false !== strpos($input,
'://') || 0 === strpos($input,
'//')) {
313 if (self::isAbsolutePath($input)) {
315 $path = ltrim(substr($input, strlen(
$root)),
'/');
322 $input = $this->root.
'/'.
$path;
325 if (
false !== strpos($input,
'*')) {
340 throw new \LogicException(
'There is no asset manager.');
364 throw new \LogicException(
'There is no filter manager.');
367 return $this->fm->get($name);
382 foreach ($asset as $leaf) {
383 foreach ($this->workers as $worker) {
384 $retval = $worker->process($leaf, $this);
392 foreach ($this->workers as $worker) {
393 $retval = $worker->process($asset, $this);
418 foreach ($roots as
$root) {
419 if (0 === strpos(
$path, $root)) {
A reference to an asset in the asset manager.
Manages the available filters.
createHttpAsset($sourceUrl, $vars)
parseInput($input, array $options=array())
Parses an input string string into an asset.
setDefaultOutput($output)
Sets the default output string.
isDebug()
Checks if the factory is in debug mode.
createGlobAsset($glob, $root=null, $vars)
generateAssetName($inputs, $filters, $options=array())
createAsset($inputs=array(), $filters=array(), array $options=array())
Creates a new asset.
getAssetManager()
Returns the current asset manager.
__construct($root, $debug=false)
Constructor.
createFileAsset($source, $root=null, $path=null, $vars)
replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful=false)
Replaces an existing leaf with a new one.
createAssetCollection(array $assets=array(), array $options=array())
setFilterManager(FilterManager $fm)
Sets the filter manager to use when adding filters.
A collection of assets loaded by glob.
Represents an asset loaded via an HTTP request.
if(!is_array($argv)) $options
Represents an asset loaded from a file.
getFilterManager()
Returns the current filter manager.
applyWorkers(AssetCollectionInterface $asset)
Filters an asset collection through the factory workers.
createAssetReference($name)
Assets are passed through factory workers before leaving the factory.
addWorker(WorkerInterface $worker)
Adds a factory worker.
setDebug($debug)
Sets debug mode for the current factory.
An asset has a mutable URL and content and can be loaded and dumped.
static isAbsolutePath($path)
Create styles array
The data for the language used.
The asset factory creates asset objects.
static findRootDir($path, array $roots)
Loops through the root directories and returns the first match.
getLastModified(AssetInterface $asset)
setAssetManager(AssetManager $am)
Sets the asset manager to use when creating asset references.