Skip to content

Commit

Permalink
CHANGED: simplified finding goal class
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Dec 22, 2015
1 parent 4692567 commit 91903fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
17 changes: 11 additions & 6 deletions bin/hidev
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@ $config = [
'pluginManager' => [
'class' => 'hiqdev\pluginmanager\PluginManager',
'goals' => [
'git' => 'hidev\goals\GitGoal',
'github' => 'hidev\goals\GitHubGoal',
'README.md' => 'readme',
'README.txt' => 'readme',
'README.markdown' => 'readme',
'CHANGELOG.md' => 'changelog',
'CHANGELOG.txt' => 'changelog',
'CHANGELOG.markdown' => 'changelog',
'vendor' => 'hidev\goals\VendorGoal',
'commits' => 'hidev\goals\CommitsGoal',
'install' => [
'class' => 'hidev\goals\InstallGoal',
],
'package' => 'hidev\goals\PackageGoal',
'gitignore' => 'hidev\goals\GitignoreGoal',
'CHANGELOG.md' => 'hidev\goals\ChangelogGoal',
'CHANGELOG.txt' => 'hidev\goals\ChangelogGoal',
'CHANGELOG.markdown' => 'hidev\goals\ChangelogGoal',
],
],
'request' => [
Expand Down
20 changes: 4 additions & 16 deletions src/goals/ConfigGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,12 @@ public static function findGoal($name)
return is_scalar($config) ? ['class' => $config] : (array) $config;
}

public static function goal2class($id, $name = null)
{
$id = $id ?: $name;

return strpos($id, '\\') !== false ? $id : 'hidev\goals\\' . Helper::id2camel($id) . 'Goal';
}

public function getItemClass($name = null, array $config = [])
{
$class = static::goal2class($config['goal'], $name);

return class_exists($class) ? $class : static::goal2class('default');
}

public function getItemConfig($name = null, array $config = [])
{
$config = ArrayHelper::merge(['goalName' => $name], static::findGoal($name), $config);
$config['class'] = $this->getItemClass($config['class'] ?: $name, $config);
$config = ArrayHelper::merge([
'goalName' => $name,
'class' => 'hidev\goals\DefaultGoal',
], static::findGoal($name), $config);

return $config;
}
Expand Down

0 comments on commit 91903fe

Please sign in to comment.