mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
First steps into removing internal usage of File and Folder class in favor of SPL equivalents
This commit is contained in:
parent
9243f6601a
commit
977f897a85
1 changed files with 34 additions and 36 deletions
70
cake/libs/cache/file.php
vendored
70
cake/libs/cache/file.php
vendored
|
@ -78,19 +78,11 @@ class FileEngine extends CacheEngine {
|
||||||
),
|
),
|
||||||
$settings
|
$settings
|
||||||
));
|
));
|
||||||
if (!isset($this->_File)) {
|
|
||||||
$this->_File =& new File($this->settings['path'] . DS . 'cake');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DIRECTORY_SEPARATOR === '\\') {
|
if (DIRECTORY_SEPARATOR === '\\') {
|
||||||
$this->settings['isWindows'] = true;
|
$this->settings['isWindows'] = true;
|
||||||
}
|
}
|
||||||
|
return $this->_active();
|
||||||
$path = $this->_File->Folder->cd($this->settings['path']);
|
|
||||||
if ($path) {
|
|
||||||
$this->settings['path'] = $path;
|
|
||||||
}
|
|
||||||
return $this->__active();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +107,7 @@ class FileEngine extends CacheEngine {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->_setKey($key) === false) {
|
if ($this->_setKey($key, true) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,12 +126,11 @@ class FileEngine extends CacheEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->settings['lock']) {
|
if ($this->settings['lock']) {
|
||||||
$this->_File->lock = true;
|
//$this->_File->lock = true;
|
||||||
}
|
}
|
||||||
$expires = time() + $duration;
|
$expires = time() + $duration;
|
||||||
$contents = $expires . $lineBreak . $data . $lineBreak;
|
$contents = $expires . $lineBreak . $data . $lineBreak;
|
||||||
$success = $this->_File->write($contents);
|
$success = $this->_File->ftruncate(0) && $this->_File->fwrite($contents);
|
||||||
$this->_File->close();
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,20 +141,27 @@ class FileEngine extends CacheEngine {
|
||||||
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
||||||
*/
|
*/
|
||||||
public function read($key) {
|
public function read($key) {
|
||||||
if ($this->_setKey($key) === false || !$this->_init || !$this->_File->exists()) {
|
if (!$this->_init || $this->_setKey($key) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->settings['lock']) {
|
if ($this->settings['lock']) {
|
||||||
$this->_File->lock = true;
|
//$this->_File->lock = true;
|
||||||
}
|
}
|
||||||
|
$this->_File->rewind();
|
||||||
$time = time();
|
$time = time();
|
||||||
$cachetime = intval($this->_File->read(11));
|
$cachetime = intval($this->_File->current());
|
||||||
|
|
||||||
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
|
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
|
||||||
$this->_File->close();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$data = $this->_File->read(true);
|
|
||||||
|
$data = '';
|
||||||
|
$this->_File->next();
|
||||||
|
while ($this->_File->valid()) {
|
||||||
|
$data .= $this->_File->current();
|
||||||
|
$this->_File->next();
|
||||||
|
}
|
||||||
|
$data = trim($data);
|
||||||
|
|
||||||
if ($data !== '' && !empty($this->settings['serialize'])) {
|
if ($data !== '' && !empty($this->settings['serialize'])) {
|
||||||
if ($this->settings['isWindows']) {
|
if ($this->settings['isWindows']) {
|
||||||
|
@ -171,7 +169,6 @@ class FileEngine extends CacheEngine {
|
||||||
}
|
}
|
||||||
$data = unserialize((string)$data);
|
$data = unserialize((string)$data);
|
||||||
}
|
}
|
||||||
$this->_File->close();
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +182,7 @@ class FileEngine extends CacheEngine {
|
||||||
if ($this->_setKey($key) === false || !$this->_init) {
|
if ($this->_setKey($key) === false || !$this->_init) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $this->_File->delete();
|
return unlink($this->_File->getRealPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,20 +205,19 @@ class FileEngine extends CacheEngine {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($check) {
|
if ($check) {
|
||||||
$mtime = $this->_File->lastChange();
|
$mtime = $this->_File->getMTime();
|
||||||
|
|
||||||
if ($mtime === false || $mtime > $threshold) {
|
if ($mtime > $threshold) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$expires = $this->_File->read(11);
|
$expires = (int)$this->_File->current();
|
||||||
$this->_File->close();
|
|
||||||
|
|
||||||
if ($expires > $now) {
|
if ($expires > $now) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->_File->delete();
|
unlink($this->_File->getRealPath());
|
||||||
}
|
}
|
||||||
$dir->close();
|
$dir->close();
|
||||||
return true;
|
return true;
|
||||||
|
@ -252,27 +248,29 @@ class FileEngine extends CacheEngine {
|
||||||
*
|
*
|
||||||
* @param string $key The key
|
* @param string $key The key
|
||||||
* @return mixed Absolute cache file for the given key or false if erroneous
|
* @return mixed Absolute cache file for the given key or false if erroneous
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function _setKey($key) {
|
protected function _setKey($key, $createKey = false) {
|
||||||
$this->_File->Folder->cd($this->settings['path']);
|
$path = new SplFileInfo($this->settings['path'] . DS . $key);
|
||||||
if ($key !== $this->_File->name) {
|
|
||||||
$this->_File->name = $key;
|
if (!$createKey && !$path->isFile()) {
|
||||||
$this->_File->path = null;
|
|
||||||
}
|
|
||||||
if (!$this->_File->Folder->inPath($this->_File->pwd(), true)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($this->_File) || $this->_File->getBaseName() !== $key) {
|
||||||
|
$this->_File = $path->openFile('a+');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine is cache directory is writable
|
* Determine is cache directory is writable
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function __active() {
|
protected function _active() {
|
||||||
if ($this->_init && !is_writable($this->settings['path'])) {
|
$dir = new SplFileInfo($this->settings['path']);
|
||||||
|
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
|
||||||
$this->_init = false;
|
$this->_init = false;
|
||||||
trigger_error(sprintf(__('%s is not writable'), $this->settings['path']), E_USER_WARNING);
|
trigger_error(sprintf(__('%s is not writable'), $this->settings['path']), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue