Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Cache / Storage / Adapter / FilesystemOptions.php
blob9dec56c3872359fb92e1423c233b0ae3623b4dec
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Cache\Storage\Adapter;
12 use Traversable;
13 use Zend\Cache\Exception;
15 /**
16 * These are options specific to the Filesystem adapter
18 class FilesystemOptions extends AdapterOptions
21 /**
22 * Directory to store cache files
24 * @var null|string The cache directory
25 * or NULL for the systems temporary directory
27 protected $cacheDir = null;
29 /**
30 * Call clearstatcache enabled?
32 * @var bool
34 protected $clearStatCache = true;
36 /**
37 * How much sub-directaries should be created?
39 * @var int
41 protected $dirLevel = 1;
43 /**
44 * Permission creating new directories
46 * @var false|int
48 protected $dirPermission = 0700;
50 /**
51 * Lock files on writing
53 * @var bool
55 protected $fileLocking = true;
57 /**
58 * Permission creating new files
60 * @var false|int
62 protected $filePermission = 0600;
64 /**
65 * Overwrite default key pattern
67 * Defined in AdapterOptions
69 * @var string
71 protected $keyPattern = '/^[a-z0-9_\+\-]*$/Di';
73 /**
74 * Namespace separator
76 * @var string
78 protected $namespaceSeparator = '-';
80 /**
81 * Don't get 'fileatime' as 'atime' on metadata
83 * @var bool
85 protected $noAtime = true;
87 /**
88 * Don't get 'filectime' as 'ctime' on metadata
90 * @var bool
92 protected $noCtime = true;
94 /**
95 * Umask to create files and directories
97 * @var false|int
99 protected $umask = false;
102 * Constructor
104 * @param array|Traversable|null $options
105 * @return FilesystemOptions
106 * @throws Exception\InvalidArgumentException
108 public function __construct($options = null)
110 // disable file/directory permissions by default on windows systems
111 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
112 $this->filePermission = false;
113 $this->dirPermission = false;
116 parent::__construct($options);
120 * Set cache dir
122 * @param string $cacheDir
123 * @return FilesystemOptions
124 * @throws Exception\InvalidArgumentException
126 public function setCacheDir($cacheDir)
128 if ($cacheDir !== null) {
129 if (!is_dir($cacheDir)) {
130 throw new Exception\InvalidArgumentException(
131 "Cache directory '{$cacheDir}' not found or not a directory"
133 } elseif (!is_writable($cacheDir)) {
134 throw new Exception\InvalidArgumentException(
135 "Cache directory '{$cacheDir}' not writable"
137 } elseif (!is_readable($cacheDir)) {
138 throw new Exception\InvalidArgumentException(
139 "Cache directory '{$cacheDir}' not readable"
143 $cacheDir = rtrim(realpath($cacheDir), DIRECTORY_SEPARATOR);
144 } else {
145 $cacheDir = sys_get_temp_dir();
148 $this->triggerOptionEvent('cache_dir', $cacheDir);
149 $this->cacheDir = $cacheDir;
150 return $this;
154 * Get cache dir
156 * @return null|string
158 public function getCacheDir()
160 if ($this->cacheDir === null) {
161 $this->setCacheDir(null);
164 return $this->cacheDir;
168 * Set clear stat cache
170 * @param bool $clearStatCache
171 * @return FilesystemOptions
173 public function setClearStatCache($clearStatCache)
175 $clearStatCache = (bool) $clearStatCache;
176 $this->triggerOptionEvent('clear_stat_cache', $clearStatCache);
177 $this->clearStatCache = $clearStatCache;
178 return $this;
182 * Get clear stat cache
184 * @return bool
186 public function getClearStatCache()
188 return $this->clearStatCache;
192 * Set dir level
194 * @param int $dirLevel
195 * @return FilesystemOptions
196 * @throws Exception\InvalidArgumentException
198 public function setDirLevel($dirLevel)
200 $dirLevel = (int) $dirLevel;
201 if ($dirLevel < 0 || $dirLevel > 16) {
202 throw new Exception\InvalidArgumentException(
203 "Directory level '{$dirLevel}' must be between 0 and 16"
206 $this->triggerOptionEvent('dir_level', $dirLevel);
207 $this->dirLevel = $dirLevel;
208 return $this;
212 * Get dir level
214 * @return int
216 public function getDirLevel()
218 return $this->dirLevel;
222 * Set permission to create directories on unix systems
224 * @param false|string|int $dirPermission FALSE to disable explicit permission or an octal number
225 * @return FilesystemOptions
226 * @see setUmask
227 * @see setFilePermission
228 * @link http://php.net/manual/function.chmod.php
230 public function setDirPermission($dirPermission)
232 if ($dirPermission !== false) {
233 if (is_string($dirPermission)) {
234 $dirPermission = octdec($dirPermission);
235 } else {
236 $dirPermission = (int) $dirPermission;
239 // validate
240 if (($dirPermission & 0700) != 0700) {
241 throw new Exception\InvalidArgumentException(
242 'Invalid directory permission: need permission to execute, read and write by owner'
247 if ($this->dirPermission !== $dirPermission) {
248 $this->triggerOptionEvent('dir_permission', $dirPermission);
249 $this->dirPermission = $dirPermission;
252 return $this;
256 * Get permission to create directories on unix systems
258 * @return false|int
260 public function getDirPermission()
262 return $this->dirPermission;
266 * Set file locking
268 * @param bool $fileLocking
269 * @return FilesystemOptions
271 public function setFileLocking($fileLocking)
273 $fileLocking = (bool) $fileLocking;
274 $this->triggerOptionEvent('file_locking', $fileLocking);
275 $this->fileLocking = $fileLocking;
276 return $this;
280 * Get file locking
282 * @return bool
284 public function getFileLocking()
286 return $this->fileLocking;
290 * Set permission to create files on unix systems
292 * @param false|string|int $filePermission FALSE to disable explicit permission or an octal number
293 * @return FilesystemOptions
294 * @see setUmask
295 * @see setDirPermission
296 * @link http://php.net/manual/function.chmod.php
298 public function setFilePermission($filePermission)
300 if ($filePermission !== false) {
301 if (is_string($filePermission)) {
302 $filePermission = octdec($filePermission);
303 } else {
304 $filePermission = (int) $filePermission;
307 // validate
308 if (($filePermission & 0600) != 0600) {
309 throw new Exception\InvalidArgumentException(
310 'Invalid file permission: need permission to read and write by owner'
312 } elseif ($filePermission & 0111) {
313 throw new Exception\InvalidArgumentException(
314 "Invalid file permission: Cache files shoudn't be executable"
319 if ($this->filePermission !== $filePermission) {
320 $this->triggerOptionEvent('file_permission', $filePermission);
321 $this->filePermission = $filePermission;
324 return $this;
328 * Get permission to create files on unix systems
330 * @return false|int
332 public function getFilePermission()
334 return $this->filePermission;
338 * Set namespace separator
340 * @param string $namespaceSeparator
341 * @return FilesystemOptions
343 public function setNamespaceSeparator($namespaceSeparator)
345 $namespaceSeparator = (string) $namespaceSeparator;
346 $this->triggerOptionEvent('namespace_separator', $namespaceSeparator);
347 $this->namespaceSeparator = $namespaceSeparator;
348 return $this;
352 * Get namespace separator
354 * @return string
356 public function getNamespaceSeparator()
358 return $this->namespaceSeparator;
362 * Set no atime
364 * @param bool $noAtime
365 * @return FilesystemOptions
367 public function setNoAtime($noAtime)
369 $noAtime = (bool) $noAtime;
370 $this->triggerOptionEvent('no_atime', $noAtime);
371 $this->noAtime = $noAtime;
372 return $this;
376 * Get no atime
378 * @return bool
380 public function getNoAtime()
382 return $this->noAtime;
386 * Set no ctime
388 * @param bool $noCtime
389 * @return FilesystemOptions
391 public function setNoCtime($noCtime)
393 $noCtime = (bool) $noCtime;
394 $this->triggerOptionEvent('no_ctime', $noCtime);
395 $this->noCtime = $noCtime;
396 return $this;
400 * Get no ctime
402 * @return bool
404 public function getNoCtime()
406 return $this->noCtime;
410 * Set the umask to create files and directories on unix systems
412 * Note: On multithreaded webservers it's better to explicit set file and dir permission.
414 * @param false|string|int $umask FALSE to disable umask or an octal number
415 * @return FilesystemOptions
416 * @see setFilePermission
417 * @see setDirPermission
418 * @link http://php.net/manual/function.umask.php
419 * @link http://en.wikipedia.org/wiki/Umask
421 public function setUmask($umask)
423 if ($umask !== false) {
424 if (is_string($umask)) {
425 $umask = octdec($umask);
426 } else {
427 $umask = (int) $umask;
430 // validate
431 if ($umask & 0700) {
432 throw new Exception\InvalidArgumentException(
433 'Invalid umask: need permission to execute, read and write by owner'
437 // normalize
438 $umask = $umask & 0777;
441 if ($this->umask !== $umask) {
442 $this->triggerOptionEvent('umask', $umask);
443 $this->umask = $umask;
446 return $this;
450 * Get the umask to create files and directories on unix systems
452 * @return false|int
454 public function getUmask()
456 return $this->umask;