6
6
use Symfony \Bundle \FrameworkBundle \Command \ContainerAwareCommand ;
7
7
use Symfony \Component \Console \Input \InputInterface ;
8
8
use Symfony \Component \Console \Output \OutputInterface ;
9
+ use Symfony \Component \Console \Question \Question ;
9
10
10
11
/**
11
12
* A console command that allows entering an address in order to see how it will be formatted.
@@ -21,16 +22,19 @@ protected function configure()
21
22
22
23
protected function execute (InputInterface $ input , OutputInterface $ output )
23
24
{
24
- $ output ->writeln ('<info>This command takes address information and formats the resulting address. ' );
25
+ $ questionHelper = $ this ->getHelper ('question ' );
26
+ $ ask = function (Question $ question ) use ($ input , $ output , $ questionHelper ) {
27
+ return $ questionHelper ->ask ($ input , $ output , $ question );
28
+ };
25
29
26
- $ dialog = $ this -> getHelperSet ()-> get ( ' dialog ' );
30
+ $ output -> writeln ( ' <info>This command takes address information and formats the resulting address. ' );
27
31
28
- $ country = $ dialog -> ask ($ output , 'What is the two letter ISO3166 code for the country? (e.g. \'US \', \'GB \') ' );
32
+ $ country = $ ask (new Question ( 'What is the two letter ISO3166 code for the country? (e.g. \'US \', \'GB \') ' ) );
29
33
30
- $ addressLines = array () ;
34
+ $ addressLines = [] ;
31
35
$ lineCount = 1 ;
32
36
while ($ lineCount <= 8 ) {
33
- $ line = $ dialog -> ask ($ output , sprintf ('Line %u of the address? (Press Return to complete entering address.) ' , $ lineCount ));
37
+ $ line = $ ask (new Question ( sprintf ('Line %u of the address? (Press Return to complete entering address.) ' , $ lineCount) ));
34
38
if (!empty ($ line )) {
35
39
$ addressLines [] = $ line ;
36
40
} else {
@@ -39,11 +43,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
39
43
$ lineCount ++;
40
44
}
41
45
42
- $ locality = $ dialog -> ask ($ output , 'What is the town/ city of the address? ' );
46
+ $ locality = $ ask (new Question ( 'What is the town/ city of the address? ' ) );
43
47
44
- $ postalCode = $ dialog -> ask ($ output , 'What is the postal code of the address? (Press Return to leave blank.) ' );
48
+ $ postalCode = $ ask (new Question ( 'What is the postal code of the address? (Press Return to leave blank.) ' ) );
45
49
46
- $ region = $ dialog ->ask ($ output , 'What is the region (i.e. state, county or province) of the address? (Press Return to leave blank.) ' );
50
+ $ region = $ ask (
51
+ new Question (
52
+ 'What is the region (i.e. state, county or province) of the address? (Press Return to leave blank.) '
53
+ )
54
+ );
47
55
48
56
$ address = new Address (
49
57
$ country ,
0 commit comments