ILIAS  release_4-4 Revision
HTMLPurifier_DefinitionCache_Serializer Class Reference
+ Inheritance diagram for HTMLPurifier_DefinitionCache_Serializer:
+ Collaboration diagram for HTMLPurifier_DefinitionCache_Serializer:

Public Member Functions

 add ($def, $config)
 
 set ($def, $config)
 
 replace ($def, $config)
 
 get ($config)
 
 remove ($config)
 
 flush ($config)
 
 cleanup ($config)
 
 generateFilePath ($config)
 Generates the file path to the serial file corresponding to the configuration and definition name. More...
 
 generateDirectoryPath ($config)
 Generates the path to the directory contain this cache's serial files. More...
 
 generateBaseDirectoryPath ($config)
 Generates path to base directory that contains all definition type serials. More...
 
- Public Member Functions inherited from HTMLPurifier_DefinitionCache
 __construct ($type)
 
 generateKey ($config)
 Generates a unique identifier for a particular configuration. More...
 
 isOld ($key, $config)
 Tests whether or not a key is old with respect to the configuration's version and revision number. More...
 
 checkDefType ($def)
 Checks if a definition's type jives with the cache's type. More...
 
 add ($def, $config)
 Adds a definition object to the cache. More...
 
 set ($def, $config)
 Unconditionally saves a definition object to the cache. More...
 
 replace ($def, $config)
 Replace an object in the cache. More...
 
 get ($config)
 Retrieves a definition object from the cache. More...
 
 remove ($config)
 Removes a definition object to the cache. More...
 
 flush ($config)
 Clears all objects from cache. More...
 
 cleanup ($config)
 Clears all expired (older version or revision) objects from cache. More...
 

Private Member Functions

 _write ($file, $data, $config)
 Convenience wrapper function for file_put_contents. More...
 
 _prepareDir ($config)
 Prepares the directory that this type stores the serials in. More...
 
 _testPermissions ($dir, $chmod)
 Tests permissions on a directory and throws out friendly error messages and attempts to chmod it itself if possible. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_DefinitionCache
 $type
 

Detailed Description

Definition at line 3 of file Serializer.php.

Member Function Documentation

◆ _prepareDir()

HTMLPurifier_DefinitionCache_Serializer::_prepareDir (   $config)
private

Prepares the directory that this type stores the serials in.

Parameters
$configConfig object
Returns
True if successful

Definition at line 122 of file Serializer.php.

References _testPermissions(), generateBaseDirectoryPath(), and generateDirectoryPath().

Referenced by add(), cleanup(), flush(), replace(), and set().

122  {
123  $directory = $this->generateDirectoryPath($config);
124  $chmod = $config->get('Cache.SerializerPermissions');
125  if (!$chmod) {
126  $chmod = 0755; // invalid config or simpletest
127  }
128  if (!is_dir($directory)) {
129  $base = $this->generateBaseDirectoryPath($config);
130  if (!is_dir($base)) {
131  trigger_error('Base directory '.$base.' does not exist,
132  please create or change using %Cache.SerializerPath',
133  E_USER_WARNING);
134  return false;
135  } elseif (!$this->_testPermissions($base, $chmod)) {
136  return false;
137  }
138  $old = umask(0000);
139  mkdir($directory, $chmod);
140  umask($old);
141  } elseif (!$this->_testPermissions($directory, $chmod)) {
142  return false;
143  }
144  return true;
145  }
generateBaseDirectoryPath($config)
Generates path to base directory that contains all definition type serials.
Definition: Serializer.php:90
generateDirectoryPath($config)
Generates the path to the directory contain this cache's serial files.
Definition: Serializer.php:80
_testPermissions($dir, $chmod)
Tests permissions on a directory and throws out friendly error messages and attempts to chmod it itse...
Definition: Serializer.php:154
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _testPermissions()

HTMLPurifier_DefinitionCache_Serializer::_testPermissions (   $dir,
  $chmod 
)
private

Tests permissions on a directory and throws out friendly error messages and attempts to chmod it itself if possible.

Parameters
$dirDirectory path
$chmodPermissions
Returns
True if directory writable

Definition at line 154 of file Serializer.php.

Referenced by _prepareDir().

