-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUGFIX: #3303 Flush reflection cache for removed php classes #3383
base: 9.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,11 @@ class ReflectionService | |
*/ | ||
protected array $updatedReflectionData = []; | ||
|
||
/** | ||
* Array with removed reflection information (e.g. in Development context after classes were deleted) | ||
*/ | ||
protected array $removedReflectionDataClasses = []; | ||
|
||
protected bool $initialized = false; | ||
|
||
/** | ||
|
@@ -1795,18 +1800,17 @@ protected function forgetClass($className): void | |
$this->classesCurrentlyBeingForgotten[$className] = true; | ||
|
||
if (class_exists($className)) { | ||
// optimisation to flush only precisely the affected interfaces | ||
$interfaceNames = class_implements($className); | ||
foreach ($interfaceNames as $interfaceName) { | ||
if (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className])) { | ||
unset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]); | ||
} | ||
} | ||
} else { | ||
foreach ($this->availableClassNames as $interfaceNames) { | ||
foreach ($interfaceNames as $interfaceName) { | ||
if (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className])) { | ||
unset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]); | ||
} | ||
foreach ($this->classReflectionData as &$possibleInterfaceReflectionData) { | ||
if (isset($possibleInterfaceReflectionData[self::DATA_INTERFACE_IMPLEMENTATIONS][$className])) { | ||
unset($possibleInterfaceReflectionData[self::DATA_INTERFACE_IMPLEMENTATIONS][$className]); | ||
} | ||
} | ||
} | ||
|
@@ -1833,6 +1837,8 @@ protected function forgetClass($className): void | |
|
||
unset($this->classReflectionData[$className]); | ||
unset($this->classesCurrentlyBeingForgotten[$className]); | ||
|
||
$this->removedReflectionDataClasses[$className] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo check if |
||
} | ||
|
||
/** | ||
|
@@ -2024,7 +2030,7 @@ public function saveToCache(): void | |
$this->reflectionDataRuntimeCache->set('__availableClassNames', $this->availableClassNames); | ||
} | ||
|
||
if ($this->updatedReflectionData !== []) { | ||
if ($this->updatedReflectionData !== [] || $this->removedReflectionDataClasses !== []) { | ||
$this->updateReflectionData(); | ||
} | ||
|
||
|
@@ -2092,7 +2098,7 @@ protected function saveProductionData(): void | |
*/ | ||
protected function updateReflectionData(): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
$this->log(sprintf('Found %s classes whose reflection data was not cached previously.', count($this->updatedReflectionData)), LogLevel::DEBUG); | ||
$this->log(sprintf('Found %s classes whose reflection data was not cached previously and %s classes which were deleted.', count($this->updatedReflectionData), count($this->removedReflectionDataClasses)), LogLevel::DEBUG); | ||
|
||
foreach (array_keys($this->updatedReflectionData) as $className) { | ||
$this->statusCache->set($this->produceCacheIdentifierFromClassName($className), ''); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically we can discuss if we always want to use the psr-4 reverse lookup instead of parsing the file via
PhpAnalyzer
... but for that we would need to know how stable this logic is... for example regarding symlinks