/** * @throws \RuntimeException * * @param string $config * * @return RootPackage */ public function getPackageFromConfigFile($config) { if (!file_exists($config)) { throw new \RuntimeException('File "' . $config . '" not found'); } return $this->loader->load((new JsonFile($config))->read(), 'Composer\\Package\\RootPackage'); }
/** * Loads the real package. * * @param LazyPackageInterface $package * * @return CompletePackageInterface|false */ protected function loadRealPackage(LazyPackageInterface $package) { $realPackage = false; try { $data = $this->driver->getComposerInformation($this->identifier); $valid = is_array($data); $data = $this->preProcess($this->driver, $this->validateData($data), $this->identifier); if ($this->verbose) { $this->io->write('Importing ' . ($valid ? '' : 'empty ') . $this->type . ' '.$data['version'].' ('.$data['version_normalized'].')'); } /* @var CompletePackageInterface $realPackage */ $realPackage = $this->loader->load($data); } catch (\Exception $e) { if ($this->verbose) { $filename = $this->assetType->getFilename(); $this->io->write('<'.$this->getIoTag().'>Skipped ' . $this->type . ' '.$package->getPrettyVersion().', '.($e instanceof TransportException ? 'no ' . $filename . ' file was found' : $e->getMessage()).'</'.$this->getIoTag().'>'); } } $this->driver->cleanup(); return $realPackage; }
private function getComposerInformation(\SplFileInfo $file) { $zip = new \ZipArchive(); $zip->open($file->getPathname()); if (0 == $zip->numFiles) { return false; } $foundFileIndex = $this->locateFile($zip, 'composer.json'); if (false === $foundFileIndex) { return false; } $configurationFileName = $zip->getNameIndex($foundFileIndex); $composerFile = "zip://{$file->getPathname()}#{$configurationFileName}"; $json = file_get_contents($composerFile); $package = JsonFile::parseJson($json, $composerFile); $package['dist'] = array('type' => 'zip', 'url' => strtr($file->getPathname(), '\\', '/'), 'shasum' => sha1_file($file->getRealPath())); $package = $this->loader->load($package); return $package; }
/** * @expectedException \RuntimeException */ public function testGetPackageFromConfigFileNoFile() { $this->loader->expects($this->never())->method('load'); $this->composer->getPackageFromConfigFile($this->root_dir . 'composer.json'); }