154  {
155  // early abort, if it is writable, everything is hunky-dory
156  if (is_writable($dir)) return true;
157  if (!is_dir($dir)) {
158  // generally, you'll want to handle this beforehand
159  // so a more specific error message can be given
160  trigger_error('Directory '.$dir.' does not exist',
161  E_USER_WARNING);
162  return false;
163  }
164  if (function_exists('posix_getuid')) {
165  // POSIX system, we can give more specific advice
166  if (fileowner($dir) === posix_getuid()) {
167  // we can chmod it ourselves
168  $chmod = $chmod | 0700;
169  if (chmod($dir, $chmod)) return true;
170  } elseif (filegroup($dir) === posix_getgid()) {
171  $chmod = $chmod | 0070;
172  } else {
173  // PHP's probably running as nobody, so we'll
174  // need to give global permissions
175  $chmod = $chmod | 0777;
176  }
177  trigger_error('Directory '.$dir.' not writable, '.
178  'please chmod to ' . decoct($chmod),
179  E_USER_WARNING);
180  } else {
181  // generic error message
182  trigger_error('Directory '.$dir.' not writable, '.
183  'please alter file permissions',
184  E_USER_WARNING);
185  }
186  return false;
187  }
+ Here is the caller graph for this function:

◆ _write()

HTMLPurifier_DefinitionCache_Serializer::_write (   $file,
  $data,
  $config 
)
private

Convenience wrapper function for file_put_contents.

Parameters
$fileFile name to write to
$dataData to write into file
$configConfig object
Returns
Number of bytes written if success, or false if failure.

Definition at line 103 of file Serializer.php.

References $data, $file, and $result.

Referenced by add(), replace(), and set().

103  {
104  $result = file_put_contents($file, $data);
105  if ($result !== false) {
106  // set permissions of the new file (no execute)
107  $chmod = $config->get('Cache.SerializerPermissions');
108  if (!$chmod) {
109  $chmod = 0644; // invalid config or simpletest
110  }
111  $chmod = $chmod & 0666;
112  chmod($file, $chmod);
113  }
114  return $result;
115  }
print $file
$result
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the caller graph for this function:

◆ add()

HTMLPurifier_DefinitionCache_Serializer::add (   $def,
  $config 
)

Definition at line 7 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

7  {
8  if (!$this->checkDefType($def)) return;
9  $file = $this->generateFilePath($config);
10  if (file_exists($file)) return false;
11  if (!$this->_prepareDir($config)) return false;
12  return $this->_write($file, serialize($def), $config);
13  }
print $file
checkDefType($def)
Checks if a definition's type jives with the cache's type.
_prepareDir($config)
Prepares the directory that this type stores the serials in.
Definition: Serializer.php:122
_write($file, $data, $config)
Convenience wrapper function for file_put_contents.
Definition: Serializer.php:103
generateFilePath($config)
Generates the file path to the serial file corresponding to the configuration and definition name...
Definition: Serializer.php:70
+ Here is the call graph for this function:

◆ cleanup()

HTMLPurifier_DefinitionCache_Serializer::cleanup (   $config)

Definition at line 53 of file Serializer.php.

References $filename, _prepareDir(), generateDirectoryPath(), and HTMLPurifier_DefinitionCache\isOld().

53  {
54  if (!$this->_prepareDir($config)) return false;
55  $dir = $this->generateDirectoryPath($config);
56  $dh = opendir($dir);
57  while (false !== ($filename = readdir($dh))) {
58  if (empty($filename)) continue;
59  if ($filename[0] === '.') continue;
60  $key = substr($filename, 0, strlen($filename) - 4);
61  if ($this->isOld($key, $config)) unlink($dir . '/' . $filename);
62  }
63  }
generateDirectoryPath($config)
Generates the path to the directory contain this cache's serial files.
Definition: Serializer.php:80
_prepareDir($config)
Prepares the directory that this type stores the serials in.
Definition: Serializer.php:122
$filename
Definition: buildRTE.php:89
isOld($key, $config)
Tests whether or not a key is old with respect to the configuration's version and revision number...
+ Here is the call graph for this function:

◆ flush()

HTMLPurifier_DefinitionCache_Serializer::flush (   $config)

Definition at line 42 of file Serializer.php.

References $filename, _prepareDir(), and generateDirectoryPath().

42  {
43  if (!$this->_prepareDir($config)) return false;
44  $dir = $this->generateDirectoryPath($config);
45  $dh = opendir($dir);
46  while (false !== ($filename = readdir($dh))) {
47  if (empty($filename)) continue;
48  if ($filename[0] === '.') continue;
49  unlink($dir . '/' . $filename);
50  }
51  }
generateDirectoryPath($config)
Generates the path to the directory contain this cache's serial files.
Definition: Serializer.php:80
_prepareDir($config)
Prepares the directory that this type stores the serials in.
Definition: Serializer.php:122
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:

