Refactored Services to use Modules config file when discovering.

This commit is contained in:
Lonnie Ezell 2018-09-11 22:49:38 -05:00
parent f79c6a867a
commit e3b3c570c1
No known key found for this signature in database
GPG Key ID: 8EB408F8D82F5002
2 changed files with 22 additions and 15 deletions

View File

@ -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;
}

View File

@ -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();
}
}
}