mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-30 12:48:21 +02:00
[ticket/16955] Add stubs for cache classes and clean up
PHPBB3-16955
This commit is contained in:
parent
b855b8a5a5
commit
83cb41e72a
24
build/psalm/stubs/apcu/apcu.php
Normal file
24
build/psalm/stubs/apcu/apcu.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class APCUIterator implements Iterator
|
||||
{
|
||||
public function current()
|
||||
{
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
}
|
||||
}
|
20
build/psalm/stubs/memcached/memcached.php
Normal file
20
build/psalm/stubs/memcached/memcached.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @link https://www.php.net/manual/en/memcached.constants.php */
|
||||
class Memcached
|
||||
{
|
||||
public const OPT_COMPRESSION = -1001;
|
||||
|
||||
public const OPT_BINARY_PROTOCOL = 18;
|
||||
}
|
21
build/psalm/stubs/redis/redis.php
Normal file
21
build/psalm/stubs/redis/redis.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @link https://phpredis.github.io/phpredis/Redis.html */
|
||||
class Redis
|
||||
{
|
||||
public const OPT_PREFIX = 2;
|
||||
|
||||
public const SERIALIZER_PHP = 1;
|
||||
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class SQLite3
|
||||
{
|
||||
public function query(string $query) {}
|
||||
|
28
phpBB/phpbb/cache/driver/apcu.php
vendored
28
phpBB/phpbb/cache/driver/apcu.php
vendored
@ -38,39 +38,25 @@ class apcu extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _read($var)
|
||||
protected function _read(string $var)
|
||||
{
|
||||
return apcu_fetch($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
protected function _write(string $var, $data, int $ttl = 2592000): bool
|
||||
{
|
||||
return apcu_store($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _delete(string $var): bool
|
||||
{
|
||||
return apcu_delete($this->key_prefix . $var);
|
||||
}
|
||||
|
11
phpBB/phpbb/cache/driver/base.php
vendored
11
phpBB/phpbb/cache/driver/base.php
vendored
@ -199,7 +199,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*
|
||||
* @param string $dir Directory to remove
|
||||
*
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
protected function remove_dir($dir)
|
||||
{
|
||||
@ -231,4 +231,13 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
*
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
abstract protected function _read(string $var);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ interface driver_interface
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return int|bool Query ID (integer) if cache contains a rowset
|
||||
* @return string|false Query ID (md5 of query) if cache contains a rowset
|
||||
* for the specified query.
|
||||
* False otherwise.
|
||||
*/
|
||||
|
8
phpBB/phpbb/cache/driver/dummy.php
vendored
8
phpBB/phpbb/cache/driver/dummy.php
vendored
@ -95,6 +95,14 @@ class dummy extends \phpbb\cache\driver\base
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
12
phpBB/phpbb/cache/driver/file.php
vendored
12
phpBB/phpbb/cache/driver/file.php
vendored
@ -331,17 +331,13 @@ class file extends \phpbb\cache\driver\base
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cached data from a specified file
|
||||
*
|
||||
* @access private
|
||||
* @param string $filename Filename to write
|
||||
* @return mixed False if an error was encountered, otherwise the data type of the cached data
|
||||
*/
|
||||
function _read($filename)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
global $phpEx;
|
||||
|
||||
$filename = $this->clean_varname($filename);
|
||||
$filename = $this->clean_varname($var);
|
||||
$file = "{$this->cache_dir}$filename.$phpEx";
|
||||
|
||||
$type = substr($filename, 0, strpos($filename, '_'));
|
||||
|
28
phpBB/phpbb/cache/driver/memcached.php
vendored
28
phpBB/phpbb/cache/driver/memcached.php
vendored
@ -37,7 +37,7 @@ if (!defined('PHPBB_ACM_MEMCACHED'))
|
||||
/**
|
||||
* ACM for Memcached
|
||||
*/
|
||||
class memcached extends \phpbb\cache\driver\memory
|
||||
class memcached extends memory
|
||||
{
|
||||
/** @var string Extension to use */
|
||||
protected $extension = 'memcached';
|
||||
@ -107,26 +107,17 @@ class memcached extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
*
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
protected function _read($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
return $this->memcached->get($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _write($var, $data, $ttl = 2592000)
|
||||
protected function _write(string $var, $data, int $ttl = 2592000): bool
|
||||
{
|
||||
if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl))
|
||||
{
|
||||
@ -136,12 +127,9 @@ class memcached extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _delete($var)
|
||||
protected function _delete(string $var): bool
|
||||
{
|
||||
return $this->memcached->delete($this->key_prefix . $var);
|
||||
}
|
||||
|
24
phpBB/phpbb/cache/driver/memory.php
vendored
24
phpBB/phpbb/cache/driver/memory.php
vendored
@ -270,13 +270,33 @@ abstract class memory extends \phpbb\cache\driver\base
|
||||
/**
|
||||
* Check if a cache var exists
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
*
|
||||
* @return bool True if it exists, otherwise false
|
||||
*/
|
||||
function _isset($var)
|
||||
protected function _isset(string $var): bool
|
||||
{
|
||||
// Most caches don't need to check
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
*
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
abstract protected function _delete(string $var): bool;
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
*
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
abstract protected function _write(string $var, $data, int $ttl = 2592000): bool;
|
||||
}
|
||||
|
30
phpBB/phpbb/cache/driver/redis.php
vendored
30
phpBB/phpbb/cache/driver/redis.php
vendored
@ -115,27 +115,17 @@ class redis extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
return $this->redis->get($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
protected function _write(string $var, $data, int $ttl = 2592000): bool
|
||||
{
|
||||
if ($ttl == 0)
|
||||
{
|
||||
@ -145,13 +135,9 @@ class redis extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _delete(string $var): bool
|
||||
{
|
||||
if ($this->redis->delete($var) > 0)
|
||||
{
|
||||
|
30
phpBB/phpbb/cache/driver/wincache.php
vendored
30
phpBB/phpbb/cache/driver/wincache.php
vendored
@ -31,13 +31,9 @@ class wincache extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
$success = false;
|
||||
$result = wincache_ucache_get($this->key_prefix . $var, $success);
|
||||
@ -46,27 +42,17 @@ class wincache extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
protected function _write(string $var, $data, int $ttl = 2592000): bool
|
||||
{
|
||||
return wincache_ucache_set($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _delete(string $var): bool
|
||||
{
|
||||
return wincache_ucache_delete($this->key_prefix . $var);
|
||||
}
|
||||
|
@ -22,8 +22,11 @@
|
||||
</issueHandlers>
|
||||
|
||||
<stubs>
|
||||
<file name="build/psalm/stubs/apcu/apcu.php"/>
|
||||
<file name="build/psalm/stubs/memcached/memcached.php"/>
|
||||
<file name="build/psalm/stubs/oci8/oci8.php"/>
|
||||
<file name="build/psalm/stubs/pgsql/pgsql.php"/>
|
||||
<file name="build/psalm/stubs/redis/redis.php"/>
|
||||
<file name="build/psalm/stubs/sqlite3/sqlite3.php"/>
|
||||
</stubs>
|
||||
</psalm>
|
||||
|
30
tests/cache/cache_memory.php
vendored
30
tests/cache/cache_memory.php
vendored
@ -23,40 +23,26 @@ class phpbb_cache_memory extends \phpbb\cache\driver\memory
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _read(string $var)
|
||||
{
|
||||
return $this->data[$var] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
protected function _write(string $var, $data, int $ttl = 2592000): bool
|
||||
{
|
||||
$this->data[$var] = $data;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _delete(string $var): bool
|
||||
{
|
||||
unset($this->data[$var]);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user