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

Commit 5350ab8

Browse files
committed
Remove herrera-io vendor dependency
1 parent df26700 commit 5350ab8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4274
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7.0
6+
- 7.1
77

88
before_script:
99
- composer self-update

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Phar Update
33

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

6-
Integrates [Phar Update](https://github.com/herrera-io/php-phar-update) to [Symfony Console](https://github.com/symfony/Console).
7-
86
Summary
97
-------
108

@@ -33,7 +31,7 @@ use Deployer\Component\PharUpdate\Console\Helper;
3331
use Symfony\Component\Console\Application;
3432

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

3836
$app = new Application();
3937
$app->getHelperSet()->set(new Helper());

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
],
2323
"autoload": {
2424
"psr-4": {
25-
"Deployer\\Component\\PharUpdate\\": "src/"
25+
"Deployer\\Component\\PharUpdate\\": "src/",
26+
"Deployer\\Component\\PHPUnit\\": "src/PHPUnit/",
27+
"Deployer\\Component\\Version\\": "src/Version/"
2628
}
2729
},
2830
"require": {
2931
"php": ">=5.3.3",
30-
"herrera-io/phar-update": "~2.0",
3132
"symfony/console": "^2.1|^3.0"
3233
},
3334
"require-dev": {
34-
"herrera-io/box": "~1.0",
35-
"herrera-io/phpunit-test-case": "1.*",
35+
"symfony/process": "~2.1",
36+
"mikey179/vfsStream": "1.1.0",
3637
"phpunit/phpunit": "3.7.*"
3738
}
3839
}

src/Console/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
namespace Deployer\Component\PharUpdate\Console;
33

4-
use Herrera\Phar\Update\Manifest;
5-
use Herrera\Phar\Update\Manager;
4+
use Deployer\Component\PharUpdate\Manifest;
5+
use Deployer\Component\PharUpdate\Manager;
66
use Symfony\Component\Console\Helper\Helper as Base;
77

88
/**

src/Exception/Exception.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate\Exception;
4+
5+
/**
6+
* Provides additional functional to the Exception class.
7+
*
8+
* @author Kevin Herrera <kevin@herrera.io>
9+
*/
10+
class Exception extends \Exception implements ExceptionInterface
11+
{
12+
/**
13+
* Creates a new exception using a format and values.
14+
*
15+
* @param string $format The format.
16+
* @param mixed $value,... The value(s).
17+
*
18+
* @return Exception The exception.
19+
*/
20+
public static function create($format, $value = null)
21+
{
22+
if (0 < func_num_args()) {
23+
$format = vsprintf($format, array_slice(func_get_args(), 1));
24+
}
25+
26+
return new static($format);
27+
}
28+
29+
/**
30+
* Creates an exception for the last error message.
31+
*
32+
* @return Exception The exception.
33+
*/
34+
public static function lastError()
35+
{
36+
$error = error_get_last();
37+
38+
return new static($error['message']);
39+
}
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate\Exception;
4+
5+
/**
6+
* Indicates that the exception came from this library.
7+
*
8+
* @author Kevin Herrera <kevin@herrera.io>
9+
*/
10+
interface ExceptionInterface
11+
{
12+
}

src/Exception/FileException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate\Exception;
4+
5+
/**
6+
* Used for errors when using the file system.
7+
*
8+
* @author Kevin Herrera <kevin@herrera.io>
9+
*/
10+
class FileException extends Exception
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate\Exception;
4+
5+
/**
6+
* Used if an invalid argument is given.
7+
*
8+
* @author Kevin Herrera <kevin@herrera.io>
9+
*/
10+
class InvalidArgumentException extends Exception
11+
{
12+
}

src/Exception/LogicException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate\Exception;
4+
5+
/**
6+
* Used if developer did something stupid (or overlooked something).
7+
*
8+
* @author Kevin Herrera <kevin@herrera.io>
9+
*/
10+
class LogicException extends Exception
11+
{
12+
}

src/Manager.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
namespace Deployer\Component\PharUpdate;
4+
5+
use Deployer\Component\PharUpdate\Exception\InvalidArgumentException;
6+
use Deployer\Component\Version\Parser;
7+
use Deployer\Component\Version\Version;
8+
9+
/**
10+
* Manages the Phar update process.
11+
*
12+
* @author Kevin Herrera <kevin@herrera.io>
13+
*/
14+
class Manager
15+
{
16+
/**
17+
* The update manifest.
18+
*
19+
* @var Manifest
20+
*/
21+
private $manifest;
22+
23+
/**
24+
* The running file (the Phar that will be updated).
25+
*
26+
* @var string
27+
*/
28+
private $runningFile;
29+
30+
/**
31+
* Sets the update manifest.
32+
*
33+
* @param Manifest $manifest The manifest.
34+
*/
35+
public function __construct(Manifest $manifest)
36+
{
37+
$this->manifest = $manifest;
38+
}
39+
40+
/**
41+
* Returns the manifest.
42+
*
43+
* @return Manifest The manifest.
44+
*/
45+
public function getManifest()
46+
{
47+
return $this->manifest;
48+
}
49+
50+
/**
51+
* Returns the running file (the Phar that will be updated).
52+
*
53+
* @return string The file.
54+
*/
55+
public function getRunningFile()
56+
{
57+
if (null === $this->runningFile) {
58+
$this->runningFile = realpath($_SERVER['argv'][0]);
59+
}
60+
61+
return $this->runningFile;
62+
}
63+
64+
/**
65+
* Sets the running file (the Phar that will be updated).
66+
*
67+
* @param string $file The file name or path.
68+
*
69+
* @throws Exception\Exception
70+
* @throws InvalidArgumentException If the file path is invalid.
71+
*/
72+
public function setRunningFile($file)
73+
{
74+
if (false === is_file($file)) {
75+
throw InvalidArgumentException::create(
76+
'The file "%s" is not a file or it does not exist.',
77+
$file
78+
);
79+
}
80+
81+
$this->runningFile = $file;
82+
}
83+
84+
/**
85+
* Updates the running Phar if any is available.
86+
*
87+
* @param string|Version $version The current version.
88+
* @param boolean $major Lock to current major version?
89+
* @param boolean $pre Allow pre-releases?
90+
*
91+
* @return boolean TRUE if an update was performed, FALSE if none available.
92+
*/
93+
public function update($version, $major = false, $pre = false)
94+
{
95+
if (false === ($version instanceof Version)) {
96+
$version = Parser::toVersion($version);
97+
}
98+
99+
if (null !== ($update = $this->manifest->findRecent(
100+
$version,
101+
$major,
102+
$pre
103+
))) {
104+
$update->getFile();
105+
$update->copyTo($this->getRunningFile());
106+
107+
return true;
108+
}
109+
110+
return false;
111+
}
112+
}

0 commit comments

Comments
 (0)