Skip to content

Commit a94b98c

Browse files
author
Shawn McCool
authored
Merge pull request #44 from devonzara/master
Update for Symfony 3 components
2 parents 2ae582e + d48ec33 commit a94b98c

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

src/AutoComplete.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php namespace BackupManager\Laravel;
22

3+
use Symfony\Component\Console\Question\Question;
4+
use Symfony\Component\Console\Exception\InvalidArgumentException;
5+
36
/**
47
* Class AutoComplete
8+
*
59
* @package BackupManager\Laravel
610
*/
711
trait AutoComplete {
@@ -21,7 +25,40 @@ public function autocomplete($dialog, array $list, $default = null) {
2125
}
2226
return $item;
2327
};
28+
29+
try {
30+
return $this->useSymfontDialog($dialog, $list, $default, $validation);
31+
} catch (InvalidArgumentException $error) {
32+
//
33+
} finally {
34+
return $this->useSymfonyQuestion($dialog, $default, $validation);
35+
}
36+
}
37+
38+
/**
39+
* @param $dialog
40+
* @param array $list
41+
* @param null $default
42+
* @return mixed
43+
*/
44+
protected function useSymfontDialog($dialog, array $list, $default = null, $validation) {
2445
$helper = $this->getHelperSet()->get('dialog');
25-
return $helper->askAndValidate($this->output, "<question>{$dialog}</question>", $validation, false, $default, $list);
46+
47+
return $helper->askAndValidate(
48+
$this->output, "<question>{$dialog}</question>", $validation, false, $default, $list
49+
);
50+
}
51+
52+
/**
53+
* @param $dialog
54+
* @param null $default
55+
* @return mixed
56+
*/
57+
protected function useSymfonyQuestion($dialog, $default = null, $validation) {
58+
$question = new Question($dialog . ' ', $default);
59+
$question->setValidator($validation);
60+
$helper = $this->getHelper('question');
61+
62+
return $helper->ask($this->input, $this->output, $question);
2663
}
2764
}

src/Laravel4Compatibility.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php namespace BackupManager\Laravel;
22

3+
use Symfony\Component\Console\Helper\Table;
4+
use Symfony\Component\Console\Exception\InvalidArgumentException;
5+
36
/**
47
* Class Laravel4Compatibility
58
* @package BackupManager\Laravel
@@ -12,7 +15,14 @@ trait Laravel4Compatibility {
1215
* @return void
1316
*/
1417
public function table(array $headers, array $rows, $style = 'default') {
15-
$table = $this->getHelperSet()->get('table');
18+
try {
19+
$table = $this->getHelperSet()->get('table');
20+
} catch (InvalidArgumentException $error) {
21+
//
22+
} finally {
23+
$table = new Table($this->output);
24+
}
25+
1626
$table->setHeaders($headers);
1727
$table->setRows($rows);
1828
$table->render($this->output);

src/Laravel50Compatibility.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php namespace BackupManager\Laravel;
22

3+
use Symfony\Component\Console\Helper\Table;
4+
use Symfony\Component\Console\Exception\InvalidArgumentException;
5+
36
/**
47
* Class Laravel5Compatibility
58
* @package BackupManager\Laravel
@@ -12,7 +15,14 @@ trait Laravel50Compatibility {
1215
* @return void
1316
*/
1417
public function table($headers, $rows, $style = 'default') {
15-
$table = $this->getHelperSet()->get('table');
18+
try {
19+
$table = $this->getHelperSet()->get('table');
20+
} catch (InvalidArgumentException $error) {
21+
//
22+
} finally {
23+
$table = new Table($this->output);
24+
}
25+
1626
$table->setHeaders($headers);
1727
$table->setRows($rows);
1828
$table->render($this->output);

src/Laravel51Compatibility.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php namespace BackupManager\Laravel;
22

3+
use Symfony\Component\Console\Helper\Table;
4+
use Symfony\Component\Console\Exception\InvalidArgumentException;
5+
36
/**
47
* Class Laravel5Compatibility
58
* @package BackupManager\Laravel
@@ -12,7 +15,14 @@ trait Laravel51Compatibility {
1215
* @return void
1316
*/
1417
public function table(array $headers, $rows, $style = 'default') {
15-
$table = $this->getHelperSet()->get('table');
18+
try {
19+
$table = $this->getHelperSet()->get('table');
20+
} catch (InvalidArgumentException $error) {
21+
//
22+
} finally {
23+
$table = new Table($this->output);
24+
}
25+
1626
$table->setHeaders($headers);
1727
$table->setRows($rows);
1828
$table->render($this->output);

0 commit comments

Comments
 (0)