public function dump($fname = null)
{
if (!$this->package) {
$this->load();
}
if ($fname) {
$this->jsonPath = $fname;
}
$version = new Header\Version($this->package);
if ($version != $this->package->getPrettyVersion()) {
throw new \Exception("Version mismatch - '" . $version . "' != '" . $this->package->getVersion() . '. in source vs JSON');
}
$dumper = new Dumper();
$dumper->dumpToFile($this->package, $this->jsonPath, false);
}
protected function readPackage($path) { $jsonLoader = new Package\Util\JSON\Loader(new Package\Util\Loader()); $package = null; if (file_exists($path . DIRECTORY_SEPARATOR . 'composer.json')) { $package = $jsonLoader->load($path . DIRECTORY_SEPARATOR . 'composer.json'); } if (null === $package && $this->noConvert) { throw new \RuntimeException('XML package are not supported. Please convert it before install'); } if (null === $package) { try { $loader = new Package\PHP\Util\XML\Loader(new Package\Util\Loader()); $pkgXml = new PackageXml($path); $pkgXml->dump(); $jsonPath = $pkgXml->getJsonPath(); $package = $jsonLoader->load($jsonPath); } catch (Exception $e) { /* pass for now, be compatible */ } } if (null == $package) { /* Just ensure it's correct, */ throw new \Exception("Couldn't read package info at '{$path}'"); } $package->setRootDir(realpath($path)); (new Header\Version($package))->updateJSON(); return $package; }