ValidateCommand.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Composer\Repository\PlatformRepository;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Input\InputArgument;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Composer\Json\JsonFile;
  17. /**
  18. * @author Robert Schönthal <seroscho@googlemail.com>
  19. */
  20. class ValidateCommand extends Command
  21. {
  22. protected function configure()
  23. {
  24. $this
  25. ->setName('validate')
  26. ->setDescription('validates a composer.json')
  27. ->setDefinition(array(
  28. new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', getcwd().'/composer.json')
  29. ))
  30. ->setHelp(<<<EOT
  31. The validate command validates a given composer.json
  32. <info>php composer.phar validate</info> for current location
  33. or
  34. <info>php composer.phar validate /path/to/composer.json</info> for custom location
  35. EOT
  36. )
  37. ;
  38. }
  39. protected function execute(InputInterface $input, OutputInterface $output)
  40. {
  41. $file = $input->getArgument('file');
  42. if (!is_readable($file)) {
  43. throw new \InvalidArgumentException('composer.json not found '.$file);
  44. }
  45. $result = JsonFile::parseJson(file_get_contents($file));
  46. $output->writeln('<info>valid</info> '.$file.' is valid');
  47. }
  48. }