Source of file FilesystemOptions.php
Size: 11,266 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Cache/Storage/Adapter/FilesystemOptions.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Cache\Storage\Adapter; use Traversable; use Zend\Cache\Exception; /** * These are options specific to the Filesystem adapter */ class FilesystemOptions extends AdapterOptions { /** * Directory to store cache files * * @var null|string The cache directory * or NULL for the systems temporary directory */ protected $cacheDir = null; /** * Call clearstatcache enabled? * * @var bool */ protected $clearStatCache = true; /** * How much sub-directaries should be created? * * @var int */ protected $dirLevel = 1; /** * Permission creating new directories * * @var false|int */ protected $dirPermission = 0700; /** * Lock files on writing * * @var bool */ protected $fileLocking = true; /** * Permission creating new files * * @var false|int */ protected $filePermission = 0600; /** * Overwrite default key pattern * * Defined in AdapterOptions * * @var string */ protected $keyPattern = '/^[a-z0-9_\+\-]*$/Di'; /** * Namespace separator * * @var string */ protected $namespaceSeparator = '-'; /** * Don't get 'fileatime' as 'atime' on metadata * * @var bool */ protected $noAtime = true; /** * Don't get 'filectime' as 'ctime' on metadata * * @var bool */ protected $noCtime = true; /** * Umask to create files and directories * * @var false|int */ protected $umask = false; /** * Constructor * * @param array|Traversable|null $options * @return FilesystemOptions * @throws Exception\InvalidArgumentException */ public function __construct($options = null) { // disable file/directory permissions by default on windows systems if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $this->filePermission = false; $this->dirPermission = false; } parent::__construct($options); } /** * Set cache dir * * @param string $cacheDir * @return FilesystemOptions * @throws Exception\InvalidArgumentException */ public function setCacheDir($cacheDir) { if ($cacheDir !== null) { if (!is_dir($cacheDir)) { throw new Exception\InvalidArgumentException( "Cache directory '{$cacheDir}' not found or not a directory" ); } elseif (!is_writable($cacheDir)) { throw new Exception\InvalidArgumentException( "Cache directory '{$cacheDir}' not writable" ); } elseif (!is_readable($cacheDir)) { throw new Exception\InvalidArgumentException( "Cache directory '{$cacheDir}' not readable" ); } $cacheDir = rtrim(realpath($cacheDir), DIRECTORY_SEPARATOR); } else { $cacheDir = sys_get_temp_dir(); } $this->triggerOptionEvent('cache_dir', $cacheDir); $this->cacheDir = $cacheDir; return $this; } /** * Get cache dir * * @return null|string */ public function getCacheDir() { if ($this->cacheDir === null) { $this->setCacheDir(null); } return $this->cacheDir; } /** * Set clear stat cache * * @param bool $clearStatCache * @return FilesystemOptions */ public function setClearStatCache($clearStatCache) { $clearStatCache = (bool) $clearStatCache; $this->triggerOptionEvent('clear_stat_cache', $clearStatCache); $this->clearStatCache = $clearStatCache; return $this; } /** * Get clear stat cache * * @return bool */ public function getClearStatCache() { return $this->clearStatCache; } /** * Set dir level * * @param int $dirLevel * @return FilesystemOptions * @throws Exception\InvalidArgumentException */ public function setDirLevel($dirLevel) { $dirLevel = (int) $dirLevel; if ($dirLevel < 0 || $dirLevel > 16) { throw new Exception\InvalidArgumentException( "Directory level '{$dirLevel}' must be between 0 and 16" ); } $this->triggerOptionEvent('dir_level', $dirLevel); $this->dirLevel = $dirLevel; return $this; } /** * Get dir level * * @return int */ public function getDirLevel() { return $this->dirLevel; } /** * Set permission to create directories on unix systems * * @param false|string|int $dirPermission FALSE to disable explicit permission or an octal number * @return FilesystemOptions * @see setUmask * @see setFilePermission * @link http://php.net/manual/function.chmod.php */ public function setDirPermission($dirPermission) { if ($dirPermission !== false) { if (is_string($dirPermission)) { $dirPermission = octdec($dirPermission); } else { $dirPermission = (int) $dirPermission; } // validate if (($dirPermission & 0700) != 0700) { throw new Exception\InvalidArgumentException( 'Invalid directory permission: need permission to execute, read and write by owner' ); } } if ($this->dirPermission !== $dirPermission) { $this->triggerOptionEvent('dir_permission', $dirPermission); $this->dirPermission = $dirPermission; } return $this; } /** * Get permission to create directories on unix systems * * @return false|int */ public function getDirPermission() { return $this->dirPermission; } /** * Set file locking * * @param bool $fileLocking * @return FilesystemOptions */ public function setFileLocking($fileLocking) { $fileLocking = (bool) $fileLocking; $this->triggerOptionEvent('file_locking', $fileLocking); $this->fileLocking = $fileLocking; return $this; } /** * Get file locking * * @return bool */ public function getFileLocking() { return $this->fileLocking; } /** * Set permission to create files on unix systems * * @param false|string|int $filePermission FALSE to disable explicit permission or an octal number * @return FilesystemOptions * @see setUmask * @see setDirPermission * @link http://php.net/manual/function.chmod.php */ public function setFilePermission($filePermission) { if ($filePermission !== false) { if (is_string($filePermission)) { $filePermission = octdec($filePermission); } else { $filePermission = (int) $filePermission; } // validate if (($filePermission & 0600) != 0600) { throw new Exception\InvalidArgumentException( 'Invalid file permission: need permission to read and write by owner' ); } elseif ($filePermission & 0111) { throw new Exception\InvalidArgumentException( "Invalid file permission: Cache files shoudn't be executable" ); } } if ($this->filePermission !== $filePermission) { $this->triggerOptionEvent('file_permission', $filePermission); $this->filePermission = $filePermission; } return $this; } /** * Get permission to create files on unix systems * * @return false|int */ public function getFilePermission() { return $this->filePermission; } /** * Set namespace separator * * @param string $namespaceSeparator * @return FilesystemOptions */ public function setNamespaceSeparator($namespaceSeparator) { $namespaceSeparator = (string) $namespaceSeparator; $this->triggerOptionEvent('namespace_separator', $namespaceSeparator); $this->namespaceSeparator = $namespaceSeparator; return $this; } /** * Get namespace separator * * @return string */ public function getNamespaceSeparator() { return $this->namespaceSeparator; } /** * Set no atime * * @param bool $noAtime * @return FilesystemOptions */ public function setNoAtime($noAtime) { $noAtime = (bool) $noAtime; $this->triggerOptionEvent('no_atime', $noAtime); $this->noAtime = $noAtime; return $this; } /** * Get no atime * * @return bool */ public function getNoAtime() { return $this->noAtime; } /** * Set no ctime * * @param bool $noCtime * @return FilesystemOptions */ public function setNoCtime($noCtime) { $noCtime = (bool) $noCtime; $this->triggerOptionEvent('no_ctime', $noCtime); $this->noCtime = $noCtime; return $this; } /** * Get no ctime * * @return bool */ public function getNoCtime() { return $this->noCtime; } /** * Set the umask to create files and directories on unix systems * * Note: On multithreaded webservers it's better to explicit set file and dir permission. * * @param false|string|int $umask FALSE to disable umask or an octal number * @return FilesystemOptions * @see setFilePermission * @see setDirPermission * @link http://php.net/manual/function.umask.php * @link http://en.wikipedia.org/wiki/Umask */ public function setUmask($umask) { if ($umask !== false) { if (is_string($umask)) { $umask = octdec($umask); } else { $umask = (int) $umask; } // validate if ($umask & 0700) { throw new Exception\InvalidArgumentException( 'Invalid umask: need permission to execute, read and write by owner' ); } // normalize $umask = $umask & 0777; } if ($this->umask !== $umask) { $this->triggerOptionEvent('umask', $umask); $this->umask = $umask; } return $this; } /** * Get the umask to create files and directories on unix systems * * @return false|int */ public function getUmask() { return $this->umask; } } |