Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
6562680 committed May 29, 2024
1 parent daf2e08 commit 497e3d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
24 changes: 12 additions & 12 deletions src/Reflector/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ protected function reflectArgumentsCallableObject($object) : ?array

$cache = $this->cache;

if ($cache->has($reflectKey)) {
$result = $cache->get($reflectKey);
if ($cache->hasReflectResult($reflectKey)) {
$result = $cache->getReflectResult($reflectKey);

} else {
if ($isClosure) {
Expand All @@ -350,7 +350,7 @@ protected function reflectArgumentsCallableObject($object) : ?array
$result = $this->resolveReflectionFunctionAbstract($reflectKey, $rm);
}

$cache->set($reflectKey, $result);
$cache->setReflectResult($reflectKey, $result);
}

return $result;
Expand All @@ -370,8 +370,8 @@ protected function reflectArgumentsCallableArray($array) : ?array

$cache = $this->cache;

if ($cache->has($reflectKey)) {
$result = $cache->get($reflectKey);
if ($cache->hasReflectResult($reflectKey)) {
$result = $cache->getReflectResult($reflectKey);

} else {
try {
Expand All @@ -383,7 +383,7 @@ protected function reflectArgumentsCallableArray($array) : ?array

$result = $this->resolveReflectionFunctionAbstract($reflectKey, $rf);

$cache->set($reflectKey, $result);
$cache->setReflectResult($reflectKey, $result);
}

return $result;
Expand Down Expand Up @@ -417,8 +417,8 @@ protected function reflectArgumentsCallableString($string) : ?array

$cache = $this->cache;

if ($cache->has($reflectKey)) {
$result = $cache->get($reflectKey);
if ($cache->hasReflectResult($reflectKey)) {
$result = $cache->getReflectResult($reflectKey);

} else {
if ($isFunction) {
Expand All @@ -443,7 +443,7 @@ protected function reflectArgumentsCallableString($string) : ?array
$result = $this->resolveReflectionFunctionAbstract($reflectKey, $rm);
}

$cache->set($reflectKey, $result);
$cache->setReflectResult($reflectKey, $result);
}

return $result;
Expand Down Expand Up @@ -490,8 +490,8 @@ protected function reflectArgumentsConstructorClass($class) : ?array

$cache = $this->cache;

if ($cache->has($reflectKey)) {
$result = $cache->get($reflectKey);
if ($cache->hasReflectResult($reflectKey)) {
$result = $cache->getReflectResult($reflectKey);

} else {
try {
Expand All @@ -505,7 +505,7 @@ protected function reflectArgumentsConstructorClass($class) : ?array

$result = $this->resolveReflectionFunctionAbstract($reflectKey, $rm);

$cache->set($reflectKey, $result);
$cache->setReflectResult($reflectKey, $result);
}

return $result;
Expand Down
28 changes: 15 additions & 13 deletions src/Reflector/Struct/ReflectorCacheRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ReflectorCacheRuntime implements \Serializable
/**
* @var array<string, array>
*/
protected $items = [];
protected $reflectResultDict = [];

/**
* @var bool
Expand All @@ -23,7 +23,7 @@ class ReflectorCacheRuntime implements \Serializable
*/
public function reset() // : static
{
$this->items = [];
$this->reflectResultDict = [];

$this->isChanged = false;

Expand All @@ -37,22 +37,22 @@ public function isChanged() : bool
}


public function has(string $key, array &$result = null) : bool
public function hasReflectResult(string $reflectKey, array &$result = null) : bool
{
$result = null;

$status = array_key_exists($key, $this->items);
$status = array_key_exists($reflectKey, $this->reflectResultDict);

if ($status) {
$result = $this->items[ $key ];
$result = $this->reflectResultDict[ $reflectKey ];
}

return $status;
}

public function get(string $key, array $fallback = []) : array
public function getReflectResult(string $reflectKey, array $fallback = []) : array
{
$status = $this->has($key, $result);
$status = $this->hasReflectResult($reflectKey, $result);

if (! $status) {
if ($fallback) {
Expand All @@ -62,7 +62,7 @@ public function get(string $key, array $fallback = []) : array
}

throw new RuntimeException(
'Missing cache key: ' . $key
'Missing cache key: ' . $reflectKey
);
}

Expand All @@ -73,15 +73,15 @@ public function get(string $key, array $fallback = []) : array
/**
* @return static
*/
public function set(string $reflectKey, array $reflectResult) // : static
public function setReflectResult(string $reflectKey, array $reflectResult) // : static
{
if (array_key_exists($reflectKey, $this->items)) {
if (array_key_exists($reflectKey, $this->reflectResultDict)) {
throw new RuntimeException(
'Cache key already exists: ' . $reflectKey
);
}

$this->items[ $reflectKey ] = $reflectResult;
$this->reflectResultDict[ $reflectKey ] = $reflectResult;

$this->isChanged = true;

Expand All @@ -91,12 +91,14 @@ public function set(string $reflectKey, array $reflectResult) // : static

public function __serialize() : array
{
return [ 'items' => $this->items ];
return [
'reflectResultDict' => $this->reflectResultDict,
];
}

public function __unserialize(array $data) : void
{
$this->items = $data[ 'items' ];
$this->reflectResultDict = $data[ 'reflectResultDict' ];
}

public function serialize()
Expand Down

0 comments on commit 497e3d6

Please sign in to comment.