예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!file_exists($file)) {
         $output->writeln('<error>' . $file . ' not found.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     $validator = new ConfigValidator($this->getIO());
     list($errors, $publishErrors, $warnings) = $validator->validate($file);
     if (!$errors && !$publishErrors && !$warnings) {
         $output->writeln('<info>' . $file . ' is valid</info>');
     } elseif (!$errors && !$publishErrors) {
         $output->writeln('<info>' . $file . ' is valid, but with a few warnings</info>');
         $output->writeln('<warning>See http://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
     } elseif (!$errors) {
         $output->writeln('<info>' . $file . ' is valid for simple usage with composer but has</info>');
         $output->writeln('<info>strict errors that make it unable to be published as a package:</info>');
         $output->writeln('<warning>See http://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
     } else {
         $output->writeln('<error>' . $file . ' is invalid, the following errors/warnings were found:</error>');
     }
     $messages = array('error' => array_merge($errors, $publishErrors), 'warning' => $warnings);
     foreach ($messages as $style => $msgs) {
         foreach ($msgs as $msg) {
             $output->writeln('<' . $style . '>' . $msg . '</' . $style . '>');
         }
     }
     return $errors || $publishErrors ? 1 : 0;
 }
예제 #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $io = $this->getIO();
     if (!file_exists($file)) {
         $io->writeError('<error>' . $file . ' not found.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $io->writeError('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     $validator = new ConfigValidator($io);
     $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
     $checkPublish = !$input->getOption('no-check-publish');
     list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
     $checkLock = !$input->getOption('no-check-lock');
     $lockErrors = array();
     $composer = Factory::create($io, $file);
     $locker = $composer->getLocker();
     if ($locker->isLocked() && !$locker->isFresh()) {
         $lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json.';
     }
     // output errors/warnings
     if (!$errors && !$publishErrors && !$warnings) {
         $io->write('<info>' . $file . ' is valid</info>');
     } elseif (!$errors && !$publishErrors) {
         $io->writeError('<info>' . $file . ' is valid, but with a few warnings</info>');
         $io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
     } elseif (!$errors) {
         $io->writeError('<info>' . $file . ' is valid for simple usage with composer but has</info>');
         $io->writeError('<info>strict errors that make it unable to be published as a package:</info>');
         $io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
     } else {
         $io->writeError('<error>' . $file . ' is invalid, the following errors/warnings were found:</error>');
     }
     $messages = array('error' => $errors, 'warning' => $warnings);
     // If checking publish errors, display them as errors, otherwise just show them as warnings
     if ($checkPublish) {
         $messages['error'] = array_merge($messages['error'], $publishErrors);
     } else {
         $messages['warning'] = array_merge($messages['warning'], $publishErrors);
     }
     // If checking lock errors, display them as errors, otherwise just show them as warnings
     if ($checkLock) {
         $messages['error'] = array_merge($messages['error'], $lockErrors);
     } else {
         $messages['warning'] = array_merge($messages['warning'], $lockErrors);
     }
     foreach ($messages as $style => $msgs) {
         foreach ($msgs as $msg) {
             $io->writeError('<' . $style . '>' . $msg . '</' . $style . '>');
         }
     }
     return $errors || $publishErrors && $checkPublish || $lockErrors && $checkLock ? 1 : 0;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $configFile = new \File($this->configPathname);
     if ($input->post('save')) {
         $tempPathname = $this->configPathname . '~';
         $tempFile = new \File($tempPathname);
         $config = $input->postRaw('config');
         $config = html_entity_decode($config, ENT_QUOTES, 'UTF-8');
         $tempFile->write($config);
         $tempFile->close();
         $validator = new ConfigValidator($this->io);
         list($errors, $publishErrors, $warnings) = $validator->validate(TL_ROOT . '/' . $tempPathname);
         if (!$errors && !$publishErrors) {
             $_SESSION['TL_CONFIRM'][] = $GLOBALS['TL_LANG']['composer_client']['configValid'];
             $this->import('Files');
             $this->Files->rename($tempPathname, $this->configPathname);
         } else {
             $tempFile->delete();
             $_SESSION['COMPOSER_EDIT_CONFIG'] = $config;
             if ($errors) {
                 foreach ($errors as $message) {
                     $_SESSION['TL_ERROR'][] = 'Error: ' . $message;
                 }
             }
             if ($publishErrors) {
                 foreach ($publishErrors as $message) {
                     $_SESSION['TL_ERROR'][] = 'Publish error: ' . $message;
                 }
             }
         }
         if ($warnings) {
             foreach ($warnings as $message) {
                 $_SESSION['TL_ERROR'][] = 'Warning: ' . $message;
             }
         }
         $this->reload();
     }
     if (isset($_SESSION['COMPOSER_EDIT_CONFIG'])) {
         $config = $_SESSION['COMPOSER_EDIT_CONFIG'];
         unset($_SESSION['COMPOSER_EDIT_CONFIG']);
     } else {
         $config = $configFile->getContent();
     }
     $template = new \BackendTemplate('be_composer_client_editor');
     $template->composer = $this->composer;
     $template->config = $config;
     return $template->parse();
 }
예제 #4
0
 private function checkComposerSchema()
 {
     $validator = new ConfigValidator($this->getIO());
     list($errors, $publishErrors, $warnings) = $validator->validate(Factory::getComposerFile());
     if ($errors || $publishErrors || $warnings) {
         $messages = array('error' => array_merge($errors, $publishErrors), 'warning' => $warnings);
         $output = '';
         foreach ($messages as $style => $msgs) {
             foreach ($msgs as $msg) {
                 $output .= '<' . $style . '>' . $msg . '</' . $style . '>' . PHP_EOL;
             }
         }
         return rtrim($output);
     }
     return true;
 }
예제 #5
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $io = $this->getIO();
     if (!file_exists($file)) {
         $io->writeError('<error>' . $file . ' not found.</error>');
         return 3;
     }
     if (!is_readable($file)) {
         $io->writeError('<error>' . $file . ' is not readable.</error>');
         return 3;
     }
     $validator = new ConfigValidator($io);
     $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
     $checkPublish = !$input->getOption('no-check-publish');
     $checkLock = !$input->getOption('no-check-lock');
     $isStrict = $input->getOption('strict');
     list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
     $lockErrors = array();
     $composer = Factory::create($io, $file);
     $locker = $composer->getLocker();
     if ($locker->isLocked() && !$locker->isFresh()) {
         $lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json, it is recommended that you run `composer update`.';
     }
     $this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true);
     $exitCode = $errors || $publishErrors && $checkPublish || $lockErrors && $checkLock ? 2 : ($isStrict && $warnings ? 1 : 0);
     if ($input->getOption('with-dependencies')) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         foreach ($localRepo->getPackages() as $package) {
             $path = $composer->getInstallationManager()->getInstallPath($package);
             $file = $path . '/composer.json';
             if (is_dir($path) && file_exists($file)) {
                 list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
                 $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors);
                 $depCode = $errors || $publishErrors && $checkPublish ? 2 : ($isStrict && $warnings ? 1 : 0);
                 $exitCode = max($depCode, $exitCode);
             }
         }
     }
     $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'validate', $input, $output);
     $eventCode = $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
     $exitCode = max($eventCode, $exitCode);
     return $exitCode;
 }
 /**
  * Check the json contents and return the error array.
  *
  * @param string $content The Json content.
  *
  * @return array<string,string[]>
  */
 private function checkComposerJson($content)
 {
     $tempFile = $this->getTensideDataDir() . '/composer.json.tmp';
     file_put_contents($tempFile, $content);
     $validator = new ConfigValidator(new BufferIO());
     list($errors, $publishErrors, $warnings) = $validator->validate($tempFile);
     unlink($tempFile);
     $errors = array_merge($errors, $publishErrors);
     $errors = str_replace(dirname($tempFile), '', $errors);
     $warnings = str_replace(dirname($tempFile), '', $warnings);
     $lineMapper = function ($str) {
         if (preg_match('#Parse error on line (\\d+)#', $str, $match)) {
             return ['line' => $match[1], 'msg' => $str];
         }
         return ['line' => 0, 'msg' => $str];
     };
     return ['errors' => array_map($lineMapper, $errors), 'warnings' => array_map($lineMapper, $warnings)];
 }
예제 #7
0
 /**
  * Test ConfigValidator warns on commit reference
  */
 public function testConfigValidatorCommitRefWarning()
 {
     $configValidator = new ConfigValidator(new NullIO());
     list(, , $warnings) = $configValidator->validate(__DIR__ . '/Fixtures/composer_commit-ref.json');
     $this->assertEquals(true, in_array('The package "some/package" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.', $warnings));
 }