Skip to content

Commit

Permalink
feat(module): Improve module app config loader
Browse files Browse the repository at this point in the history
Improve 'metadata/config' and 'view/config'.

Changed:
- Ensure extra paths are defined before merging.
- Add support for extra module paths to 'translator/config'.
  • Loading branch information
mcaskill committed Mar 6, 2024
1 parent e6c3493 commit 8871115
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ protected function registerMetadataDependencies(Container $container)
$configPath = $basePath . DIRECTORY_SEPARATOR . $configPath;

$configData = $metaConfig->loadFile($configPath);
$extraPaths = array_merge(
$extraPaths,
$configData['metadata']['paths']
);
if (isset($configData['metadata']['paths'])) {
$extraPaths = array_merge(
$extraPaths,
$configData['metadata']['paths']
);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,38 @@ private function registerTranslator(Container $container)
$container['translator/config'] = function (Container $container) {
$appConfig = isset($container['config']) ? $container['config'] : [];
$transConfig = isset($appConfig['translator']) ? $appConfig['translator'] : null;

if (isset($transConfig['paths'])) {
$transConfig['paths'] = $container['config']->resolveValues($transConfig['paths']);
$transConfig['paths'] = $appConfig->resolveValues($transConfig['paths']);
}

$transConfig = new TranslatorConfig($transConfig);

if (isset($container['module/classes'])) {
$extraPaths = [];
$basePath = $appConfig['base_path'];
$modules = $container['module/classes'];
foreach ($modules as $module) {
if (defined(sprintf('%s::APP_CONFIG', $module))) {
$configPath = ltrim($module::APP_CONFIG, '/');
$configPath = $basePath . DIRECTORY_SEPARATOR . $configPath;

$configData = $appConfig->loadFile($configPath);
if (isset($configData['translator']['paths'])) {
$extraPaths = array_merge(
$extraPaths,
$appConfig->resolveValues($configData['translator']['paths'])
);
}
};
}

if ($extraPaths) {
$transConfig->addPaths($extraPaths);
}
}
return new TranslatorConfig($transConfig);

return $transConfig;
};

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/view/src/Charcoal/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ protected function registerViewConfig(Container $container): void
$configPath = $basePath . DIRECTORY_SEPARATOR . $configPath;

$configData = $viewConfig->loadFile($configPath);
$extraPaths = array_merge(
$extraPaths,
$configData['view']['paths']
);
if (isset($configData['view']['paths'])) {
$extraPaths = array_merge(
$extraPaths,
$configData['view']['paths']
);
}
};
}

Expand Down

0 comments on commit 8871115

Please sign in to comment.