-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task assembly #284
Task assembly #284
Changes from 8 commits
cea3129
084e165
3d59092
dcf1b03
f0ae7e9
dfff660
d9c20af
ec5d60f
4b3f964
5f66ab3
254c647
009fcde
269e6d0
40b1bf5
ff7850b
eb0d5c7
3990a7c
f7ef6dc
8e40124
729202a
8a014a8
12b1255
426cf5f
3ee6235
8388ce3
cd4fbed
9e0c4b0
bf25add
ac88ae9
9b31b4e
a1515f6
d141895
699d388
cf079a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,70 @@ | |
|
||
class Application extends SymfonyApplication | ||
{ | ||
/** | ||
* @var \Robo\TaskAssembler | ||
*/ | ||
protected $taskAssembler; | ||
|
||
public function __construct($name, $version) | ||
{ | ||
parent::__construct($name, $version); | ||
|
||
$this->getDefinition()->addOption( | ||
new InputOption('--simulate', null, InputOption::VALUE_NONE, 'Run in simulated mode (show what would have happened).') | ||
); | ||
} | ||
|
||
public function setTaskAssembler($taskAssembler) | ||
{ | ||
$this->taskAssembler = $taskAssembler; | ||
} | ||
|
||
public function taskAssembler() | ||
{ | ||
return $this->taskAssembler; | ||
} | ||
|
||
protected static function findAccessorMethods($commandNames) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this method is really needed. See notes below |
||
{ | ||
$accessorNames = []; | ||
// Using get_class_vars is not reliable, because it only | ||
// exposes public class variables. | ||
foreach ($commandNames as $commandName) { | ||
// We count a set of methods as accessor methods if | ||
// there is a setter and at least one getter. | ||
if (strpos($commandName, 'set') === 0) { | ||
$name = lcfirst(substr($commandName, 3)); | ||
$getter = 'get' . ucfirst($name); | ||
$hasGetter = false; | ||
if (in_array($name, $commandNames)) { | ||
$accessorNames[] = $name; | ||
$hasGetter = true; | ||
} | ||
if (in_array($getter, $commandNames)) { | ||
$accessorNames[] = $getter; | ||
$hasGetter = true; | ||
} | ||
if ($hasGetter) { | ||
$accessorNames[] = $commandName; | ||
} | ||
} | ||
} | ||
return $accessorNames; | ||
} | ||
|
||
public function addCommandsFromClass($className, $passThrough = null) | ||
{ | ||
$roboTasks = new $className; | ||
if ($roboTasks instanceof \Robo\Tasks) { | ||
$roboTasks->setTaskAssembler($this->taskAssembler); | ||
} | ||
|
||
$commandNames = array_filter(get_class_methods($className), function($m) { | ||
$commandNames = array_filter(get_class_methods($className), function ($m) { | ||
return !in_array($m, ['__construct']); | ||
}); | ||
$accessorNames = static::findAccessorMethods($commandNames); | ||
$commandNames = array_diff($commandNames, $accessorNames); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why you need |
||
|
||
foreach ($commandNames as $commandName) { | ||
$command = $this->createCommand(new TaskInfo($className, $commandName)); | ||
|
@@ -28,6 +84,11 @@ public function addCommandsFromClass($className, $passThrough = null) | |
$args[key(array_slice($args, -1, 1, TRUE))] = $passThrough; | ||
} | ||
$args[] = $input->getOptions(); | ||
// Need a better way to handle global options | ||
// Also, this is not necessarily the best place to do this | ||
Config::setGlobalOptions($input); | ||
// Avoid making taskAssembler depend on Config class. | ||
Config::service('taskAssembler')->setSimulated(Config::isSimulated()); | ||
|
||
$res = call_user_func_array([$roboTasks, $commandName], $args); | ||
if (is_int($res)) exit($res); | ||
|
@@ -97,4 +158,4 @@ public function addInitRoboFileCommand($roboFile, $roboClass) | |
}); | ||
$this->add($createRoboFile); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good choice )