/** * @param Package $package * * @return RuleSet */ private function loadPackageRuleSet(Package $package) { $ruleSet = new RuleSet(); $key = $package->generatePackageKey(); if ($this->cache->has($key)) { $ruleSet = $this->cache->getCachedRuleSet($key); } elseif (is_dir($path = $package->getPackagePath(self::PACKAGE_PATH))) { $ruleSet = $this->traverser->traverse($path); $this->cache->cacheRuleSet($key, $ruleSet); } else { // there is no vendor package in the given path } return $ruleSet; }
/** * @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/')); }