feature #13548 [TwigBridge] Added support for passing more files to twig:lint command (sustmi)
This PR was merged into the 2.7 branch.
Discussion
----------
[TwigBridge] Added support for passing more files to twig:lint command
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | none
| License | MIT
| Doc PR | none
Commits
-------
6e197a0
[TwigBridge] Added support for passing more files to twig:lint command
This commit is contained in:
commit
db5dee66ee
@ -16,6 +16,7 @@ if (!defined('JSON_PRETTY_PRINT')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@ -62,7 +63,7 @@ class LintCommand extends Command
|
|||||||
$this
|
$this
|
||||||
->setDescription('Lints a template and outputs encountered errors')
|
->setDescription('Lints a template and outputs encountered errors')
|
||||||
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
|
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
|
||||||
->addArgument('filename')
|
->addArgument('filename', InputArgument::IS_ARRAY)
|
||||||
->setHelp(<<<EOF
|
->setHelp(<<<EOF
|
||||||
The <info>%command.name%</info> command lints a template and outputs to STDOUT
|
The <info>%command.name%</info> command lints a template and outputs to STDOUT
|
||||||
the first encountered syntax error.
|
the first encountered syntax error.
|
||||||
@ -94,9 +95,9 @@ EOF
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $input->getArgument('filename');
|
$filenames = $input->getArgument('filename');
|
||||||
|
|
||||||
if (!$filename) {
|
if (0 === count($filenames)) {
|
||||||
if (0 !== ftell(STDIN)) {
|
if (0 !== ftell(STDIN)) {
|
||||||
throw new \RuntimeException("Please provide a filename or pipe template content to STDIN.");
|
throw new \RuntimeException("Please provide a filename or pipe template content to STDIN.");
|
||||||
}
|
}
|
||||||
@ -109,12 +110,21 @@ EOF
|
|||||||
return $this->display($input, $output, array($this->validate($twig, $template, uniqid('sf_'))));
|
return $this->display($input, $output, array($this->validate($twig, $template, uniqid('sf_'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filesInfo = $this->getFilesInfo($twig, $filenames);
|
||||||
|
|
||||||
|
return $this->display($input, $output, $filesInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFilesInfo(\Twig_Environment $twig, array $filenames)
|
||||||
|
{
|
||||||
$filesInfo = array();
|
$filesInfo = array();
|
||||||
|
foreach ($filenames as $filename) {
|
||||||
foreach ($this->findFiles($filename) as $file) {
|
foreach ($this->findFiles($filename) as $file) {
|
||||||
$filesInfo[] = $this->validate($twig, file_get_contents($file), $file);
|
$filesInfo[] = $this->validate($twig, file_get_contents($file), $file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->display($input, $output, $filesInfo);
|
return $filesInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findFiles($filename)
|
protected function findFiles($filename)
|
||||||
|
@ -28,7 +28,7 @@ class LintCommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tester = $this->createCommandTester();
|
$tester = $this->createCommandTester();
|
||||||
$filename = $this->createFile('{{ foo }}');
|
$filename = $this->createFile('{{ foo }}');
|
||||||
|
|
||||||
$ret = $tester->execute(array('filename' => $filename), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE));
|
$ret = $tester->execute(array('filename' => array($filename)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE));
|
||||||
|
|
||||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||||
$this->assertRegExp('/^OK in /', $tester->getDisplay());
|
$this->assertRegExp('/^OK in /', $tester->getDisplay());
|
||||||
@ -39,7 +39,7 @@ class LintCommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tester = $this->createCommandTester();
|
$tester = $this->createCommandTester();
|
||||||
$filename = $this->createFile('{{ foo');
|
$filename = $this->createFile('{{ foo');
|
||||||
|
|
||||||
$ret = $tester->execute(array('filename' => $filename));
|
$ret = $tester->execute(array('filename' => array($filename)));
|
||||||
|
|
||||||
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
|
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
|
||||||
$this->assertRegExp('/^KO in /', $tester->getDisplay());
|
$this->assertRegExp('/^KO in /', $tester->getDisplay());
|
||||||
@ -54,7 +54,7 @@ class LintCommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$filename = $this->createFile('');
|
$filename = $this->createFile('');
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
|
|
||||||
$ret = $tester->execute(array('filename' => $filename));
|
$ret = $tester->execute(array('filename' => array($filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLintFileCompileTimeException()
|
public function testLintFileCompileTimeException()
|
||||||
@ -62,7 +62,7 @@ class LintCommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tester = $this->createCommandTester();
|
$tester = $this->createCommandTester();
|
||||||
$filename = $this->createFile("{{ 2|number_format(2, decimal_point='.', ',') }}");
|
$filename = $this->createFile("{{ 2|number_format(2, decimal_point='.', ',') }}");
|
||||||
|
|
||||||
$ret = $tester->execute(array('filename' => $filename));
|
$ret = $tester->execute(array('filename' => array($filename)));
|
||||||
|
|
||||||
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
|
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
|
||||||
$this->assertRegExp('/^KO in /', $tester->getDisplay());
|
$this->assertRegExp('/^KO in /', $tester->getDisplay());
|
||||||
|
Reference in New Issue
Block a user