ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_DefinitionCache_Serializer Class Reference
+ Inheritance diagram for HTMLPurifier_DefinitionCache_Serializer:
+ Collaboration diagram for HTMLPurifier_DefinitionCache_Serializer:

Public Member Functions

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

Private Member Functions

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

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_DefinitionCache
 $type

Detailed Description

Definition at line 3 of file Serializer.php.

Member Function Documentation

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 $config, _testPermissions(), generateBaseDirectoryPath(), and generateDirectoryPath().

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

{
$directory = $this->generateDirectoryPath($config);
$chmod = $config->get('Cache.SerializerPermissions');
if (!$chmod) {
$chmod = 0755; // invalid config or simpletest
}
if (!is_dir($directory)) {
if (!is_dir($base)) {
trigger_error('Base directory '.$base.' does not exist,
please create or change using %Cache.SerializerPath',
E_USER_WARNING);
return false;
} elseif (!$this->_testPermissions($base, $chmod)) {
return false;
}
$old = umask(0000);
mkdir($directory, $chmod);
umask($old);
} elseif (!$this->_testPermissions($directory, $chmod)) {
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References $dir.

Referenced by _prepareDir().

{
// early abort, if it is writable, everything is hunky-dory
if (is_writable($dir)) return true;
if (!is_dir($dir)) {
// generally, you'll want to handle this beforehand
// so a more specific error message can be given
trigger_error('Directory '.$dir.' does not exist',
E_USER_WARNING);
return false;
}
if (function_exists('posix_getuid')) {
// POSIX system, we can give more specific advice
if (fileowner($dir) === posix_getuid()) {
// we can chmod it ourselves
$chmod = $chmod | 0700;
if (chmod($dir, $chmod)) return true;
} elseif (filegroup($dir) === posix_getgid()) {
$chmod = $chmod | 0070;
} else {
// PHP's probably running as nobody, so we'll
// need to give global permissions
$chmod = $chmod | 0777;
}
trigger_error('Directory '.$dir.' not writable, '.
'please chmod to ' . decoct($chmod),
E_USER_WARNING);
} else {
// generic error message
trigger_error('Directory '.$dir.' not writable, '.
'please alter file permissions',
E_USER_WARNING);
}
return false;
}

+ Here is the caller graph for this function:

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 $config, $data, $file, and $result.

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

{
$result = file_put_contents($file, $data);
if ($result !== false) {
// set permissions of the new file (no execute)
$chmod = $config->get('Cache.SerializerPermissions');
if (!$chmod) {
$chmod = 0644; // invalid config or simpletest
}
$chmod = $chmod & 0666;
chmod($file, $chmod);
}
return $result;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::add (   $def,
  $config 
)

Adds a definition object to the cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 7 of file Serializer.php.

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

{
if (!$this->checkDefType($def)) return;
if (file_exists($file)) return false;
if (!$this->_prepareDir($config)) return false;
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::cleanup (   $config)

Clears all expired (older version or revision) objects from cache.

Note
Be carefuly implementing this method as flush. Flush must not interfere with other Definition types, and cleanup() should not be repeatedly called by userland code.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 53 of file Serializer.php.

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

{
if (!$this->_prepareDir($config)) return false;
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if (empty($filename)) continue;
if ($filename[0] === '.') continue;
$key = substr($filename, 0, strlen($filename) - 4);
if ($this->isOld($key, $config)) unlink($dir . '/' . $filename);
}
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::flush (   $config)

Clears all objects from cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 42 of file Serializer.php.

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

{
if (!$this->_prepareDir($config)) return false;
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if (empty($filename)) continue;
if ($filename[0] === '.') continue;
unlink($dir . '/' . $filename);
}
}

+ Here is the call graph for this function:

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.

References $config.

Referenced by _prepareDir(), and generateDirectoryPath().

{
$base = $config->get('Cache.SerializerPath');
$base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base;
return $base;
}

+ Here is the caller graph for this function:

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 $config, HTMLPurifier_DefinitionCache\$type, and generateBaseDirectoryPath().

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

{
return $base . '/' . $this->type;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 $config, generateDirectoryPath(), and HTMLPurifier_DefinitionCache\generateKey().

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

{
$key = $this->generateKey($config);
return $this->generateDirectoryPath($config) . '/' . $key . '.ser';
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::get (   $config)

Retrieves a definition object from the cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 30 of file Serializer.php.

References $config, $file, and generateFilePath().

{
if (!file_exists($file)) return false;
return unserialize(file_get_contents($file));
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::remove (   $config)

Removes a definition object to the cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 36 of file Serializer.php.

References $config, $file, and generateFilePath().

{
if (!file_exists($file)) return false;
return unlink($file);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::replace (   $def,
  $config 
)

Replace an object in the cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 22 of file Serializer.php.

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

{
if (!$this->checkDefType($def)) return;
if (!file_exists($file)) return false;
if (!$this->_prepareDir($config)) return false;
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::set (   $def,
  $config 
)

Unconditionally saves a definition object to the cache.

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 15 of file Serializer.php.

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

{
if (!$this->checkDefType($def)) return;
if (!$this->_prepareDir($config)) return false;
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:


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