Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #74 from falvarez/Symfony3Compatibility
Browse files Browse the repository at this point in the history
Add compatibility with Symfony > 3.0
  • Loading branch information
mevdschee authored Jun 23, 2016
2 parents 04d6efa + b455870 commit 736b09c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
13 changes: 1 addition & 12 deletions Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
protected function interact(InputInterface $input, OutputInterface $output)
{
if (!$input->getArgument('pool')) {
$pool = $this->getHelper('dialog')->askAndValidate(
$output,
'Please give the pool:',
function($pool)
{
if (empty($pool)) {
throw new \Exception('pool can not be empty');
}

return $pool;
}
);
$pool = (new InteractHelper())->askForPool($this, $input, $output);
$input->setArgument('pool', $pool);
}
}
Expand Down
62 changes: 62 additions & 0 deletions Command/InteractHelper.php
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);
}
}
}
13 changes: 1 addition & 12 deletions Command/StatisticsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
protected function interact(InputInterface $input, OutputInterface $output)
{
if (!$input->getArgument('pool')) {
$pool = $this->getHelper('dialog')->askAndValidate(
$output,
'Please give the pool:',
function($pool)
{
if (empty($pool)) {
throw new \Exception('pool can not be empty');
}

return $pool;
}
);
$pool = (new InteractHelper())->askForPool($this, $input, $output);
$input->setArgument('pool', $pool);
}
}
Expand Down

0 comments on commit 736b09c

Please sign in to comment.