/** * Returns composer.json or NULL if composer.json does not exist or is invalid. * * @param string commit hash, brach or tag name * @return stdClass|NULL * @throws \NetteAddons\IOException */ private function getComposerJson($hash) { try { $content = $this->repository->getFileContent($hash, Utils\Composer::FILENAME); $composer = Json::decode($content); if (!Utils\Composer::isValid($composer)) { return NULL; // invalid composer.json } return $composer; } catch (\NetteAddons\Utils\HttpException $e) { if ($e->getCode() === 404) { return NULL; } throw $e; } catch (\Nette\Utils\JsonException $e) { return NULL; } }
/** * 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; }