Inheritance: extends Nette\Object
Ejemplo n.º 1
0
 /**
  * Returns the latest version.
  *
  * @param AddonVersion[] reverse sorted versions
  * @param bool
  * @return AddonVersion|FALSE
  */
 public function getCurrent($versions, $preferStable = TRUE)
 {
     if (count($versions) === 0) {
         return FALSE;
     }
     if ($preferStable) {
         $stable = $this->parser->filterStable($versions);
         if ($stable) {
             $versions = $stable;
         }
     }
     krsort($versions);
     return reset($versions);
 }
Ejemplo n.º 2
0
 public function isVersionValid($versionString)
 {
     return (bool) $this->versionParser->parseTag($versionString);
 }
 /**
  * Returns list of version in repository.
  *
  * @return array (version => hash)
  */
 private function getVersions()
 {
     $versions = array();
     $tags = $this->repository->getTags();
     $branches = $this->repository->getBranches();
     $util = new Utils\VersionParser();
     // TODO: use dependency injection
     foreach ($tags as $tag => $hash) {
         $version = $util->parseTag($tag);
         if (!$version) {
             continue;
         }
         $versions[$version] = $tag;
     }
     foreach ($branches as $branch => $hash) {
         $version = $util->parseBranch($branch);
         $versions[$version] = $branch;
     }
     return $versions;
 }
 /**
  * Creates new addon version from values and adds it to addon.
  *
  * @param \NetteAddons\Model\Addon
  * @param array
  * @param \Nette\Security\IIdentity
  * @param \NetteAddons\Model\Utils\VersionParser
  * @return \NetteAddons\Model\AddonVersion
  * @throws \NetteAddons\InvalidArgumentException
  * @throws \NetteAddons\IOException
  */
 public function addVersionFromValues(Addon $addon, $values, IIdentity $owner, VersionParser $versionParser)
 {
     if (!$values->license) {
         throw new \NetteAddons\InvalidArgumentException("License is mandatory.");
     }
     if (!$values->version) {
         throw new \NetteAddons\InvalidArgumentException("Version is mandatory.");
     }
     $version = new AddonVersion();
     $version->addon = $addon;
     $version->version = $versionParser->parseTag($values->version);
     $version->license = is_array($values->license) ? implode(', ', $values->license) : $values->license;
     $version->distType = 'zip';
     $version->distUrl = $values->archiveLink;
     $version->composerJson = Composer::createComposerJson($version);
     $version->composerJson->authors = array((object) array('name' => $owner->realname, 'email' => $owner->email));
     $addon->versions[] = $version;
     return $version;
 }