Skip to content

Commit

Permalink
Added autoconfig option weight
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Feb 15, 2015
1 parent 966d171 commit 15e07f5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
36 changes: 28 additions & 8 deletions lib/Autoconfig/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

class Config
{
const CONFIG_WEIGHT_FRAMEWORK = -100;
const CONFIG_WEIGHT_MODULE = 0;
const CONFIG_WEIGHT_APP = 100;

/**
* @var Package[]
*/
Expand Down Expand Up @@ -98,13 +102,6 @@ protected function resolve_fragments(array $packages)
list($package, $pathname) = $pi;

$pathname = realpath($pathname);
$weight = -10;

if ($package instanceof RootPackage)
{
$weight = 10;
}

$fragment = $this->resolve_fragment($pathname);

if (!$fragment)
Expand All @@ -113,12 +110,35 @@ protected function resolve_fragments(array $packages)
}

$fragments[$pathname] = $fragment;
$weights[$pathname] = $weight;
$weights[$pathname] = $this->resolve_config_weight($package, $fragment);
}

return [ $fragments, $weights ];
}

/**
* Resolves config weight.
*
* @param Package $package
* @param array $fragment
*
* @return int
*/
private function resolve_config_weight(Package $package, array $fragment)
{
if (isset($fragment['config-weight']))
{
return $fragment['config-weight'];
}

if ($package instanceof RootPackage)
{
return self::CONFIG_WEIGHT_APP;
}

return self::CONFIG_WEIGHT_FRAMEWORK;
}

/**
* Resolve the autoconfig fragment of a package.
*
Expand Down
8 changes: 8 additions & 0 deletions lib/Autoconfig/composer-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@

},

"config-weight": {

"type": "integer",
"description": "The weight of the config. Default to CONFIG_WEIGHT_FRAMEWORK (-100)",
"required": false

},

"locale-path": {

"type": [ "string", "array" ],
Expand Down
8 changes: 8 additions & 0 deletions lib/Autoconfig/icanboogie-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

},

"config-weight": {

"type": "integer",
"description": "The weight of the config. Default to CONFIG_WEIGHT_FRAMEWORK (-100)",
"required": false

},

"locale-path": {

"type": [ "string", "array" ],
Expand Down

0 comments on commit 15e07f5

Please sign in to comment.