-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SimpleCache collector/decorator - support all versions of interface
- Loading branch information
Showing
10 changed files
with
620 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPDebugConsole | ||
* | ||
* @package PHPDebugConsole | ||
* @author Brad Kent <bkfake-github@yahoo.com> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2014-2024 Brad Kent | ||
* @since 3.3 | ||
*/ | ||
|
||
namespace bdk\Debug\Collector\SimpleCache; | ||
|
||
$refClass = new \ReflectionClass('Psr\SimpleCache\CacheInterface'); | ||
$refMethod = $refClass->getMethod('get'); | ||
$refParameters = $refMethod->getParameters(); | ||
|
||
if (\method_exists($refMethod, 'hasReturnType') && $refMethod->hasReturnType()) { | ||
// psr/simple-cache 3.0 | ||
require __DIR__ . '/CompatTrait_3.php'; | ||
} elseif (\method_exists($refParameters[0], 'hasType') && $refParameters[0]->hasType()) { | ||
// psr/simple-cache 2.0 | ||
require __DIR__ . '/CompatTrait_2.php'; | ||
} elseif (\trait_exists(__NAMESPACE__ . '\\CompatTrait', false) === false) { | ||
// psr/simple-cache 1.0 | ||
require __DIR__ . '/CompatTrait_1.php'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPDebugConsole | ||
* | ||
* @package PHPDebugConsole | ||
* @author Brad Kent <bkfake-github@yahoo.com> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2014-2024 Brad Kent | ||
* @since 3.3 | ||
*/ | ||
|
||
namespace bdk\Debug\Collector\SimpleCache; | ||
|
||
/* | ||
Wrap in condition. | ||
PHPUnit code coverage scans all files and will conflict | ||
*/ | ||
if (\trait_exists(__NAMESPACE__ . '\\CompatTrait', false) === false) { | ||
/** | ||
* Provide method signatures compatible with psr/simple-cache 1.x | ||
*/ | ||
trait CompatTrait | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function get($key, $default = null) | ||
{ | ||
return $this->profileCall('get', \func_get_args(), false, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function set($key, $value, $ttl = null) | ||
{ | ||
return $this->profileCall('set', \func_get_args(), true, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function delete($key) | ||
{ | ||
return $this->profileCall('delete', \func_get_args(), false, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function clear() | ||
{ | ||
return $this->profileCall('clear', [], true); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getMultiple($keys, $default = null) | ||
{ | ||
$keysDebug = $this->keysDebug($keys); | ||
return $this->profileCall('getMultiple', \func_get_args(), false, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setMultiple($values, $ttl = null) | ||
{ | ||
$keysDebug = $this->keysDebug($values, true); | ||
return $this->profileCall('setMultiple', \func_get_args(), true, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function deleteMultiple($keys) | ||
{ | ||
$keysDebug = $this->keysDebug($keys); | ||
return $this->profileCall('deleteMultiple', \func_get_args(), true, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function has($key) | ||
{ | ||
return $this->profileCall('has', \func_get_args(), false, $key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPDebugConsole | ||
* | ||
* @package PHPDebugConsole | ||
* @author Brad Kent <bkfake-github@yahoo.com> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2014-2024 Brad Kent | ||
* @since 3.3 | ||
*/ | ||
|
||
namespace bdk\Debug\Collector\SimpleCache; | ||
|
||
/* | ||
Wrap in condition. | ||
PHPUnit code coverage scans all files and will conflict | ||
*/ | ||
if (\trait_exists(__NAMESPACE__ . '\\CompatTrait', false) === false) { | ||
/** | ||
* Provide method signatures compatible with psr/simple-cache 2.x | ||
*/ | ||
trait CompatTrait | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function get(string $key, mixed $default = null) | ||
{ | ||
return $this->profileCall('get', \func_get_args(), false, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null) | ||
{ | ||
return $this->profileCall('set', \func_get_args(), true, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function delete(string $key) | ||
{ | ||
return $this->profileCall('delete', \func_get_args(), false, $key); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function clear() | ||
{ | ||
return $this->profileCall('clear', [], true); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getMultiple(string $keys, mixed $default = null) | ||
{ | ||
$keysDebug = $this->keysDebug($keys); | ||
return $this->profileCall('getMultiple', \func_get_args(), false, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null) | ||
{ | ||
$keysDebug = $this->keysDebug($values, true); | ||
return $this->profileCall('setMultiple', \func_get_args(), true, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function deleteMultiple(iterable $keys) | ||
{ | ||
$keysDebug = $this->keysDebug($keys); | ||
return $this->profileCall('deleteMultiple', \func_get_args(), true, $keysDebug); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function has(string $key) | ||
{ | ||
return $this->profileCall('has', \func_get_args(), false, $key); | ||
} | ||
} | ||
} |
Oops, something went wrong.