Skip to content

Commit 6714ffd

Browse files
committed
Helper function should only return the parameters needed to create the object for the constructor
1 parent e9467d3 commit 6714ffd

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

wcfsetup/install/files/lib/system/cache/ephemeral/AbstractEphemeralCache.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function (ItemInterface $item, bool &$save) {
4343
new EphemeralCacheRebuildBackgroundJob(
4444
$item,
4545
\get_class($this),
46-
ClassUtil::getObjectProperties($this, \ReflectionProperty::IS_READONLY)
46+
ClassUtil::getConstructorProperties($this)
4747
)
4848
);
4949

@@ -68,7 +68,7 @@ private function getCacheKey(): string
6868
\get_class($this)
6969
);
7070

71-
$parameters = ClassUtil::getObjectProperties($this, \ReflectionProperty::IS_READONLY);
71+
$parameters = ClassUtil::getConstructorProperties($this);
7272

7373
if ($parameters !== []) {
7474
$this->cacheName .= '-' . CacheHandler::getInstance()->getCacheIndex($parameters);

wcfsetup/install/files/lib/system/cache/persistent/AbstractPersistentCache.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private function getCacheKey(): string
5353
\get_class($this)
5454
);
5555

56-
$parameters = ClassUtil::getObjectProperties($this, \ReflectionProperty::IS_READONLY);
56+
$parameters = ClassUtil::getConstructorProperties($this);
5757

5858
if ($parameters !== []) {
5959
$this->cacheName .= '-' . CacheHandler::getInstance()->getCacheIndex($parameters);

wcfsetup/install/files/lib/util/ClassUtil.class.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,19 @@ public static function isDecoratedInstanceOf($className, $targetClass)
9898
}
9999

100100
/**
101-
* Returns the properties as a key-value array of the given object.
102-
* This array doesn't contain properties with `null` as value.
103-
*
104-
* @param ?\ReflectionProperty::IS_* $filter
101+
* Returns the properties as a key-value array to construct the given object.
105102
*
106103
* @return array<string, mixed>
107104
*/
108-
public static function getObjectProperties(object $object, ?int $filter = null): array
105+
public static function getConstructorProperties(object $object): array
109106
{
110107
$reflection = new \ReflectionClass($object);
108+
111109
$properties = [];
112-
foreach ($reflection->getProperties($filter) as $property) {
113-
if (!$property->isInitialized($object)) {
114-
continue;
115-
}
110+
foreach ($reflection->getConstructor()?->getParameters() ?? [] as $parameter) {
111+
$property = $reflection->getProperty($parameter->getName());
116112

117-
if ($property->getValue($object) === null) {
113+
if (!$property->isInitialized($object)) {
118114
continue;
119115
}
120116

0 commit comments

Comments
 (0)