Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

If sys_get_temp_dir() is available and the 'cacheDir' option is not p…

…rovided in the constructor options array its output is used to determine the suitable temporary directory.

Fixes PEAR bug #18328

git-svn-id: http://svn.php.net/repository/pear/packages/Cache_Lite/trunk@308851 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 05374560357068ead6b827ee466ad2c15201df36 1 parent 9da9753
@coderbyheart coderbyheart authored
Showing with 34 additions and 0 deletions.
  1. +11 −0 Lite.php
  2. +23 −0 tests/pearbug18328.phpt
View
11 Lite.php
@@ -273,6 +273,14 @@ class Cache_Lite
* 'hashedDirectoryUmask' => umask for hashed directory structure (int),
* 'errorHandlingAPIBreak' => API break for better error handling ? (boolean)
* );
+ *
+ * If sys_get_temp_dir() is available and the
+ * 'cacheDir' option is not provided in the
+ * constructor options array its output is used
+ * to determine the suitable temporary directory.
+ *
+ * @see http://de.php.net/sys_get_temp_dir
+ * @see http://pear.php.net/bugs/bug.php?id=18328
*
* @param array $options options
* @access public
@@ -282,6 +290,9 @@ function Cache_Lite($options = array(NULL))
foreach($options as $key => $value) {
$this->setOption($key, $value);
}
+ if (!isset($options['cacheDir']) && function_exists('sys_get_temp_dir')) {
+ $this->setOption('cacheDir', sys_get_temp_dir() . DIRECTORY_SEPARATOR);
+ }
}
/**
View
23 tests/pearbug18328.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Cache_Lite::Cache_Lite (PEAR bug #18328)
+--FILE--
+<?php
+
+/**
+ * Process for test pearbug18328
+ *
+ * @see https://pear.php.net/bugs/bug.php?id=18328
+ * @author Markus Tacker <tacker@php.net>
+ */
+
+require_once 'Cache/Lite.php';
+$c = new Cache_Lite(array('cacheDir' => '.', 'lifeTime' => 60,));
+var_dump($c->_cacheDir === '.');
+$c = new Cache_Lite(array('lifeTime' => 60));
+var_dump($c->_cacheDir === (function_exists('sys_get_temp_dir') ? sys_get_temp_dir() . DIRECTORY_SEPARATOR : '/tmp/'));
+
+--GET--
+--POST--
+--EXPECT--
+bool(true)
+bool(true)
Please sign in to comment.
Something went wrong with that request. Please try again.