check('The "apc.enable_cli" setting is off.', 'Notice: The "apc.enable_cli" is on and may cause problems with Phars.', function () { return false == ini_get('apc.enable_cli'); }, false); } echo "{$n}Everything seems good!{$n}{$n}"; echo "Download{$n}"; echo "--------{$n}{$n}"; // Retrieve manifest echo " - Downloading manifest...{$n}"; $manifest = file_get_contents('http://box-project.github.io/box2/manifest.json'); echo " - Reading manifest...{$n}"; $manifest = json_decode($manifest); $current = null; foreach ($manifest as $item) { $item->version = Parser::toVersion($item->version); if ($current && Comparator::isGreaterThan($item->version, $current->version)) { $current = $item; } } if (!$item) { echo " x No application download was found.{$n}"; } echo " - Downloading Box v", Dumper::toString($item->version), "...{$n}"; file_put_contents($item->name, file_get_contents($item->url)); echo " - Checking file checksum...{$n}"; if ($item->sha1 !== sha1_file($item->name)) { unlink($item->name); echo " x The download was corrupted.{$n}"; } echo " - Checking if valid Phar...{$n}"; try {
/** * Updates the running Phar if any is available. * * @param string|Version $version The current version. * @param boolean $major Lock to current major version? * @param boolean $pre Allow pre-releases? * * @return boolean TRUE if an update was performed, FALSE if none available. */ public function update($version, $major = false, $pre = false, $newVersion = null) { if (false === $version instanceof Version) { $version = Parser::toVersion($version); } if ($newVersion !== null && false === $newVersion instanceof Version) { $newVersion = Parser::toVersion($newVersion); } if ($newVersion) { if (Comparator::isEqualTo($version, $newVersion)) { $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version)); } $update = $this->manifest->find($newVersion); if (null === $update) { $this->logger->error(sprintf('No update found for version "%s".', (string) $newVersion)); return false; } } else { $update = $this->manifest->findRecent($version, $major, $pre); } if (null === $update) { $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version)); return false; } if ($update instanceof Update) { if (!$this->downloadFile($update)) { return false; } } return true; }
$response->setPublic(); // Handling the manifest data if ($file->isReadable()) { // If there were no new releases, then just return with the last on $response->setLastModified(new DateTime('@' . $file->getMTime())); if ($response->isNotModified($request)) { return $response; } $manifestData = json_decode(file_get_contents($file->getPathname()), true); // Sorting the versions in descending order $builder = new \Herrera\Version\Builder(); uasort($manifestData, function ($a, $b) use($builder) { if ($a['version'] === $b['version']) { return 0; } return \Herrera\Version\Comparator::isLessThan($builder->importString($a['version'])->getVersion(), $builder->importString($b['version'])->getVersion()); }); // Adding the "highlighted" bool value to every version. // Only the latest stable release is highlighted in every major version. $prevMajorVersion = null; foreach ($manifestData as $key => $data) { $manifestData[$key]['highlighted'] = false; $version = $builder->importString($data['version'])->getVersion(); if ($version->getMajor() !== $prevMajorVersion && $version->isStable()) { $manifestData[$key]['highlighted'] = true; $prevMajorVersion = $version->getMajor(); } } } // Rendering the template, setting up the response $response->headers->set('Content-Type', 'text/html');
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); } $templateParams = []; if ($page === 'index') { $manifestFile = new SplFileInfo($app['releases.path'] . '/manifest.json'); // Getting the latest stable release $manifestData = json_decode(file_get_contents($manifestFile->getPathname()), true); $stable = ''; $latest = new \Herrera\Version\Version(); $builder = new \Herrera\Version\Builder(); foreach ($manifestData as $versionData) { $version = $builder->importString($versionData['version'])->getVersion(); if ($stable === '' && !$version->isStable()) { continue; } if (\Herrera\Version\Comparator::isLessThan($latest, $version)) { $latest = $version; } } $templateParams['latest_deployer_version'] = $latest; $templateLastModified = new DateTime('@' . $templateFile->getMTime()); $manifestLastModified = new DateTime('@' . $manifestFile->getMTime()); $response->setLastModified($templateLastModified > $manifestLastModified ? $templateLastModified : $manifestLastModified); if ($response->isNotModified($request)) { return $response; } } else { $response->setLastModified(new DateTime('@' . $templateFile->getMTime())); if ($response->isNotModified($request)) { return $response; }
/** * @dataProvider getLess */ public function testIsLessThan($left, $right) { $this->assertTrue(Comparator::isLessThan(Builder::create()->importString($left), Builder::create()->importString($right))); }
/** * Returns 0 if both are equal, -1 if current version is earlier, 1 if its later * * @param Version $version * * @return int */ public function compare(Version $version) { return Comparator::compareTo($this, $version); }
/** * Validates the data, processes it, and returns a new instance of Manifest. * * @param array $decoded The decoded JSON data. * @param Json $json The Json instance used to decode the data. * * @return Manifest The new instance. */ private static function create($decoded, Json $json) { $json->validate($json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA), $decoded); $updates = array(); foreach ($decoded as $update) { $updates[] = new Update($update->name, $update->sha1, $update->url, Parser::toVersion($update->version), isset($update->publicKey) ? $update->publicKey : null); } usort($updates, function (Update $a, Update $b) { return Comparator::isGreaterThan($a->getVersion(), $b->getVersion()); }); return new static($updates); }