ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
AssetWriter.php
Go to the documentation of this file.
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;
13
16
24{
25 private $dir;
26 private $values;
27
36 public function __construct($dir, array $values = array())
37 {
38 foreach ($values as $var => $vals) {
39 foreach ($vals as $value) {
40 if (!is_string($value)) {
41 throw new \InvalidArgumentException(sprintf('All variable values must be strings, but got %s for variable "%s".', json_encode($value), $var));
42 }
43 }
44 }
45
46 $this->dir = $dir;
47 $this->values = $values;
48 }
49
50 public function writeManagerAssets(AssetManager $am)
51 {
52 foreach ($am->getNames() as $name) {
53 $this->writeAsset($am->get($name));
54 }
55 }
56
57 public function writeAsset(AssetInterface $asset)
58 {
59 foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
60 $asset->setValues($combination);
61
62 static::write(
63 $this->dir.'/'.VarUtils::resolve(
64 $asset->getTargetPath(),
65 $asset->getVars(),
66 $asset->getValues()
67 ),
68 $asset->dump()
69 );
70 }
71 }
72
73 protected static function write($path, $contents)
74 {
75 if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
76 throw new \RuntimeException('Unable to create directory '.$dir);
77 }
78
79 if (false === @file_put_contents($path, $contents)) {
80 throw new \RuntimeException('Unable to write file '.$path);
81 }
82 }
83
90 private function getCombinations(array $vars)
91 {
92 return VarUtils::getCombinations($vars, $this->values);
93 }
94}
sprintf('%.4f', $callTime)
$path
Definition: aliased.php:25
Manages assets.
get($name)
Gets an asset by name.
getNames()
Returns an array of asset names.
Writes assets to the filesystem.
Definition: AssetWriter.php:24
static write($path, $contents)
Definition: AssetWriter.php:73
__construct($dir, array $values=array())
Constructor.
Definition: AssetWriter.php:36
writeAsset(AssetInterface $asset)
Definition: AssetWriter.php:57
getCombinations(array $vars)
Not used.
Definition: AssetWriter.php:90
writeManagerAssets(AssetManager $am)
Definition: AssetWriter.php:50
Variable utilities.
Definition: VarUtils.php:20
An exception for terminatinating execution or to throw for unit testing.
An asset has a mutable URL and content and can be loaded and dumped.
setValues(array $values)
Sets the values for the asset's variables.
getValues()
Returns the current values for this asset.
dump(FilterInterface $additionalFilter=null)
Applies dump filters and returns the asset as a string.
getVars()
Returns an array of variable names for this asset.
getTargetPath()
Returns the URL for the current asset.
Class CssCacheBustingFilter.