ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\AssetWriter Class Reference

Writes assets to the filesystem. More...

+ Collaboration diagram for Assetic\AssetWriter:

Public Member Functions

 __construct ($dir, array $values=array())
 Constructor. More...
 
 writeManagerAssets (AssetManager $am)
 
 writeAsset (AssetInterface $asset)
 

Static Protected Member Functions

static write ($path, $contents)
 

Private Member Functions

 getCombinations (array $vars)
 Not used. More...
 

Private Attributes

 $dir
 
 $values
 

Detailed Description

Writes assets to the filesystem.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Johannes M. Schmitt schmi.nosp@m.ttjo.nosp@m.h@gma.nosp@m.il.c.nosp@m.om

Definition at line 23 of file AssetWriter.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\AssetWriter::__construct (   $dir,
array  $values = array() 
)

Constructor.

Parameters
string$dirThe base web directory
array$valuesVariable values
Exceptions

InvalidArgumentException if a variable value is not a string

Definition at line 36 of file AssetWriter.php.

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 }
sprintf('%.4f', $callTime)

References sprintf.

Member Function Documentation

◆ getCombinations()

Assetic\AssetWriter::getCombinations ( array  $vars)
private

Not used.

This method is provided for backward compatibility with certain versions of AsseticBundle.

Definition at line 90 of file AssetWriter.php.

91 {
92 return VarUtils::getCombinations($vars, $this->values);
93 }
static getCombinations(array $vars, array $values)
Definition: VarUtils.php:50

◆ write()

static Assetic\AssetWriter::write (   $path,
  $contents 
)
staticprotected

Definition at line 73 of file AssetWriter.php.

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 }
$path
Definition: aliased.php:25

References $contents, and $path.

◆ writeAsset()

Assetic\AssetWriter::writeAsset ( AssetInterface  $asset)

Definition at line 57 of file AssetWriter.php.

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 }
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32

References Assetic\Asset\AssetInterface\dump(), Assetic\Asset\AssetInterface\getTargetPath(), Assetic\Asset\AssetInterface\getValues(), Assetic\Asset\AssetInterface\getVars(), and Assetic\Asset\AssetInterface\setValues().

+ Here is the call graph for this function:

◆ writeManagerAssets()

Assetic\AssetWriter::writeManagerAssets ( AssetManager  $am)

Definition at line 50 of file AssetWriter.php.

51 {
52 foreach ($am->getNames() as $name) {
53 $this->writeAsset($am->get($name));
54 }
55 }
writeAsset(AssetInterface $asset)
Definition: AssetWriter.php:57

References Assetic\AssetManager\get(), and Assetic\AssetManager\getNames().

+ Here is the call graph for this function:

Field Documentation

◆ $dir

Assetic\AssetWriter::$dir
private

Definition at line 25 of file AssetWriter.php.

◆ $values

Assetic\AssetWriter::$values
private

Definition at line 26 of file AssetWriter.php.


The documentation for this class was generated from the following file: