Example #1
0
 protected function setUp()
 {
     $this->v1 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('1.2.3'));
     $this->v1p = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('2.0.0-alpha.2'));
     $this->v2 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('4.5.6'));
     $this->manifest = new Manifest(array($this->v1, $this->v1p, $this->v2));
 }
Example #2
0
 /**
  * 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)
 {
     if (false === $version instanceof Version) {
         $version = Version::create($version);
     }
     if (null !== ($update = $this->manifest->findRecent($version, $major, $pre))) {
         $update->getFile();
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
 /**
  * Updates the running Phar if any is available and checks
  * the fingerprint of the public key.
  *
  * @param string|Version $version The current version.
  * @param bool           $major   Lock to current major version?
  * @param bool           $pre     Allow pre-releases?
  *
  * @return bool TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false)
 {
     if (false === $version instanceof Version) {
         $version = Version::create($version);
     }
     if (null !== ($update = $this->getManifest()->findRecent($version, $major, $pre))) {
         $tmpfile = $update->getFile();
         if (null !== $this->getPublicKeyHash()) {
             if (false === is_file($tmpfile . '.pubkey')) {
                 echo "ALERT: Update not signed with public key!\n";
                 $update->deleteFile();
                 return false;
             }
             if (hash_file('sha256', $tmpfile . '.pubkey') !== $this->getPublicKeyHash()) {
                 echo "ALERT: Public key fingerprint mismatch!!!\n";
                 $update->deleteFile();
                 return false;
             }
         }
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * Checks if this update is newer than the version given.
  *
  * @param Version $version The current version.
  *
  * @return boolean TRUE if the update is newer, FALSE if not.
  */
 public function isNewer(Version $version)
 {
     return $this->version->isGreaterThan($version);
 }
Example #5
0
 /**
  * @depends testDefaults
  */
 public function testSetPatch()
 {
     $version = new Version();
     $version->setPatch(1);
     $this->assertSame(1, $version->getPatch());
 }
Example #6
0
 public function testUpdateNone()
 {
     $manager = new Manager(new Manifest(array(new Update('new.phar', 'test', 'test', Version::create('2.0.1')))));
     $manager->setRunningFile($this->createFile());
     $this->assertFalse($manager->update('1.0.0', true));
 }
Example #7
0
 protected function setUp()
 {
     $this->update = new Update('test.phar', '1234567890123456789012345678901234567890', 'http://example.com/test.phar', $this->version = Version::create('1.2.3'), 'http://example.com/test-1.2.3.phar.pubkey');
 }
Example #8
0
 /**
  * Compares one version to another.
  *
  * @param Version $version Another version.
  *
  * @return -1 If this one is greater, 0 if equal, or 1 if $version is greater.
  *
  * @api
  */
 public function compareTo($version)
 {
     $major = $version->getMajor();
     $minor = $version->getMinor();
     $patch = $version->getPatch();
     $pre = $version->getPreRelease();
     $build = $version->getBuild();
     switch (true) {
         case $this->major < $major:
             return 1;
         case $this->major > $major:
             return -1;
         case $this->minor > $minor:
             return -1;
         case $this->minor < $minor:
             return 1;
         case $this->patch > $patch:
             return -1;
         case $this->patch < $patch:
             return 1;
             // @codeCoverageIgnoreStart
     }
     // @codeCoverageIgnoreEnd
     if ($pre || $this->pre) {
         if (empty($this->pre) && $pre) {
             return -1;
         }
         if ($this->pre && empty($pre)) {
             return 1;
         }
         if (0 !== ($weight = $this->precedence($this->pre, $pre))) {
             return $weight;
         }
     }
     if ($build || $this->build) {
         if (null === $this->build && $build) {
             return 1;
         }
         if ($this->build && null === $build) {
             return -1;
         }
         return $this->precedence($this->build, $build);
     }
     return 0;
 }
Example #9
0
 /**
  * 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, Version::create($update->version), isset($update->publicKey) ? $update->publicKey : null);
     }
     usort($updates, function (Update $a, Update $b) {
         return $a->getVersion()->compareTo($b->getVersion());
     });
     return new static($updates);
 }