Skip to content

Commit a9fa8f0

Browse files
authored
Merge pull request #8037 from kenjis/fix-Factories-cache-bug
fix: Factories caching bug
2 parents 098bd10 + 7664bb6 commit a9fa8f0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

system/Config/Factories.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class Factories
100100
*/
101101
public static function define(string $component, string $alias, string $classname): void
102102
{
103+
$component = strtolower($component);
104+
103105
if (isset(self::$aliases[$component][$alias])) {
104106
if (self::$aliases[$component][$alias] === $classname) {
105107
return;
@@ -130,12 +132,14 @@ public static function define(string $component, string $alias, string $classnam
130132
*/
131133
public static function __callStatic(string $component, array $arguments)
132134
{
135+
$component = strtolower($component);
136+
133137
// First argument is the class alias, second is options
134138
$alias = trim(array_shift($arguments), '\\ ');
135139
$options = array_shift($arguments) ?? [];
136140

137141
// Determine the component-specific options
138-
$options = array_merge(self::getOptions(strtolower($component)), $options);
142+
$options = array_merge(self::getOptions($component), $options);
139143

140144
if (! $options['getShared']) {
141145
if (isset(self::$aliases[$component][$alias])) {
@@ -395,6 +399,8 @@ public static function getOptions(string $component): array
395399
*/
396400
public static function setOptions(string $component, array $values): array
397401
{
402+
$component = strtolower($component);
403+
398404
// Allow the config to replace the component name, to support "aliases"
399405
$values['component'] = strtolower($values['component'] ?? $component);
400406

@@ -425,19 +431,19 @@ public static function reset(?string $component = null)
425431
{
426432
if ($component !== null) {
427433
unset(
428-
static::$options[$component],
429-
static::$aliases[$component],
430-
static::$instances[$component],
431-
static::$updated[$component]
434+
self::$options[$component],
435+
self::$aliases[$component],
436+
self::$instances[$component],
437+
self::$updated[$component]
432438
);
433439

434440
return;
435441
}
436442

437-
static::$options = [];
438-
static::$aliases = [];
439-
static::$instances = [];
440-
static::$updated = [];
443+
self::$options = [];
444+
self::$aliases = [];
445+
self::$instances = [];
446+
self::$updated = [];
441447
}
442448

443449
/**
@@ -453,8 +459,9 @@ public static function reset(?string $component = null)
453459
*/
454460
public static function injectMock(string $component, string $alias, object $instance)
455461
{
456-
// Force a configuration to exist for this component
457462
$component = strtolower($component);
463+
464+
// Force a configuration to exist for this component
458465
self::getOptions($component);
459466

460467
$class = get_class($instance);
@@ -494,15 +501,17 @@ public static function getBasename(string $alias): string
494501
*/
495502
public static function getComponentInstances(string $component): array
496503
{
497-
if (! isset(static::$aliases[$component])) {
504+
if (! isset(self::$aliases[$component])) {
498505
return [
506+
'options' => [],
499507
'aliases' => [],
500508
'instances' => [],
501509
];
502510
}
503511

504512
return [
505-
'aliases' => static::$aliases[$component],
513+
'options' => self::$options[$component],
514+
'aliases' => self::$aliases[$component],
506515
'instances' => self::$instances[$component],
507516
];
508517
}
@@ -514,8 +523,10 @@ public static function getComponentInstances(string $component): array
514523
*/
515524
public static function setComponentInstances(string $component, array $data): void
516525
{
517-
static::$aliases[$component] = $data['aliases'];
526+
self::$options[$component] = $data['options'];
527+
self::$aliases[$component] = $data['aliases'];
518528
self::$instances[$component] = $data['instances'];
529+
519530
unset(self::$updated[$component]);
520531
}
521532

tests/system/Config/FactoriesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function testGetComponentInstances()
429429
public function testSetComponentInstances(array $data)
430430
{
431431
$before = Factories::getComponentInstances('config');
432-
$this->assertSame(['aliases' => [], 'instances' => []], $before);
432+
$this->assertSame(['options' => [], 'aliases' => [], 'instances' => []], $before);
433433

434434
Factories::setComponentInstances('config', $data);
435435

0 commit comments

Comments
 (0)