Skip to content

Commit e3b3c57

Browse files
committed
Refactored Services to use Modules config file when discovering.
1 parent f79c6a8 commit e3b3c57

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

system/Config/BaseConfig.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class BaseConfig
5858

5959
protected static $didDiscovery = false;
6060

61+
protected static $moduleConfig;
62+
6163
/**
6264
* Will attempt to get environment variables with names
6365
* that match the properties of the child class.
@@ -66,6 +68,8 @@ class BaseConfig
6668
*/
6769
public function __construct()
6870
{
71+
static::$moduleConfig = config('Modules');
72+
6973
$properties = array_keys(get_object_vars($this));
7074
$prefix = get_class($this);
7175
$slashAt = strrpos($prefix, '\\');
@@ -167,9 +171,7 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr
167171
*/
168172
protected function registerProperties()
169173
{
170-
$config = config('Modules');
171-
172-
if (! $config->shouldDiscover('registrars'))
174+
if (! static::$moduleConfig->shouldDiscover('registrars'))
173175
{
174176
return;
175177
}

system/Config/BaseService.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,27 @@ protected static function discoverServices(string $name, array $arguments)
202202
{
203203
if (! static::$discovered)
204204
{
205-
$locator = static::locator();
206-
$files = $locator->search('Config/Services');
205+
$config = config('Modules');
207206

208-
if (empty($files))
207+
if ($config->shouldDiscover('services'))
209208
{
210-
return;
211-
}
209+
$locator = static::locator();
210+
$files = $locator->search('Config/Services');
212211

213-
// Get instances of all service classes and cache them locally.
214-
foreach ($files as $file)
215-
{
216-
$classname = $locator->getClassname($file);
212+
if (empty($files))
213+
{
214+
return;
215+
}
217216

218-
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
217+
// Get instances of all service classes and cache them locally.
218+
foreach ($files as $file)
219219
{
220-
static::$services[] = new $classname();
220+
$classname = $locator->getClassname($file);
221+
222+
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
223+
{
224+
static::$services[] = new $classname();
225+
}
221226
}
222227
}
223228

0 commit comments

Comments
 (0)