|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Command; |
| 13 | + |
| 14 | +use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Input\InputInterface; |
| 16 | +use Symfony\Component\Console\Output\OutputInterface; |
| 17 | +use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand; |
| 18 | + |
| 19 | +/** |
| 20 | + * Validates XLIFF files syntax and outputs encountered errors. |
| 21 | + * |
| 22 | + * @author Grégoire Pineau <lyrixx@lyrixx.info> |
| 23 | + * @author Robin Chalas <robin.chalas@gmail.com> |
| 24 | + * @author Javier Eguiluz <javier.eguiluz@gmail.com> |
| 25 | + */ |
| 26 | +class XliffLintCommand extends Command |
| 27 | +{ |
| 28 | + private $command; |
| 29 | + |
| 30 | + /** |
| 31 | + * {@inheritdoc} |
| 32 | + */ |
| 33 | + protected function configure() |
| 34 | + { |
| 35 | + $this->setName('lint:xliff'); |
| 36 | + |
| 37 | + if (!$this->isEnabled()) { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + $directoryIteratorProvider = function ($directory, $default) { |
| 42 | + if (!is_dir($directory)) { |
| 43 | + $directory = $this->getApplication()->getKernel()->locateResource($directory); |
| 44 | + } |
| 45 | + |
| 46 | + return $default($directory); |
| 47 | + }; |
| 48 | + |
| 49 | + $isReadableProvider = function ($fileOrDirectory, $default) { |
| 50 | + return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory); |
| 51 | + }; |
| 52 | + |
| 53 | + $this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider); |
| 54 | + |
| 55 | + $this |
| 56 | + ->setDescription($this->command->getDescription()) |
| 57 | + ->setDefinition($this->command->getDefinition()) |
| 58 | + ->setHelp($this->command->getHelp().<<<'EOF' |
| 59 | +
|
| 60 | +Or find all files in a bundle: |
| 61 | +
|
| 62 | + <info>php %command.full_name% @AcmeDemoBundle</info> |
| 63 | + |
| 64 | +EOF |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * {@inheritdoc} |
| 70 | + */ |
| 71 | + public function isEnabled() |
| 72 | + { |
| 73 | + return class_exists(BaseLintCommand::class); |
| 74 | + } |
| 75 | + |
| 76 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 77 | + { |
| 78 | + return $this->command->execute($input, $output); |
| 79 | + } |
| 80 | +} |
0 commit comments