genesis-php /
genesis
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace Genesis; |
||
| 5 | |||
| 6 | |||
| 7 | use Genesis\Commands; |
||
| 8 | use Genesis\Config; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @author Adam Bisek <[email protected]> |
||
| 12 | */ |
||
| 13 | class Build implements IBuild |
||
| 14 | { |
||
| 15 | |||
| 16 | protected $container; |
||
| 17 | |||
| 18 | protected $arguments; |
||
| 19 | |||
| 20 | |||
| 21 | 4 | public function __construct(Config\Container $container, array $arguments = NULL) |
|
| 22 | { |
||
| 23 | 4 | $this->container = $container; |
|
| 24 | 4 | $this->arguments = $arguments; |
|
| 25 | 4 | } |
|
| 26 | |||
| 27 | |||
| 28 | public function setup() |
||
| 29 | { |
||
| 30 | } |
||
| 31 | |||
| 32 | |||
| 33 | 1 | public function runDefault() |
|
| 34 | { |
||
| 35 | 1 | $helpCommand = new Commands\Help; |
|
| 36 | 1 | foreach ($this->detectAvailableTasks() as $section => $tasks) { |
|
| 37 | 1 | if(!$helpCommand->hasSection($section)){ |
|
| 38 | 1 | $helpCommand->addSection($section); |
|
| 39 | 1 | } |
|
| 40 | 1 | $helpCommand->setSectionTasks($section, $tasks); |
|
| 41 | 1 | } |
|
| 42 | 1 | $helpCommand->execute(); |
|
| 43 | 1 | } |
|
| 44 | |||
| 45 | |||
| 46 | 1 | protected function detectAvailableTasks() |
|
| 47 | { |
||
| 48 | 1 | $tasks = []; |
|
| 49 | 1 | $classReflection = new \ReflectionClass($this); |
|
| 50 | 1 | foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
|
| 51 | 1 | if (preg_match('#^run(.*)#', $method->getName(), $match)) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 52 | 1 | $doc = $method->getDocComment(); |
|
| 53 | 1 | $section = NULL; |
|
| 54 | 1 | if(preg_match('#@section ?([^\s]*)\s#s', $doc, $m)){ |
|
| 55 | 1 | $section = trim($m[1]); |
|
| 56 | 1 | } |
|
| 57 | 1 | $description = NULL; |
|
| 58 | 1 | if(preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)){ |
|
| 59 | 1 | $description = trim($m[0]); |
|
| 60 | 1 | } |
|
| 61 | 1 | $tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL; |
|
| 62 | 1 | } |
|
| 63 | 1 | } |
|
| 64 | 1 | return $tasks; |
|
| 65 | } |
||
| 66 | |||
| 67 | |||
| 68 | 1 | protected function error($message) |
|
| 69 | { |
||
| 70 | 1 | throw new \ErrorException($message); |
|
| 71 | } |
||
| 72 | |||
| 73 | |||
| 74 | 1 | protected function logSection($message) |
|
| 75 | { |
||
| 76 | 1 | echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL; |
|
| 77 | 1 | } |
|
| 78 | |||
| 79 | |||
| 80 | 2 | protected function log($message) |
|
| 81 | 1 | { |
|
| 82 | 2 | echo $message . PHP_EOL; |
|
| 83 | 2 | } |
|
| 84 | |||
| 85 | } |