Skip to content

Commit

Permalink
Set DependencyInjector::getImportedServices as static to be able to o…
Browse files Browse the repository at this point in the history
…btain all services without any instance of DependencyInjector
  • Loading branch information
p0lemic authored Aug 7, 2020
2 parents 538a2bf + 3c7a065 commit 5acb5df
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Sifo/DependencyInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private function generateDependenciesDeclarationForInstance($instance, $parent_i
}

$parsed_yaml_content = Yaml::parse(file_get_contents($instance_yml_definitions_file));
$declared_services = $this->getImportedServices($parsed_yaml_content, $instance_yml_definitions_file);
$declared_services = self::getImportedServices($parsed_yaml_content, $instance_yml_definitions_file);

$compiled_services = [];
$scoped_definitions = [];
Expand Down Expand Up @@ -314,7 +314,7 @@ private function stringifyArguments(array $arguments, array $compiled_services,
return $compiled_arguments;
}

public function getImportedServices($parsed_yaml_content, $parsed_yaml_path)
public static function getImportedServices($parsed_yaml_content, $parsed_yaml_path)
{
$imports = is_array($parsed_yaml_content)
? array_key_exists('imports', $parsed_yaml_content)
Expand All @@ -330,30 +330,30 @@ public function getImportedServices($parsed_yaml_content, $parsed_yaml_path)

$retrieved_services = [];

if ($this->hasGroupedServicesByInstances($imports)) {
if (self::hasGroupedServicesByInstances($imports)) {
foreach ($imports as $instance => $files_to_import) {
$config_files_path = ROOT_PATH . '/instances/' . $instance . '/config/services/';
$retrieved_services = array_merge(
$retrieved_services,
$this->getServicesFromFilesCollection($config_files_path, $files_to_import)
self::getServicesFromFilesCollection($config_files_path, $files_to_import)
);
}

return array_merge($retrieved_services, $services);
}

$config_files_path = dirname($parsed_yaml_path) . '/';
$retrieved_services = $this->getServicesFromFilesCollection($config_files_path, $imports);
$retrieved_services = self::getServicesFromFilesCollection($config_files_path, $imports);

return array_merge($retrieved_services, $services);
}

private function hasGroupedServicesByInstances($imports)
private static function hasGroupedServicesByInstances($imports)
{
return count(array_filter(array_keys($imports), 'is_string')) > 0;
}

private function getServicesFromFilesCollection($config_files_path, array $files_to_import)
private static function getServicesFromFilesCollection($config_files_path, array $files_to_import)
{
$retrieved_services = [];

Expand All @@ -363,7 +363,7 @@ private function getServicesFromFilesCollection($config_files_path, array $files

$retrieved_services = array_merge(
$retrieved_services,
$this->getImportedServices($imported_parsed_yaml_content, $imported_parsed_yaml_path)
self::getImportedServices($imported_parsed_yaml_content, $imported_parsed_yaml_path)
);
}

Expand Down

0 comments on commit 5acb5df

Please sign in to comment.