initial commit; version 22.5.12042

This commit is contained in:
2022-12-12 23:28:25 -05:00
commit af1b03d79f
17653 changed files with 22692970 additions and 0 deletions

View File

@ -0,0 +1,488 @@
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Helper;
use phpFastCache\CacheManager;
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
use phpFastCache\EventManager;
use Psr\Cache\CacheItemInterface;
/**
* Class ActOnAll
* @package phpFastCache\Helper
*/
class ActOnAll implements ExtendedCacheItemPoolInterface
{
/**
* @var ExtendedCacheItemPoolInterface[]
*/
protected $instances = [];
/**
* ActOnAll constructor.
*/
public function __construct()
{
$this->instances =& CacheManager::getInternalInstances();
}
/**
* @return \Closure
*/
protected function getGenericCallback()
{
return function ($method, $args) {
$getterMethod = (strpos($method, 'get') === 0);
$return = false;
if ($getterMethod) {
$return = [];
}
foreach ($this->instances as $instance) {
$reflectionMethod = new \ReflectionMethod(get_class($instance), $method);
if ($getterMethod) {
$return[ $instance->getDriverName() ] = $reflectionMethod->invokeArgs($instance, $args);
} else {
$result = $reflectionMethod->invokeArgs($instance, $args);
if ($result !== false) {
$return = $result;
}
}
}
return $return;
};
}
/**
* @param string $key
* @return mixed
*/
public function hasItem($key)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function clear()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $key
* @return mixed
*/
public function deleteItem($key)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $keys
* @return mixed
*/
public function deleteItems(array $keys)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function save(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function saveDeferred(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array ...$items
* @return mixed
*/
public function saveMultiple(...$items)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function commit()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function getConfig()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function getConfigOption($optionName)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function getDriverName()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $key
* @return mixed
*/
public function getItem($key)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $keys
* @return mixed
*/
public function getItems(array $keys = [])
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $keys
* @param int $option
* @param int $depth
* @return mixed
*/
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function setItem(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function getHelp()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function getStats()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @return mixed
*/
public function getItemsByTag($tagName)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @return mixed
*/
public function getItemsByTags(array $tagNames)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param int $option
* @param int $depth
* @return mixed
*/
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @return mixed
*/
public function deleteItemsByTag($tagName)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @return mixed
*/
public function deleteItemsByTags(array $tagNames)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @param int $step
* @return mixed
*/
public function incrementItemsByTag($tagName, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param int $step
* @return mixed
*/
public function incrementItemsByTags(array $tagNames, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @param int $step
* @return mixed
*/
public function decrementItemsByTag($tagName, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param int $step
* @return mixed
*/
public function decrementItemsByTags(array $tagNames, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @param array|string $data
* @return mixed
*/
public function appendItemsByTag($tagName, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param array|string $data
* @return mixed
*/
public function appendItemsByTags(array $tagNames, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param string $tagName
* @param array|string $data
* @return mixed
*/
public function prependItemsByTag($tagName, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param array|string $data
* @return mixed
*/
public function prependItemsByTags(array $tagNames, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @return mixed
*/
public function getItemsByTagsAll(array $tagNames)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @return mixed
*/
public function deleteItemsByTagsAll(array $tagNames)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param int $step
* @return mixed
*/
public function incrementItemsByTagsAll(array $tagNames, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param int $step
* @return mixed
*/
public function decrementItemsByTagsAll(array $tagNames, $step = 1)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param array|string $data
* @return mixed
*/
public function appendItemsByTagsAll(array $tagNames, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param array $tagNames
* @param array|string $data
* @return mixed
*/
public function prependItemsByTagsAll(array $tagNames, $data)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function detachItem(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @return mixed
*/
public function detachAllItems()
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function attachItem(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function isAttached(CacheItemInterface $item)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
/**
* @param \phpFastCache\EventManager $em
* @return mixed
*/
public function setEventManager(EventManager $em)
{
$callback = $this->getGenericCallback();
return $callback(__FUNCTION__, func_get_args());
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Helper;
use Psr\Cache\CacheItemPoolInterface;
/**
* Class CacheConditional
* @package phpFastCache\Helper
*/
class CacheConditionalHelper
{
/**
* @var CacheItemPoolInterface
*/
protected $cacheInstance;
/**
* CachePromise constructor.
* @param CacheItemPoolInterface $cacheInstance
*/
public function __construct(CacheItemPoolInterface $cacheInstance)
{
$this->cacheInstance = $cacheInstance;
}
/**
* @param string $cacheKey
* @param callable $callback
*/
public function get($cacheKey, callable $callback)
{
$cacheItem = $this->cacheInstance->getItem($cacheKey);
if (!$cacheItem->isHit()) {
$cacheItem->set($callback());
$this->cacheInstance->save($cacheItem);
}
return $cacheItem->get();
}
}

View File

@ -0,0 +1,199 @@
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Helper;
use phpFastCache\CacheManager;
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
use phpFastCache\Exceptions\phpFastCacheRootException;
use phpFastCache\Exceptions\phpFastCacheSimpleCacheException;
use Psr\SimpleCache\CacheInterface;
/**
* Class Psr16Adapter
* @package phpFastCache\Helper
*/
class Psr16Adapter implements CacheInterface
{
/**
* @var ExtendedCacheItemPoolInterface
*/
protected $internalCacheInstance;
/**
* Psr16Adapter constructor.
* @param string $driver
* @param array $config
* @throws phpFastCacheDriverCheckException
*/
public function __construct($driver, array $config = [])
{
$this->internalCacheInstance = CacheManager::getInstance($driver, $config);
}
/**
* @param string $key
* @param null $default
* @return mixed|null
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function get($key, $default = null)
{
try {
$cacheItem = $this->internalCacheInstance->getItem($key);
if (!$cacheItem->isExpired() && $cacheItem->get() !== null) {
return $cacheItem->get();
} else {
return $default;
}
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string $key
* @param mixed $value
* @param null $ttl
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function set($key, $value, $ttl = null)
{
try {
$cacheItem = $this->internalCacheInstance
->getItem($key)
->set($value);
if (is_int($ttl) && $ttl <= 0) {
$cacheItem->expiresAt((new \DateTime('@0')));
} elseif (is_int($ttl) || $ttl instanceof \DateInterval) {
$cacheItem->expiresAfter($ttl);
}
return $this->internalCacheInstance->save($cacheItem);
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string $key
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function delete($key)
{
try {
return $this->internalCacheInstance->deleteItem($key);
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function clear()
{
try {
return $this->internalCacheInstance->clear();
} catch (phpFastCacheRootException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string[] $keys
* @param null $default
* @return \iterable
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function getMultiple($keys, $default = null)
{
if ($keys instanceof \Traversable) {
$keys = \iterator_to_array($keys);
}
try {
return array_map(function (ExtendedCacheItemInterface $item) {
return $item->get();
}, $this->internalCacheInstance->getItems($keys));
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string[] $values
* @param null|int|\DateInterval $ttl
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function setMultiple($values, $ttl = null)
{
try {
foreach ($values as $key => $value) {
$cacheItem = $this->internalCacheInstance->getItem($key)->set($value);
if (is_int($ttl) && $ttl <= 0) {
$cacheItem->expiresAt((new \DateTime('@0')));
} elseif (is_int($ttl) || $ttl instanceof \DateInterval) {
$cacheItem->expiresAfter($ttl);
}
$this->internalCacheInstance->saveDeferred($cacheItem);
unset($cacheItem);
}
return $this->internalCacheInstance->commit();
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string[] $keys
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function deleteMultiple($keys)
{
try {
if ($keys instanceof \Traversable) {
return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
} elseif (is_array($keys)) {
return $this->internalCacheInstance->deleteItems($keys);
} else {
throw new phpFastCacheInvalidArgumentException('$keys must be an array/Traversable instance.');
}
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
/**
* @param string $key
* @return bool
* @throws \phpFastCache\Exceptions\phpFastCacheSimpleCacheException
*/
public function has($key)
{
try {
$cacheItem = $this->internalCacheInstance->getItem($key);
return $cacheItem->isHit() && !$cacheItem->isExpired();
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
}
}

View File

@ -0,0 +1,164 @@
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Helper;
use phpFastCache\Api;
/**
* Class TestHelper
* @package phpFastCache\Helper
*/
class TestHelper
{
/**
* @var int
*/
protected $exitCode = 0;
/**
* TestHelper constructor.
* @param $testName
*/
public function __construct($testName)
{
$this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true);
$this->printText("[Begin Test: '{$testName}']");
$this->printText('---');
}
/**
* @return int
*/
public function getExitCode()
{
return $this->exitCode;
}
/**
* @return $this
*/
public function resetExitCode()
{
$this->exitCode = 0;
return $this;
}
/**
* @param string $string
* @return $this
*/
public function printSkipText($string)
{
$this->printText("[SKIP] {$string}");
return $this;
}
/**
* @param string $string
* @return $this
*/
public function printPassText($string)
{
$this->printText("[PASS] {$string}");
return $this;
}
/**
* @param string $string
* @return $this
*/
public function printFailText($string)
{
$this->printText("[FAIL] {$string}");
$this->exitCode = 1;
return $this;
}
/**
* @param int $count
* @return $this
*/
public function printNewLine($count = 1)
{
for ($i = 0; $i < $count; $i++) {
print PHP_EOL;
}
return $this;
}
/**
* @param $string
* @param bool $strtoupper
* @return $this
*/
public function printText($string, $strtoupper = false)
{
if (!$strtoupper) {
print trim($string) . PHP_EOL;
} else {
print strtoupper(trim($string) . PHP_EOL);
}
return $this;
}
/**
* @param string $cmd
*/
public function runAsyncProcess($cmd)
{
if (substr(php_uname(), 0, 7) === 'Windows') {
pclose(popen('start /B ' . $cmd, 'r'));
} else {
exec($cmd . ' > /dev/null &');
}
}
/**
* @param string $file
* @param string $ext
*/
public function runSubProcess($file, $ext = '.php')
{
$this->runAsyncProcess('php ' . getcwd() . DIRECTORY_SEPARATOR . 'subprocess' . DIRECTORY_SEPARATOR . $file . '.subprocess' . $ext);
}
/**
* @return void
*/
public function terminateTest()
{
exit($this->exitCode);
}
/**
* @param $obj
* @param $prop
* @return mixed
* @throws \ReflectionException
*/
public function accessInaccessibleMember($obj, $prop) {
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return $property->getValue($obj);
}
}