This repository has been archived by the owner on Apr 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
4,274 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
|
||
before_script: | ||
- composer self-update | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate\Exception; | ||
|
||
/** | ||
* Provides additional functional to the Exception class. | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
class Exception extends \Exception implements ExceptionInterface | ||
{ | ||
/** | ||
* Creates a new exception using a format and values. | ||
* | ||
* @param string $format The format. | ||
* @param mixed $value,... The value(s). | ||
* | ||
* @return Exception The exception. | ||
*/ | ||
public static function create($format, $value = null) | ||
{ | ||
if (0 < func_num_args()) { | ||
$format = vsprintf($format, array_slice(func_get_args(), 1)); | ||
} | ||
|
||
return new static($format); | ||
} | ||
|
||
/** | ||
* Creates an exception for the last error message. | ||
* | ||
* @return Exception The exception. | ||
*/ | ||
public static function lastError() | ||
{ | ||
$error = error_get_last(); | ||
|
||
return new static($error['message']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate\Exception; | ||
|
||
/** | ||
* Indicates that the exception came from this library. | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
interface ExceptionInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate\Exception; | ||
|
||
/** | ||
* Used for errors when using the file system. | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
class FileException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate\Exception; | ||
|
||
/** | ||
* Used if an invalid argument is given. | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
class InvalidArgumentException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate\Exception; | ||
|
||
/** | ||
* Used if developer did something stupid (or overlooked something). | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
class LogicException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Deployer\Component\PharUpdate; | ||
|
||
use Deployer\Component\PharUpdate\Exception\InvalidArgumentException; | ||
use Deployer\Component\Version\Parser; | ||
use Deployer\Component\Version\Version; | ||
|
||
/** | ||
* Manages the Phar update process. | ||
* | ||
* @author Kevin Herrera <[email protected]> | ||
*/ | ||
class Manager | ||
{ | ||
/** | ||
* The update manifest. | ||
* | ||
* @var Manifest | ||
*/ | ||
private $manifest; | ||
|
||
/** | ||
* The running file (the Phar that will be updated). | ||
* | ||
* @var string | ||
*/ | ||
private $runningFile; | ||
|
||
/** | ||
* Sets the update manifest. | ||
* | ||
* @param Manifest $manifest The manifest. | ||
*/ | ||
public function __construct(Manifest $manifest) | ||
{ | ||
$this->manifest = $manifest; | ||
} | ||
|
||
/** | ||
* Returns the manifest. | ||
* | ||
* @return Manifest The manifest. | ||
*/ | ||
public function getManifest() | ||
{ | ||
return $this->manifest; | ||
} | ||
|
||
/** | ||
* Returns the running file (the Phar that will be updated). | ||
* | ||
* @return string The file. | ||
*/ | ||
public function getRunningFile() | ||
{ | ||
if (null === $this->runningFile) { | ||
$this->runningFile = realpath($_SERVER['argv'][0]); | ||
} | ||
|
||
return $this->runningFile; | ||
} | ||
|
||
/** | ||
* Sets the running file (the Phar that will be updated). | ||
* | ||
* @param string $file The file name or path. | ||
* | ||
* @throws Exception\Exception | ||
* @throws InvalidArgumentException If the file path is invalid. | ||
*/ | ||
public function setRunningFile($file) | ||
{ | ||
if (false === is_file($file)) { | ||
throw InvalidArgumentException::create( | ||
'The file "%s" is not a file or it does not exist.', | ||
$file | ||
); | ||
} | ||
|
||
$this->runningFile = $file; | ||
} | ||
|
||
/** | ||
* 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 = Parser::toVersion($version); | ||
} | ||
|
||
if (null !== ($update = $this->manifest->findRecent( | ||
$version, | ||
$major, | ||
$pre | ||
))) { | ||
$update->getFile(); | ||
$update->copyTo($this->getRunningFile()); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.