* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Command; use Composer\Package\Loader\ValidatingArrayLoader; use Composer\Util\ConfigValidator; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** * ValidateCommand * * @author Robert Schönthal * @author Jordi Boggiano */ class ValidateCommand extends Command { /** * configure */ protected function configure() { $this ->setName('validate') ->setDescription('Validates a composer.json') ->setDefinition(array( new InputOption('no-check-all', null, InputOption::VALUE_NONE, 'Do not make a complete validation'), new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', './composer.json') )) ->setHelp(<<getArgument('file'); if (!file_exists($file)) { $this->getIO()->writeError('' . $file . ' not found.'); return 1; } if (!is_readable($file)) { $this->getIO()->writeError('' . $file . ' is not readable.'); return 1; } $validator = new ConfigValidator($this->getIO()); $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL; list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); // output errors/warnings if (!$errors && !$publishErrors && !$warnings) { $this->getIO()->write('' . $file . ' is valid'); } elseif (!$errors && !$publishErrors) { $this->getIO()->writeError('' . $file . ' is valid, but with a few warnings'); $this->getIO()->writeError('See http://getcomposer.org/doc/04-schema.md for details on the schema'); } elseif (!$errors) { $this->getIO()->writeError('' . $file . ' is valid for simple usage with composer but has'); $this->getIO()->writeError('strict errors that make it unable to be published as a package:'); $this->getIO()->writeError('See http://getcomposer.org/doc/04-schema.md for details on the schema'); } else { $this->getIO()->writeError('' . $file . ' is invalid, the following errors/warnings were found:'); } $messages = array( 'error' => array_merge($errors, $publishErrors), 'warning' => $warnings, ); foreach ($messages as $style => $msgs) { foreach ($msgs as $msg) { $this->getIO()->writeError('<' . $style . '>' . $msg . ''); } } return $errors || $publishErrors ? 1 : 0; } }