Source for file Cached.php
Documentation is available at Cached.php
* Provides a cached version of System_Folders.
* It also has methods to read folder settings from an ini file.
* require_once 'System/Folders/Cached.php';
* $sf = new System_Folders_Cached();
* //load the stored settings from last time
* //Set an own documents directory
* $sf->setDocuments('/home/cweiske/MyDocuments/');
* //Save the settings for next time
* @package System_Folders
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @link http://pear.php.net/package/System_Folders
require_once 'System/Folders.php';
require_once 'Config.php';
require_once 'Config/Container.php';
* Provides a cached version of System_Folders.
* It also has methods to read folder settings from an ini file.
* Be very careful when overriding the AppData setting with
* setAppData()! When loading a config file without specifying the file
* name, the default app data directory will be used. After loading,
* the file will be saved to the new app data directory, thus it won't
* be available the next time, as the app data folder is the old one again.
* @package System_Folders
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @link http://pear.php.net/package/System_Folders
* The cached paths will be hold here.
* The settings that are available.
'AllUsers', 'AppData', 'Desktop', 'Documents', 'Home',
'Programs', 'Temp', 'SharedDocuments', 'Windows'
}//function System_Folders_Cached()
* Loads the directories from an ini file.
* If you don't specify the config file, it will be determined
* @param string $strFile The file to load the data from (ini file)
* @return mixed True on success, PEAR_Error on failure
//Not existing config file isn't an error
$root = & $conf->parseConfig ($strFile, 'inifile');
if (PEAR ::isError ($root)) {
$arSettings = $root->toArray ();
if (!isset ($arSettings['root']['paths'])) {
foreach ($arSettings['root']['paths'] as $strId => $strValue) {
$this->arCache[$strId] = $strValue;
}//function loadFromFile($strFile = null)
* Saves the folders into a config file that can be edited by hand.
* If you don't specify the config file, it will be determined
* Values that are NULL won't be saved.
* @param string $strFile The file to save the data into
* @param boolean $bSaveAllSettings If all settings shall be saved
* that can be loaded, or only that settings,
* that have been retrieved by the user
* @return mixed True on success, PEAR_Error on failure
function saveToFile($strFile = null , $bSaveAllSettings = true )
$conf = & new Config_Container ('section', 'paths');
$strFunction = 'get' . $strSetting;
$strValue = $this->$strFunction();
$conf->createDirective (strtolower($strSetting), $strValue);
foreach ($this->arCache as $strId => $strValue) {
$conf->createDirective ($strId, $strValue);
}//function saveToFile($strFile = null, $bSaveAllSettings = true)
* Returns the path to the default config file.
* It the one that's used if no filename is passed to the
* saveToFile/loadFromFile methods.
* @return string The filename
return $this->getAppData() . '/.net.php.pear.system.folders';
}//function getDefaultConfigFile()
* Returns a cached value.
* If the cache doesn't exist, the cached value is empty or null,
* the System_Folders method for the key is called to get the value.
* @param string $strKey The id of the value to get
* @return string The directory
if (!isset ($this->arCache[$strKeyLower])) {
$strFunction = 'get' . $strKey;
$this->arCache[$strKeyLower] = parent ::$strFunction();
return $this->arCache[$strKeyLower];
}//function getCachedValue($strKey)
* Sets the cache of the given key to the given value.
* Passing NULL removes the cache entry.
* @param string $strKey Id of the value to get
* @param string $strValue Value to set.
if ($strValue === null ) {
}//function setCachedValue($strKey, $strValue)
* Overriding the parent's methods to cache them
* Cached version of getAllUsers().
* @return string The all users directory
* @see System_Folders::getAllUsers()
}//function getAllUsers()
* Cached version of getAppData().
* @return string The application data directory
* @see System_Folders::getAppData()
* Cached version of getDesktop().
* @return string The desktop directory
* @see System_Folders::getDesktop()
* Cached version of getDocuments().
* @return string The documents directory
* @see System_Folders::getDocuments()
}//function getDocuments()
* Cached version of getHome().
* @return string The home directory
* @see System_Folders::getHome()
* Cached version of getPrograms().
* @return string The programs directory
* @see System_Folders::getPrograms()
}//function getPrograms()
* Cached version of getTemp().
* @return string The temporary directory
* @see System_Folders::getTemp()
* Cached version of getSharedDocuments().
* @return string The shared documents directory
* @see System_Folders::getSharedDocuments()
}//function getSharedDocuments()
* Cached version of getWindows().
* @return string The windows directory
* @see System_Folders::getWindows()
* Sets an own all users directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new all users directory
}//function setAllUsers($value)
* Sets an own application data directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new app data directory
}//function setAppData($value)
* Sets an own desktop directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new desktop directory
}//function setDesktop($value)
* Sets an own documents directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new documents directory
}//function setDocuments($value)
* Sets an own home directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new home directory
}//function setHome($value)
* Sets an own programs directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new programs directory
}//function setPrograms($value)
* Sets an own temp directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new temp directory
}//function setTemp($value)
* Sets an own shared documents directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new shared documents directory
* @see getSharedDocuments()
}//function setSharedDocuments($value)
* Sets an own windows directory.
* Set it to NULL to deactivate saving and
* remove the value from the cache.
* @param string $value The new windows directory
}//function setWindows($value)
}//class System_Folders_Cached extends System_Folders
Documentation generated on Fri, 21 Dec 2012 15:30:02 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|