Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Remove herrera-io vendor dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 27, 2017
1 parent df26700 commit 5350ab8
Show file tree
Hide file tree
Showing 48 changed files with 4,274 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
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
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Phar Update

[![Build Status](https://travis-ci.org/deployphp/phar-update.svg?branch=master)](https://travis-ci.org/deployphp/phar-update)

Integrates [Phar Update](https://github.com/herrera-io/php-phar-update) to [Symfony Console](https://github.com/symfony/Console).

Summary
-------

Expand Down Expand Up @@ -33,7 +31,7 @@ use Deployer\Component\PharUpdate\Console\Helper;
use Symfony\Component\Console\Application;

$command = new Command('update');
$command->setManifestUri('http://deployer.org/manifest.json');
$command->setManifestUri('https://deployer.org/manifest.json');

$app = new Application();
$app->getHelperSet()->set(new Helper());
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
],
"autoload": {
"psr-4": {
"Deployer\\Component\\PharUpdate\\": "src/"
"Deployer\\Component\\PharUpdate\\": "src/",
"Deployer\\Component\\PHPUnit\\": "src/PHPUnit/",
"Deployer\\Component\\Version\\": "src/Version/"
}
},
"require": {
"php": ">=5.3.3",
"herrera-io/phar-update": "~2.0",
"symfony/console": "^2.1|^3.0"
},
"require-dev": {
"herrera-io/box": "~1.0",
"herrera-io/phpunit-test-case": "1.*",
"symfony/process": "~2.1",
"mikey179/vfsStream": "1.1.0",
"phpunit/phpunit": "3.7.*"
}
}
4 changes: 2 additions & 2 deletions src/Console/Helper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Deployer\Component\PharUpdate\Console;

use Herrera\Phar\Update\Manifest;
use Herrera\Phar\Update\Manager;
use Deployer\Component\PharUpdate\Manifest;
use Deployer\Component\PharUpdate\Manager;
use Symfony\Component\Console\Helper\Helper as Base;

/**
Expand Down
40 changes: 40 additions & 0 deletions src/Exception/Exception.php
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']);
}
}
12 changes: 12 additions & 0 deletions src/Exception/ExceptionInterface.php
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
{
}
12 changes: 12 additions & 0 deletions src/Exception/FileException.php
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
{
}
12 changes: 12 additions & 0 deletions src/Exception/InvalidArgumentException.php
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
{
}
12 changes: 12 additions & 0 deletions src/Exception/LogicException.php
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
{
}
112 changes: 112 additions & 0 deletions src/Manager.php
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;
}
}
Loading

0 comments on commit 5350ab8

Please sign in to comment.