/** * A method to build the PEAR::Cache_Lite options for a plugin's cache file(s), * given a module/package name. Also creates the required cache store directory * if it doesn't exist. * * @static * @param string $module The plugin module name (i.e. /plugins/module directory). * @param string $package The plugin package name (i.e. /plugins/module/package * directory). * @param string $cacheDir An optional specification for the cache directory. * The default is /var/plugins/cache/module/package/). * @param integer $cacheExpire An optional specification for the cache lifetime * in seconds. The default is 1 hour. * @return mixed An array with the cache options for PEAR Cache_Lite class, or * false if the cache directory does not exist/cannot be created. */ function prepareCacheOptions($module, $package, $cacheDir = null, $cacheExpire = 3600) { $aConf = $GLOBALS['_MAX']['CONF']; // Prepare the options for PEAR::Cache_Lite if (is_null($cacheDir)) { $cacheDir = MAX_PATH . $aConf['pluginPaths']['var'] . 'cache/' . $module . '/' . $package . '/'; } $aOptions = array('cacheDir' => $cacheDir, 'lifeTime' => $cacheExpire, 'automaticSerialization' => true); if (!is_dir($aOptions['cacheDir'])) { if (!MAX_Plugin::_mkDirRecursive($aOptions['cacheDir'], MAX_PLUGINS_VAR_WRITE_MODE)) { MAX::raiseError('Folder: "' . $aOptions['cacheDir'] . '" is not writeable.', PEAR_LOG_ERR); return false; } } return $aOptions; }
/** * A method to test the _mkDirRecursive() method. */ function test_mkDirRecursive() { $aConf = $GLOBALS['_MAX']['CONF']; // Try to create a folder $result = MAX_Plugin::_mkDirRecursive($aConf['pluginPaths']['var'] . 'test'); $this->assertTrue($result); // Remove the created directory $this->_delDir($aConf['pluginPaths']['var'] . 'test'); }