/**
  * Loads the configuration file and returns it.
  *
  * @param string $file The configuration file path.
  *
  * @return Configuration The configuration settings.
  */
 public function loadFile($file = null)
 {
     if (null === $file) {
         $file = $this->getDefaultPath();
     }
     $json = $this->json->decodeFile($file);
     $this->json->validate($this->json->decodeFile(BOX_SCHEMA_FILE), $json);
     return new Configuration($file, $json);
 }
Esempio n. 2
0
 /**
  * Loads the configuration file and returns it.
  *
  * @param string $file The configuration file path.
  *
  * @return Configuration The configuration settings.
  */
 public function loadFile($file = null)
 {
     if (null === $file) {
         $file = $this->getDefaultPath();
     }
     $json = $this->json->decodeFile($file);
     if (isset($json->import)) {
         if (!Path::isAbsolute($json->import)) {
             $json->import = Path::join(array(dirname($file), $json->import));
         }
         $json = (object) array_merge((array) $this->json->decodeFile($json->import), (array) $json);
     }
     $this->json->validate($this->json->decodeFile(CRATE_SCHEMA_FILE), $json);
     return new Configuration($file, $json);
 }
Esempio n. 3
0
 public function fixRemoteDir($remoteDir, OutputInterface $output, array $options = [])
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(['level' => 'symfony', 'dry-run' => true]);
     $options = $resolver->resolve($options);
     $this->getSshExec()->passthru(strtr('php-cs-fixer fix %command_options% --level=%level% --no-interaction %dir%', ['%level%' => $options['level'], '%dir%' => $remoteDir, '%command_options%' => $options['dry-run'] ? '--dry-run --diff' : '']));
     $returnStatus = $this->getSshExec()->getLastReturnStatus();
     $this->getRemoteFilesystem()->mkdir($this->remotePhpcsStandardDir);
     $tmpDir = sprintf('%s/jarvis/phpcs_standard_dir', $this->cacheDir);
     $this->getLocalFilesystem()->mirror($this->localPhpcsStandardDir, $tmpDir);
     $this->getRemoteFilesystem()->syncLocalToRemote($tmpDir, $this->remotePhpcsStandardDir, ['delete' => true]);
     $jsonReport = $this->getSshExec()->exec(strtr('phpcs %dir% --extensions=php --standard=%standard% --warning-severity=%warning-severity% --encoding=utf-8 --report=json', ['%dir%' => $remoteDir, '%standard%' => $this->remotePhpcsStandardDir, '%warning-severity%' => 0]));
     $json = new Json();
     try {
         $data = $json->decode($jsonReport);
     } catch (\Seld\JsonLint\ParsingException $e) {
         $output->writeln(sprintf('<error>%s</error>', $jsonReport));
         throw $e;
     }
     if ($data->totals->errors > 0) {
         $highlighter = new Highlighter(new ConsoleColor());
         $output->writeln(sprintf('<error>%s errors detected</error>', $data->totals->errors));
         foreach ($data->files as $filepath => $metadata) {
             if ($metadata->errors > 0) {
                 foreach ($metadata->messages as $error) {
                     $output->writeln(sprintf('<error>%s in "%s" at line %d</error>', strtr($error->message, [' use NULL() instead' => '']), strtr($filepath, [$remoteDir => '']), $error->line));
                     $fileContent = $this->getRemoteFilesystem()->getRemoteFileContent($filepath);
                     // $output->writeln(
                     //     $highlighter->getCodeSnippet($fileContent, $error->line),
                     //     OutputInterface::OUTPUT_RAW
                     // );
                 }
             }
         }
         $returnStatus += 1;
     }
     return $returnStatus;
 }
 /**
  * @return array
  */
 private function parse()
 {
     if (file_exists($this->filePath)) {
         $json = new Json();
         $data = $json->decode(file_get_contents($this->filePath));
         return (array) $data->projects;
     }
     return [];
 }
Esempio n. 5
0
 /**
  * @override
  */
 protected function doLoad($file)
 {
     return $this->json->decodeFile($file, true);
 }
Esempio n. 6
0
 /**
  * Decode json file
  *
  * @param  string  $filepath
  * @param  boolean $assoc
  * @param  integer $depth
  * @param  integer $options
  * @return array
  */
 private function decodeJsonFile($filepath)
 {
     $json = file_get_contents($filepath);
     // search and remove comments like /* */ and //
     $json = preg_replace("#(/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/)|([\\s\t]//.*)|(^//.*)#", '', $json);
     $jsonReader = new Json();
     $assoc = true;
     $depth = 512;
     $options = 0;
     return $jsonReader->decode($json, $assoc, $depth, $options);
 }
