Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 18, 2023
2 parents 232ddfa + a9fa8f0 commit a29ea10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
37 changes: 24 additions & 13 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Factories
*/
public static function define(string $component, string $alias, string $classname): void
{
$component = strtolower($component);

if (isset(self::$aliases[$component][$alias])) {
if (self::$aliases[$component][$alias] === $classname) {
return;
Expand Down Expand Up @@ -130,12 +132,14 @@ public static function define(string $component, string $alias, string $classnam
*/
public static function __callStatic(string $component, array $arguments)
{
$component = strtolower($component);

// First argument is the class alias, second is options
$alias = trim(array_shift($arguments), '\\ ');
$options = array_shift($arguments) ?? [];

// Determine the component-specific options
$options = array_merge(self::getOptions(strtolower($component)), $options);
$options = array_merge(self::getOptions($component), $options);

if (! $options['getShared']) {
if (isset(self::$aliases[$component][$alias])) {
Expand Down Expand Up @@ -395,6 +399,8 @@ public static function getOptions(string $component): array
*/
public static function setOptions(string $component, array $values): array
{
$component = strtolower($component);

// Allow the config to replace the component name, to support "aliases"
$values['component'] = strtolower($values['component'] ?? $component);

Expand Down Expand Up @@ -425,19 +431,19 @@ public static function reset(?string $component = null)
{
if ($component !== null) {
unset(
static::$options[$component],
static::$aliases[$component],
static::$instances[$component],
static::$updated[$component]
self::$options[$component],
self::$aliases[$component],
self::$instances[$component],
self::$updated[$component]
);

return;
}

static::$options = [];
static::$aliases = [];
static::$instances = [];
static::$updated = [];
self::$options = [];
self::$aliases = [];
self::$instances = [];
self::$updated = [];
}

/**
Expand All @@ -453,8 +459,9 @@ public static function reset(?string $component = null)
*/
public static function injectMock(string $component, string $alias, object $instance)
{
// Force a configuration to exist for this component
$component = strtolower($component);

// Force a configuration to exist for this component
self::getOptions($component);

$class = get_class($instance);
Expand Down Expand Up @@ -494,15 +501,17 @@ public static function getBasename(string $alias): string
*/
public static function getComponentInstances(string $component): array
{
if (! isset(static::$aliases[$component])) {
if (! isset(self::$aliases[$component])) {
return [
'options' => [],
'aliases' => [],
'instances' => [],
];
}

return [
'aliases' => static::$aliases[$component],
'options' => self::$options[$component],
'aliases' => self::$aliases[$component],
'instances' => self::$instances[$component],
];
}
Expand All @@ -514,8 +523,10 @@ public static function getComponentInstances(string $component): array
*/
public static function setComponentInstances(string $component, array $data): void
{
static::$aliases[$component] = $data['aliases'];
self::$options[$component] = $data['options'];
self::$aliases[$component] = $data['aliases'];
self::$instances[$component] = $data['instances'];

unset(self::$updated[$component]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Config/FactoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function testGetComponentInstances()
public function testSetComponentInstances(array $data)
{
$before = Factories::getComponentInstances('config');
$this->assertSame(['aliases' => [], 'instances' => []], $before);
$this->assertSame(['options' => [], 'aliases' => [], 'instances' => []], $before);

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

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/BaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testStoresConnectionTimings(): void
$db->initialize();

$this->assertGreaterThan($start, $db->getConnectStart());
$this->assertGreaterThan(0.0, $db->getConnectDuration());
$this->assertGreaterThanOrEqual(0.0, $db->getConnectDuration());
}

/**
Expand Down

0 comments on commit a29ea10

Please sign in to comment.