mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Refactored Services to use Modules config file when discovering.
This commit is contained in:
parent
f79c6a867a
commit
e3b3c570c1
@ -58,6 +58,8 @@ class BaseConfig
|
||||
|
||||
protected static $didDiscovery = false;
|
||||
|
||||
protected static $moduleConfig;
|
||||
|
||||
/**
|
||||
* Will attempt to get environment variables with names
|
||||
* that match the properties of the child class.
|
||||
@ -66,6 +68,8 @@ class BaseConfig
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
static::$moduleConfig = config('Modules');
|
||||
|
||||
$properties = array_keys(get_object_vars($this));
|
||||
$prefix = get_class($this);
|
||||
$slashAt = strrpos($prefix, '\\');
|
||||
@ -167,9 +171,7 @@ class BaseConfig
|
||||
*/
|
||||
protected function registerProperties()
|
||||
{
|
||||
$config = config('Modules');
|
||||
|
||||
if (! $config->shouldDiscover('registrars'))
|
||||
if (! static::$moduleConfig->shouldDiscover('registrars'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -202,22 +202,27 @@ class BaseService
|
||||
{
|
||||
if (! static::$discovered)
|
||||
{
|
||||
$locator = static::locator();
|
||||
$files = $locator->search('Config/Services');
|
||||
$config = config('Modules');
|
||||
|
||||
if (empty($files))
|
||||
if ($config->shouldDiscover('services'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$locator = static::locator();
|
||||
$files = $locator->search('Config/Services');
|
||||
|
||||
// Get instances of all service classes and cache them locally.
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$classname = $locator->getClassname($file);
|
||||
|
||||
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
|
||||
if (empty($files))
|
||||
{
|
||||
static::$services[] = new $classname();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get instances of all service classes and cache them locally.
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$classname = $locator->getClassname($file);
|
||||
|
||||
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
|
||||
{
|
||||
static::$services[] = new $classname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user