Skip to content

Commit

Permalink
looks working
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 18, 2016
1 parent 65d1a3e commit 470dc87
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function onPostAutoloadDump(Event $event)
$this->processPackage($this->composer->getPackage());

$this->assembleParams();

define('COMPOSER_CONFIG_PLUGIN_DIR', $this->getOutputDir());
$this->assembleConfigs();
}

Expand Down Expand Up @@ -155,52 +155,65 @@ public function processPackage(PackageInterface $package)
$this->prepareAliases($package, 'psr-4')
);

if (isset($files['defines'])) {
$this->readConfigFile($package, $files['defines']);
unset($files['defines']);
}

if (isset($files['params'])) {
$this->rawParams[] = $this->readConfigFile($package, $files['params']);
unset($files['params']);
}

$this->raw[$package->getName()] = [
'package' => $package,
'extension' => $extensin,
'extension' => $extension,
'aliases' => $aliases,
'files' => (array)$files,
];
}

public function assembleParams()
{
var_dump($this->rawParams);
die();
$params = call_user_func_array(Helper::mergeConfig, $this->rawParams);

$this->writeFile('params', $params);
$this->assembleFile('params', $this->rawParams);
}

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

$aliases = $info['aliases'];
$this->data['aliases'] = array_merge($this->data['aliases'], $aliases);
$allAliases = array_merge($allAliases, $aliases);

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

foreach ($this->data as $name => $data) {
$this->writeFile($name, $data);
$this->writeFile('aliases', $allAliases);
$this->writeFile('extensions', $extensions);

foreach ($rawConfigs as $file => $configs) {
$this->assembleFile($file, $configs);
}
}

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

/**
* Read extra config.
* @param string $file
Expand Down Expand Up @@ -271,14 +284,23 @@ public function preparePath(PackageInterface $package, $path)
return $this->getFilesystem()->normalizePath($path);
}

/**
* Get output dir.
* @return string
*/
public function getOutputDir()
{
return $this->getVendorDir() . DIRECTORY_SEPARATOR . static::OUTPUT_PATH;
}

/**
* Build full path to write file for a given filename.
* @param string $filename
* @return string
*/
public function buildOutputPath($filename)
{
return $this->getVendorDir() . DIRECTORY_SEPARATOR . static::OUTPUT_PATH . DIRECTORY_SEPARATOR . $filename . '.php';
return $this->getOutputDir() . DIRECTORY_SEPARATOR . $filename . '.php';
}

/**
Expand Down

0 comments on commit 470dc87

Please sign in to comment.