Exemple #1
0
 protected function prepare()
 {
     if (Type::determinePickle($this->path, $matches) < 1) {
         throw new \Exception('Not a pickle git URI');
     }
     $this->name = $matches['package'];
     $extension = $this->fetchPackageJson();
     $versionParser = new VersionParser();
     if ($matches['version'] == '') {
         $versions = array_keys($extension['packages'][$this->name]);
         if (count($versions) > 1) {
             $versionToUse = $versions[1];
         } else {
             $versionToUse = $versions[0];
         }
     } else {
         $versionConstraints = $versionParser->parseConstraints($matches['version']);
         /* versions are sorted decreasing */
         foreach ($extension['packages'][$this->name] as $version => $release) {
             $constraint = new VersionConstraint('=', $versionParser->normalize($version));
             if ($versionConstraints->matches($constraint)) {
                 $versionToUse = $version;
                 break;
             }
         }
     }
     $package = $extension['packages'][$this->name][$versionToUse];
     $this->version = $versionToUse;
     $this->normalizedVersion = $versionParser->normalize($versionToUse);
     $this->name = $matches['package'];
     $this->prettyVersion = $this->version;
     $this->url = $package['source']['url'];
     $this->reference = $package['source']['reference'];
     $this->type = $package['source']['type'];
 }