◆ generateBaseDirectoryPath()

HTMLPurifier_DefinitionCache_Serializer::generateBaseDirectoryPath (   $config)

Generates path to base directory that contains all definition type serials.

Todo:
Make protected

Definition at line 90 of file Serializer.php.

Referenced by _prepareDir(), and generateDirectoryPath().

90  {
91  $base = $config->get('Cache.SerializerPath');
92  $base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base;
93  return $base;
94  }
+ Here is the caller graph for this function:

◆ generateDirectoryPath()

HTMLPurifier_DefinitionCache_Serializer::generateDirectoryPath (   $config)

Generates the path to the directory contain this cache's serial files.

Note
No trailing slash
Todo:
Make protected

Definition at line 80 of file Serializer.php.

References HTMLPurifier_DefinitionCache\$type, and generateBaseDirectoryPath().

Referenced by _prepareDir(), cleanup(), flush(), and generateFilePath().

80  {
81  $base = $this->generateBaseDirectoryPath($config);
82  return $base . '/' . $this->type;
83  }
generateBaseDirectoryPath($config)
Generates path to base directory that contains all definition type serials.
Definition: Serializer.php:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateFilePath()

HTMLPurifier_DefinitionCache_Serializer::generateFilePath (   $config)

Generates the file path to the serial file corresponding to the configuration and definition name.

Todo:
Make protected

Definition at line 70 of file Serializer.php.

References generateDirectoryPath(), and HTMLPurifier_DefinitionCache\generateKey().

Referenced by add(), get(), remove(), replace(), and set().

70  {
71  $key = $this->generateKey($config);
72  return $this->generateDirectoryPath($config) . '/' . $key . '.ser';
73  }
generateDirectoryPath($config)
Generates the path to the directory contain this cache's serial files.
Definition: Serializer.php:80
generateKey($config)
Generates a unique identifier for a particular configuration.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

HTMLPurifier_DefinitionCache_Serializer::get (   $config)

Definition at line 30 of file Serializer.php.

References $file, and generateFilePath().

30  {
31  $file = $this->generateFilePath($config);
32  if (!file_exists($file)) return false;
33  return unserialize(file_get_contents($file));
34  }
print $file
generateFilePath($config)
Generates the file path to the serial file corresponding to the configuration and definition name...
Definition: Serializer.php:70
+ Here is the call graph for this function:

◆ remove()

HTMLPurifier_DefinitionCache_Serializer::remove (   $config)

Definition at line 36 of file Serializer.php.

References $file, and generateFilePath().

36  {
37  $file = $this->generateFilePath($config);
38  if (!file_exists($file)) return false;
39  return unlink($file);
40  }
print $file
generateFilePath($config)
Generates the file path to the serial file corresponding to the configuration and definition name...
Definition: Serializer.php:70
+ Here is the call graph for this function:

◆ replace()

HTMLPurifier_DefinitionCache_Serializer::replace (   $def,
  $config 
)

Definition at line 22 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

22  {
23  if (!$this->checkDefType($def)) return;
24  $file = $this->generateFilePath($config);
25  if (!file_exists($file)) return false;
26  if (!$this->_prepareDir($config)) return false;
27  return $this->_write($file, serialize($def), $config);
28  }
print $file
checkDefType($def)
Checks if a definition's type jives with the cache's type.
_prepareDir($config)
Prepares the directory that this type stores the serials in.
Definition: Serializer.php:122
_write($file, $data, $config)
Convenience wrapper function for file_put_contents.
Definition: Serializer.php:103
generateFilePath($config)
Generates the file path to the serial file corresponding to the configuration and definition name...
Definition: Serializer.php:70
+ Here is the call graph for this function:

◆ set()

HTMLPurifier_DefinitionCache_Serializer::set (   $def,
  $config 
)

Definition at line 15 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

15  {
16  if (!$this->checkDefType($def)) return;
17  $file = $this->generateFilePath($config);
18  if (!$this->_prepareDir($config)) return false;
19  return $this->_write($file, serialize($def), $config);
20  }
print $file
checkDefType($def)
Checks if a definition's type jives with the cache's type.
_prepareDir($config)
Prepares the directory that this type stores the serials in.
Definition: Serializer.php:122
_write($file, $data, $config)
Convenience wrapper function for file_put_contents.
Definition: Serializer.php:103
generateFilePath($config)
Generates the file path to the serial file corresponding to the configuration and definition name...
Definition: Serializer.php:70
+ Here is the call graph for this function:

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