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

A config cache stores values using var_export() and include. More...

+ Collaboration diagram for Assetic\Cache\ConfigCache:

Public Member Functions

 __construct ($dir)
 Construct. More...
 
 has ($resource)
 Checks of the cache has a file. More...
 
 set ($resource, $value)
 Writes a value to a file. More...
 
 get ($resource)
 Loads and returns the value for the supplied cache key. More...
 
 getTimestamp ($resource)
 Returns a timestamp for when the cache was created. More...
 

Private Member Functions

 getSourcePath ($resource)
 Returns the path where the file corresponding to the supplied cache key can be included from. More...
 

Private Attributes

 $dir
 

Detailed Description

A config cache stores values using var_export() and include.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 19 of file ConfigCache.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Cache\ConfigCache::__construct (   $dir)

Construct.

Parameters
string$dirThe cache directory

Definition at line 28 of file ConfigCache.php.

References Assetic\Cache\ConfigCache\$dir.

29  {
30  $this->dir = $dir;
31  }

Member Function Documentation

◆ get()

Assetic\Cache\ConfigCache::get (   $resource)

Loads and returns the value for the supplied cache key.

Parameters
string$resourceA cache key
Returns
mixed The cached value

Definition at line 75 of file ConfigCache.php.

References $path, and Assetic\Cache\ConfigCache\getSourcePath().

76  {
77  $path = $this->getSourcePath($resource);
78 
79  if (!file_exists($path)) {
80  throw new \RuntimeException('There is no cached value for '.$resource);
81  }
82 
83  return include $path;
84  }
$path
Definition: aliased.php:25
getSourcePath($resource)
Returns the path where the file corresponding to the supplied cache key can be included from...
+ Here is the call graph for this function:

◆ getSourcePath()

Assetic\Cache\ConfigCache::getSourcePath (   $resource)
private

Returns the path where the file corresponding to the supplied cache key can be included from.

Parameters
string$resourceA cache key
Returns
string A file path

Definition at line 117 of file ConfigCache.php.

Referenced by Assetic\Cache\ConfigCache\get(), Assetic\Cache\ConfigCache\getTimestamp(), Assetic\Cache\ConfigCache\has(), and Assetic\Cache\ConfigCache\set().

118  {
119  $key = md5($resource);
120 
121  return $this->dir.'/'.$key[0].'/'.$key.'.php';
122  }
+ Here is the caller graph for this function:

◆ getTimestamp()

Assetic\Cache\ConfigCache::getTimestamp (   $resource)

Returns a timestamp for when the cache was created.

Parameters
string$resourceA cache key
Returns
integer A UNIX timestamp

Definition at line 93 of file ConfigCache.php.

References $path, and Assetic\Cache\ConfigCache\getSourcePath().

94  {
95  $path = $this->getSourcePath($resource);
96 
97  if (!file_exists($path)) {
98  throw new \RuntimeException('There is no cached value for '.$resource);
99  }
100 
101  if (false === $mtime = @filemtime($path)) {
102  // @codeCoverageIgnoreStart
103  throw new \RuntimeException('Unable to determine file mtime for '.$path);
104  // @codeCoverageIgnoreEnd
105  }
106 
107  return $mtime;
108  }
$path
Definition: aliased.php:25
getSourcePath($resource)
Returns the path where the file corresponding to the supplied cache key can be included from...
+ Here is the call graph for this function:

◆ has()

Assetic\Cache\ConfigCache::has (   $resource)

Checks of the cache has a file.

Parameters
string$resourceA cache key
Returns
Boolean True if a file exists

Definition at line 40 of file ConfigCache.php.

References Assetic\Cache\ConfigCache\getSourcePath().

41  {
42  return file_exists($this->getSourcePath($resource));
43  }
getSourcePath($resource)
Returns the path where the file corresponding to the supplied cache key can be included from...
+ Here is the call graph for this function:

◆ set()

Assetic\Cache\ConfigCache::set (   $resource,
  $value 
)

Writes a value to a file.

Parameters
string$resourceA cache key
mixed$valueA value to cache

Definition at line 51 of file ConfigCache.php.

References Assetic\Cache\ConfigCache\$dir, $path, and Assetic\Cache\ConfigCache\getSourcePath().

52  {
53  $path = $this->getSourcePath($resource);
54 
55  if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
56  // @codeCoverageIgnoreStart
57  throw new \RuntimeException('Unable to create directory '.$dir);
58  // @codeCoverageIgnoreEnd
59  }
60 
61  if (false === @file_put_contents($path, sprintf("<?php\n\n// $resource\nreturn %s;\n", var_export($value, true)))) {
62  // @codeCoverageIgnoreStart
63  throw new \RuntimeException('Unable to write file '.$path);
64  // @codeCoverageIgnoreEnd
65  }
66  }
$path
Definition: aliased.php:25
getSourcePath($resource)
Returns the path where the file corresponding to the supplied cache key can be included from...
+ Here is the call graph for this function:

Field Documentation

◆ $dir

Assetic\Cache\ConfigCache::$dir
private

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