|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
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 Sensio\Bundle\GeneratorBundle\Command\Helper; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Console\Helper\DialogHelper as BaseDialogHelper; |
|
|
15 |
use Symfony\Component\Console\Output\OutputInterface; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* Generates bundles. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class DialogHelper extends BaseDialogHelper |
|
|
23 |
{ |
|
|
24 |
public function writeGeneratorSummary(OutputInterface $output, $errors) |
|
|
25 |
{ |
|
|
26 |
if (!$errors) { |
|
|
27 |
$this->writeSection($output, 'You can now start using the generated code!'); |
|
|
28 |
} else { |
|
|
29 |
$this->writeSection($output, array( |
|
|
30 |
'The command was not able to configure everything automatically.', |
|
|
31 |
'You must do the following changes manually.', |
|
|
32 |
), 'error'); |
|
|
33 |
|
|
|
34 |
$output->writeln($errors); |
|
|
35 |
} |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
public function getRunner(OutputInterface $output, &$errors) |
|
|
39 |
{ |
|
|
40 |
$runner = function ($err) use ($output, &$errors) { |
|
|
41 |
if ($err) { |
|
|
42 |
$output->writeln('<fg=red>FAILED</>'); |
|
|
43 |
$errors = array_merge($errors, $err); |
|
|
44 |
} else { |
|
|
45 |
$output->writeln('<info>OK</info>'); |
|
|
46 |
} |
|
|
47 |
}; |
|
|
48 |
|
|
|
49 |
return $runner; |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
public function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white') |
|
|
53 |
{ |
|
|
54 |
$output->writeln(array( |
|
|
55 |
'', |
|
|
56 |
$this->getHelperSet()->get('formatter')->formatBlock($text, $style, true), |
|
|
57 |
'', |
|
|
58 |
)); |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
public function getQuestion($question, $default, $sep = ':') |
|
|
62 |
{ |
|
|
63 |
return $default ? sprintf('<info>%s</info> [<comment>%s</comment>]%s ', $question, $default, $sep) : sprintf('<info>%s</info>%s ', $question, $sep); |
|
|
64 |
} |
|
|
65 |
} |