/** * @param string $lockPath * * @return Composer * * @throws ComposerFileDoesNotExistsException * @throws ComposerFileIsInvalidException */ public function fromLock($lockPath) { if (!is_file($lockPath)) { throw new ComposerFileDoesNotExistsException($lockPath); } $file = new SplFileInfo($lockPath, null, null); $decodedData = json_decode($file->getContents(), true); if (json_last_error() != JSON_ERROR_NONE) { throw new ComposerFileIsInvalidException($lockPath); } $packages = array(); foreach ($decodedData['packages'] as $package) { $packages[] = Package::fromArray($package); } $devPackages = array(); foreach ($decodedData['packages-dev'] as $package) { $devPackages[] = Package::fromArray($package); } return new Composer($packages, $devPackages, true); }
public function testGetPackagePath() { $package = Package::fromArray(array('name' => 'vendor/lib', 'version' => '1.0.0')); $this->assertEquals('vendor/vendor/lib', $package->getPackagePath('vendor/')); }