Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ vendor/
/phpstan.neon
# PHPStan cache directory
/.phpstan.cache/

# Added by horde-components QC --fix-qc-issues
# Horde installer plugin runtime data
/var/
# Horde installer plugin web-accessible directory
/web/
19 changes: 11 additions & 8 deletions lib/Horde/Cache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 1999-2017 Horde LLC (http://www.horde.org/)
* Copyright 1999-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -31,10 +32,10 @@ class Horde_Cache
*
* @var array
*/
protected $_params = array(
protected $_params = [
'compress' => false,
'lifetime' => 86400
);
'lifetime' => 86400,
];

/**
* Logger.
Expand Down Expand Up @@ -63,9 +64,10 @@ class Horde_Cache
* - logger: (Horde_Log_Logger) Log object to use for log/debug messages.
* </pre>
*/
public function __construct(Horde_Cache_Storage_Base $storage,
array $params = array())
{
public function __construct(
Horde_Cache_Storage_Base $storage,
array $params = []
) {
if (isset($params['logger'])) {
$this->_logger = $params['logger'];
unset($params['logger']);
Expand Down Expand Up @@ -197,7 +199,8 @@ public function testReadWrite()
$this->_storage->expire($key);
return true;
}
} catch (Exception $e) {}
} catch (Exception $e) {
}

return false;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Horde/Cache/Exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2010-2017 Horde LLC (http://www.horde.org/)
* Copyright 2010-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand All @@ -20,6 +21,4 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @package Cache
*/
class Horde_Cache_Exception extends Horde_Exception_Wrapped
{
}
class Horde_Cache_Exception extends Horde_Exception_Wrapped {}
9 changes: 5 additions & 4 deletions lib/Horde/Cache/Storage/Apc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2006-2017 Horde LLC (http://www.horde.org/)
* Copyright 2006-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -31,11 +32,11 @@ class Horde_Cache_Storage_Apc extends Horde_Cache_Storage_Base
* DEFAULT: ''
* </pre>
*/
public function __construct(array $params = array())
public function __construct(array $params = [])
{
parent::__construct(array_merge(array(
parent::__construct(array_merge([
'prefix' => '',
), $params));
], $params));
}

/**
Expand Down
23 changes: 11 additions & 12 deletions lib/Horde/Cache/Storage/Base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2010-2017 Horde LLC (http://www.horde.org/)
* Copyright 2010-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -34,14 +35,14 @@ abstract class Horde_Cache_Storage_Base implements Serializable
*
* @var array
*/
protected $_params = array();
protected $_params = [];

/**
* Constructor.
*
* @param array $params Configuration parameters.
*/
public function __construct(array $params = array())
public function __construct(array $params = [])
{
$this->_params = array_merge($this->_params, $params);
$this->_initOb();
Expand All @@ -50,9 +51,7 @@ public function __construct(array $params = array())
/**
* Do initialization tasks.
*/
protected function _initOb()
{
}
protected function _initOb() {}

/**
* Set the logging object.
Expand Down Expand Up @@ -118,29 +117,29 @@ abstract public function clear();
*/
public function serialize()
{
return serialize(array(
return serialize([
$this->_params,
$this->_logger
));
$this->_logger,
]);
}
public function __serialize(): array
{
return [
$this->_params,
$this->_logger
$this->_logger,
];
}

/**
*/
public function unserialize($data)
{
@list($this->_params, $this->_logger) = @unserialize($data);
@[$this->_params, $this->_logger] = @unserialize($data);
$this->_initOb();
}
public function __unserialize(array $data): void
{
list($this->_params, $this->_logger) = $data;
[$this->_params, $this->_logger] = $data;
$this->_initOb();
}

Expand Down
9 changes: 5 additions & 4 deletions lib/Horde/Cache/Storage/Eaccelerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2006-2017 Horde LLC (http://www.horde.org/)
* Copyright 2006-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -33,15 +34,15 @@ class Horde_Cache_Storage_Eaccelerator extends Horde_Cache_Storage_Base
*
* @throws Horde_Cache_Exception
*/
public function __construct(array $params = array())
public function __construct(array $params = [])
{
if (!function_exists('eaccelerator_gc')) {
throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.');
}

parent::__construct(array_merge(array(
parent::__construct(array_merge([
'prefix' => '',
), $params));
], $params));
}

/**
Expand Down
57 changes: 30 additions & 27 deletions lib/Horde/Cache/Storage/File.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use Horde\Util\Util;

/**
* Copyright 1999-2017 Horde LLC (http://www.horde.org/)
* Copyright 1999-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand All @@ -27,14 +30,14 @@
class Horde_Cache_Storage_File extends Horde_Cache_Storage_Base
{
/* Location of the garbage collection data file. */
const GC_FILE = 'horde_cache_gc';
public const GC_FILE = 'horde_cache_gc';

/**
* List of key to filename mappings.
*
* @var array
*/
protected $_file = array();
protected $_file = [];

/**
* Constructor.
Expand All @@ -52,12 +55,12 @@ class Horde_Cache_Storage_File extends Horde_Cache_Storage_Base
* DEFAULT: 0
* </pre>
*/
public function __construct(array $params = array())
public function __construct(array $params = [])
{
$params = array_merge(array(
$params = array_merge([
'prefix' => 'cache_',
'sub' => 0
), $params);
'sub' => 0,
], $params);

if (!isset($params['dir']) || !@is_dir($params['dir'])) {
$params['dir'] = sys_get_temp_dir();
Expand All @@ -74,8 +77,8 @@ public function __destruct()
$c_time = time();

/* Only do garbage collection 0.1% of the time we create an object. */
if (!empty($this->_params['no_gc']) ||
(intval(substr($c_time, -3)) !== 0)) {
if (!empty($this->_params['no_gc'])
|| (intval(substr($c_time, -3)) !== 0)) {
return;
}

Expand Down Expand Up @@ -104,9 +107,9 @@ public function get($key, $lifetime = 0)
public function set($key, $data, $lifetime = 0)
{
$filename = $this->_keyToFile($key, true);
$tmp_file = Horde_Util::getTempFile('HordeCache', true, $this->_params['dir']);
$tmp_file = Util::getTempFile('HordeCache', true, $this->_params['dir']);
if (isset($this->_params['umask'])) {
chmod($tmp_file, 0666 & ~$this->_params['umask']);
chmod($tmp_file, 0o666 & ~$this->_params['umask']);
}

if (file_put_contents($tmp_file, $data) === false) {
Expand All @@ -115,8 +118,8 @@ public function set($key, $data, $lifetime = 0)

@rename($tmp_file, $filename);

if ($lifetime &&
($fp = @fopen(dirname($filename) . '/' . self::GC_FILE, 'a'))) {
if ($lifetime
&& ($fp = @fopen(dirname($filename) . '/' . self::GC_FILE, 'a'))) {
// This may result in duplicate entries in GC_FILE, but we
// will take care of these whenever we do GC and this is quicker
// than having to check every time we access the file.
Expand All @@ -136,8 +139,8 @@ public function exists($key, $lifetime = 0)
/* 0 means no expire.
* Also, If the file was been created after the supplied value,
* the data is valid (fresh). */
if (($lifetime == 0) ||
(time() - $lifetime <= filemtime($filename))) {
if (($lifetime == 0)
|| (time() - $lifetime <= filemtime($filename))) {
return true;
}

Expand Down Expand Up @@ -175,7 +178,7 @@ public function clear()
*/
protected function _getCacheFiles($start = null)
{
$paths = array();
$paths = [];

try {
$it = empty($this->_params['sub'])
Expand All @@ -186,9 +189,9 @@ protected function _getCacheFiles($start = null)
}

foreach ($it as $val) {
if (!$val->isDir() &&
($fname = $val->getFilename()) &&
(strpos($fname, $this->_params['prefix']) === 0)) {
if (!$val->isDir()
&& ($fname = $val->getFilename())
&& (strpos($fname, $this->_params['prefix']) === 0)) {
$paths[$fname] = $val->getPathname();
}
}
Expand Down Expand Up @@ -254,8 +257,8 @@ protected function _gc()
{
$c_time = time();

if (!empty($this->_params['sub']) &&
file_exists($this->_params['dir'] . '/' . self::GC_FILE)) {
if (!empty($this->_params['sub'])
&& file_exists($this->_params['dir'] . '/' . self::GC_FILE)) {
// If we cannot migrate, we cannot GC either, because we expect the
// new format.
try {
Expand All @@ -266,7 +269,7 @@ protected function _gc()
}

foreach ($this->_getGCFiles() as $filename) {
$excepts = array();
$excepts = [];
if (is_readable($filename)) {
$fp = fopen($filename, 'r');
while (!feof($fp) && ($data = fgets($fp))) {
Expand All @@ -276,8 +279,8 @@ protected function _gc()
}

foreach ($this->_getCacheFiles(dirname($filename)) as $pname) {
if (!empty($excepts[$pname]) &&
($c_time > $excepts[$pname])) {
if (!empty($excepts[$pname])
&& ($c_time > $excepts[$pname])) {
@unlink($pname);
unset($excepts[$pname]);
}
Expand All @@ -303,7 +306,7 @@ protected function _migrateGc()
return;
}

$fhs = array();
$fhs = [];
$fp = fopen($filename, 'r');
if (!flock($fp, LOCK_EX)) {
throw new Horde_Cache_Exception('Cannot acquire lock for old garbage collection index');
Expand All @@ -312,7 +315,7 @@ protected function _migrateGc()
// Loops through all cached files from the old index and write their GC
// information to the new GC indexes.
while (!feof($fp) && ($data = fgets($fp))) {
list($path, $time) = explode("\t", trim($data), 2);
[$path, $time] = explode("\t", trim($data), 2);
$dir = dirname($path);
if ($dir == $this->_params['dir']) {
continue;
Expand All @@ -325,7 +328,7 @@ protected function _migrateGc()
foreach ($fhs as $fh) {
fclose($fh);
}
$fhs = array();
$fhs = [];
$fhs[$dir] = @fopen($dir . '/' . self::GC_FILE, 'a');
}
if (!$fhs[$dir]) {
Expand Down
Loading