Skip to content

Commit

Permalink
simplified aliases assembling
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 19, 2016
1 parent dbe12ec commit 174c848
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,39 @@ public function assembleConfigs()
{
$allAliases = [];
$extensions = [];
$rawConfigs = [];
$rawConfigs = [
'aliases' => [],
'extensions' => [],
];

foreach ($this->raw as $name => $info) {
$extensions[$name] = $info['extension'];
$rawConfigs['extensions'][] = [
$name => $info['extension']
];

$aliases = $info['aliases'];
$allAliases = array_merge($allAliases, $aliases);

foreach ($info['files'] as $file => $path) {
$config = $this->readConfigFile($info['package'], $path);
$config['aliases'] = array_merge(
$aliases,
isset($config['aliases']) ? (array) $config['aliases'] : []
);
$allAliases = array_merge($allAliases, $config['aliases']);
$rawConfigs[$file][] = $config;
$rawConfigs['aliases'][] = $aliases;

foreach ($info['files'] as $name => $path) {
$rawConfigs[$name][] = $this->readConfigFile($info['package'], $path);
}
}

$this->writeFile('aliases', $allAliases);
$this->writeFile('extensions', $extensions);

foreach ($rawConfigs as $file => $configs) {
$this->assembleFile($file, $configs);
foreach ($rawConfigs as $name => $configs) {
if (!in_array($name, ['params', 'aliases', 'extensions'], true)) {
$configs[] = [
'params' => $this->data['params'],
'aliases' => $this->data['aliases'],
];
}
$this->assembleFile($name, $configs);
}
}

protected function assembleFile($file, $configs)
protected function assembleFile($name, $configs)
{
$data = call_user_func_array([Helper::class, 'mergeConfig'], $configs);
$this->writeFile($file, $data);
$this->data[$name] = call_user_func_array([Helper::class, 'mergeConfig'], $configs);
$this->writeFile($name, $this->data[$name]);
}

/**
Expand All @@ -221,12 +224,13 @@ protected function assembleFile($file, $configs)
*/
protected function readConfigFile(PackageInterface $package, $file)
{
$path = $this->preparePath($package, $file);
if (!file_exists($path)) {
$__path = $this->preparePath($package, $file);
if (!file_exists($__path)) {
$this->io->writeError('<error>Non existent extension config file</error> ' . $file . ' in ' . $package->getName());
exit(1);
}
return require $path;
extract($this->data);
return require $__path;
}

/**
Expand Down

0 comments on commit 174c848

Please sign in to comment.