This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from falvarez/Symfony3Compatibility
Add compatibility with Symfony > 3.0
- Loading branch information
Showing
3 changed files
with
64 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
|
||
namespace Lsw\MemcacheBundle\Command; | ||
|
||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\DialogHelper; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\Question; | ||
|
||
class InteractHelper | ||
{ | ||
private $questionText = 'Please give the pool'; | ||
private $exceptionMessage = 'pool can not be empty'; | ||
private $defaultPool = 'default'; | ||
|
||
private function askForPoolQuestion(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output) | ||
{ | ||
$question = new Question("$this->questionText ($this->defaultPool)", $this->defaultPool); | ||
$question->setValidator(function($pool) { | ||
if (empty($pool)) { | ||
throw new \Exception($this->exceptionMessage); | ||
} | ||
return $pool; | ||
}); | ||
|
||
return $questionHelper->ask( | ||
$input, | ||
$output, | ||
$question | ||
); | ||
} | ||
|
||
private function askForPoolDialog(DialogHelper $dialogHelper, $output) | ||
{ | ||
$pool = $dialogHelper->askAndValidate( | ||
$output, | ||
$this->questionText, | ||
function($pool) | ||
{ | ||
if (empty($pool)) { | ||
throw new \Exception($this->exceptionMessage); | ||
} | ||
|
||
return $pool; | ||
} | ||
); | ||
return $pool; | ||
} | ||
|
||
public function askForPool(Command $command, InputInterface $input, OutputInterface $output) | ||
{ | ||
if ($command->getHelperSet()->has('question')) { | ||
return self::askForPoolQuestion($command->getHelper('question'), $input, $output); | ||
} else { | ||
return self::askForPoolDialog($command->getHelper('dialog'), $output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters