|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Conveyor package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Jeroen Fiege <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Webcreate\Conveyor\Subscriber; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
16
|
|
|
use Webcreate\Conveyor\Event\TaskRunnerEvents; |
|
17
|
|
|
use Webcreate\Conveyor\IO\IOInterface; |
|
18
|
|
|
|
|
19
|
|
|
class TaskRunnerSubscriber implements EventSubscriberInterface |
|
20
|
|
|
{ |
|
21
|
|
|
protected $io; |
|
|
|
|
|
|
22
|
|
|
protected $showProgress = false; |
|
23
|
|
|
protected $needsNewline = false; |
|
24
|
|
|
|
|
25
|
1 |
|
public function __construct(IOInterface $io) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
1 |
|
$this->io = $io; |
|
28
|
1 |
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public static function getSubscribedEvents() |
|
31
|
|
|
{ |
|
32
|
|
|
return array( |
|
33
|
1 |
|
TaskRunnerEvents::TASKRUNNER_PRE_EXECUTE_TASK => array('onTaskPreExecute'), |
|
34
|
|
|
TaskRunnerEvents::TASKRUNNER_POST_EXECUTE_TASK => array('onTaskPostExecute'), |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
public function onTaskPreExecute(GenericEvent $event) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$task = $event->getSubject(); |
|
41
|
|
|
$io = $this->io; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$self = $this; |
|
44
|
|
|
|
|
45
|
|
|
$task->setOutput(function ($output) use ($io, $self) { |
|
46
|
|
|
if ($io->isVerbose()) { |
|
47
|
|
|
$io->write(sprintf('%s', $output)); |
|
48
|
|
|
$self->needsNewline = false; |
|
49
|
|
|
} else { |
|
50
|
|
|
$io->overwrite(sprintf('%s', $output), false); |
|
51
|
|
|
$self->needsNewline = true; |
|
52
|
|
|
} |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
if ($event->getArgument('index') > 0) { |
|
56
|
|
|
if (true === $this->needsNewline) { |
|
57
|
|
|
$this->io->write(''); |
|
58
|
|
|
$this->needsNewline = false; |
|
59
|
|
|
} |
|
60
|
|
|
$this->io->write(''); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->io->write(sprintf('- Executing task <info>%s</info>', get_class($task))); |
|
64
|
|
|
$this->io->increaseIndention(2); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function onTaskPostExecute(GenericEvent $event) |
|
68
|
|
|
{ |
|
69
|
|
|
$task = $event->getSubject(); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->io->write(''); |
|
72
|
|
|
|
|
73
|
|
|
$this->io->decreaseIndention(2); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.