Skip to content

Commit

Permalink
Preserve BC
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 16, 2024
1 parent 2cd7d77 commit 9780aa0
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/Utility/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Cache {
/**
* @var array
*/
protected static $_defaultConfig = [
'cache' => '_cake_translations_',
protected static array $_defaultConfig = [
'cache' => '_cake_model_',
'cachePrefix' => 'tiny_auth_',
'allowCacheKey' => self::KEY_ALLOW,
'aclCacheKey' => self::KEY_ACL,
Expand All @@ -41,7 +41,7 @@ class Cache {
*
* @return void
*/
public static function clear($type = null) {
public static function clear(?string $type = null): void {
$config = static::prepareConfig();
static::assertValidCacheSetup($config);

Expand All @@ -62,7 +62,7 @@ public static function clear($type = null) {
*
* @return void
*/
public static function write($type, $data) {
public static function write(string $type, array $data): void {
$config = static::prepareConfig();

CoreCache::write(static::key($type), $data, $config['cache']);
Expand All @@ -73,18 +73,18 @@ public static function write($type, $data) {
*
* @return array|null
*/
public static function read($type) {
public static function read(string $type): ?array {
$config = static::prepareConfig();

return CoreCache::read(static::key($type), $config['cache']) ?: null;
}

/**
* @param string $type
* @throws \Cake\Core\Exception\CakeException
*@throws \Cake\Core\Exception\CakeException
* @return string
*/
public static function key($type) {
public static function key(string $type): string {
$config = static::prepareConfig();

static::assertValidCacheSetup($config);
Expand All @@ -102,7 +102,7 @@ public static function key($type) {
* @throws \Cake\Core\Exception\CakeException
* @return void
*/
protected static function assertValidCacheSetup(array $config) {
protected static function assertValidCacheSetup(array $config): void {
if (!in_array($config['cache'], CoreCache::configured(), true)) {
throw new CakeException(sprintf('Invalid or not configured TinyAuth cache `%s`', $config['cache']));
}
Expand All @@ -111,10 +111,16 @@ protected static function assertValidCacheSetup(array $config) {
/**
* @return array
*/
protected static function prepareConfig() {
$config = (array)Configure::read('TinyAuth') + static::$_defaultConfig;
protected static function prepareConfig(): array {
$defaultConfig = static::$_defaultConfig;

//BC with 5.0.x
$configured = CoreCache::getRegistry();
if ($configured->has('_cake_core_')) {
$defaultConfig['cache'] = '_cake_core_';
}

return $config;
return (array)Configure::read('TinyAuth') + $defaultConfig;
}

}

0 comments on commit 9780aa0

Please sign in to comment.