Skip to content

Commit

Permalink
Configure Sifo Dependency Injector to be able to locate service defin…
Browse files Browse the repository at this point in the history
…ition files outside instances folders
  • Loading branch information
obokaman-com authored May 28, 2019
2 parents b64eeec + 456ec77 commit d4ab5c2
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/Sifo/DependencyInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ 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);
$declared_services = $this->getImportedServices($parsed_yaml_content, $instance_yml_definitions_file);

$compiled_services = array();
$scoped_definitions = array();
$private_services = array();
Expand Down Expand Up @@ -311,7 +312,7 @@ private function stringifyArguments(array $arguments, array $compiled_services,
return $compiled_arguments;
}

private function getImportedServices($parsed_yaml_content)
private function getImportedServices($parsed_yaml_content, $parsed_yaml_path)
{
$imports = is_array($parsed_yaml_content)
? array_key_exists('imports', $parsed_yaml_content)
Expand All @@ -326,21 +327,47 @@ private function getImportedServices($parsed_yaml_content)
: array();

$retrieved_services = array();
foreach ($imports as $instance => $files_to_import) {
$config_files_path = ROOT_PATH . '/instances/' . $instance . '/config/services/';

foreach ($files_to_import as $file_to_import) {
$imported_parsed_yaml_content = Yaml::parse(file_get_contents($config_files_path . $file_to_import));
$retrieved_services = array_merge(
if ($this->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->getImportedServices($imported_parsed_yaml_content)
$this->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);

return array_merge($retrieved_services, $services);
}

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

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

foreach ($files_to_import as $file_to_import) {
$imported_parsed_yaml_path = $config_files_path . $file_to_import;
$imported_parsed_yaml_content = Yaml::parse(file_get_contents($imported_parsed_yaml_path));

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

return $retrieved_services;
}

private function isALiteralDeclaration($declaration)
{
return !is_array($declaration);
Expand Down

0 comments on commit d4ab5c2

Please sign in to comment.