Esempio n. 7
0
 /**
  * @param string $composerJsonFileContent
  * @param string $composerLockFileContent
  * @param string $installedFileDevContent
  * @param string $installedFileContent
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return \JMS\Composer\Graph\DependencyGraph
  */
 public function analyze($composerJsonFileContent, $composerLockFileContent, $installedFileContent, $installedFileDevContent = null, $connectRequireDev = false)
 {
     $json = new Json();
     $rootPackageData = $json->decode($composerJsonFileContent, true);
     if (!isset($rootPackageData['name'])) {
         $rootPackageData['name'] = '__root';
     }
     // If there is no composer.lock file, then either the project has no
     // dependencies, or the dependencies were not installed.
     if (empty($composerLockFileContent)) {
         if ($this->hasDependencies($rootPackageData)) {
             throw new \RuntimeException(sprintf('You need to run "composer install" in "%s" before analyzing dependencies.', $dir));
         }
         $graph = new DependencyGraph(new PackageNode($rootPackageData['name'], $rootPackageData));
         // Connect built-in dependencies for example on the PHP version, or
         // on PHP extensions. For these, composer does not create a composer.lock.
         if (isset($rootPackageData['require'])) {
             foreach ($rootPackageData['require'] as $name => $versionConstraint) {
                 $this->connect($graph, $rootPackageData['name'], $name, $versionConstraint);
             }
         }
         if ($connectRequireDev && isset($rootPackageData['require-dev'])) {
             foreach ($rootPackageData['require-dev'] as $name => $versionConstraint) {
                 $this->connect($graph, $rootPackageData['name'], $name, $versionConstraint);
             }
         }
         return $graph;
     }
     $graph = new DependencyGraph(new PackageNode($rootPackageData['name'], $rootPackageData));
     // Add regular packages.
     if (!empty($installedFileContent)) {
         foreach ($json->decode($installedFileContent, true) as $packageData) {
             $graph->createPackage($packageData['name'], $packageData);
             $this->processLockedData($graph, $packageData);
         }
     }
     // Add development packages.
     if ($connectRequireDev && !empty($installedFileDevContent)) {
         foreach ($json->decode($installedFileDevContent, true) as $packageData) {
             $graph->createPackage($packageData['name'], $packageData);
             $this->processLockedData($graph, $packageData);
         }
     }
     // Connect dependent packages.
     foreach ($graph->getPackages() as $packageNode) {
         $packageData = $packageNode->getData();
         if (isset($packageData['require'])) {
             foreach ($packageData['require'] as $name => $version) {
                 $this->connect($graph, $packageData['name'], $name, $version);
             }
         }
         if ($connectRequireDev && isset($packageData['require-dev'])) {
             foreach ($packageData['require-dev'] as $name => $version) {
                 $this->connect($graph, $packageData['name'], $name, $version);
             }
         }
     }
     // Populate graph with versions, and source references.
     $lockData = $json->decode($composerLockFileContent, true);
     if (isset($lockData['packages'])) {
         foreach ($lockData['packages'] as $lockedPackageData) {
             $this->processLockedData($graph, $lockedPackageData);
         }
     }
     if ($connectRequireDev && isset($lockData['packages-dev'])) {
         foreach ($lockData['packages-dev'] as $lockedPackageData) {
             $this->processLockedData($graph, $lockedPackageData);
         }
     }
     return $graph;
 }
Esempio n. 8
0
 /**
  * Validates the data, processes it, and returns a new instance of Manifest.
  *
  * @param array $decoded The decoded JSON data.
  * @param Json  $json    The Json instance used to decode the data.
  *
  * @return Manifest The new instance.
  */
 private static function create($decoded, Json $json)
 {
     $json->validate($json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA), $decoded);
     $updates = array();
     foreach ($decoded as $update) {
         $updates[] = new Update($update->name, $update->sha1, $update->url, Version::create($update->version), isset($update->publicKey) ? $update->publicKey : null);
     }
     usort($updates, function (Update $a, Update $b) {
         return $a->getVersion()->compareTo($b->getVersion());
     });
     return new static($updates);
 }