Skip to content

Commit 0161236

Browse files
committed
Added support for self-updating the .phar file.
Uses the herrera-io/phar-update package to update the application based on semantic version.
1 parent 34171b1 commit 0161236

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

box.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compactors": ["Herrera\\Box\\Compactor\\Php"],
44
"compression": "GZ",
55
"directories": ["src"],
6-
"files": ["LICENSE"],
6+
"files": ["LICENSE", "vendor/herrera-io/phar-update/res/schema.json"],
77
"finder": [
88
{
99
"name": "*.php",

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
],
2828
"require": {
2929
"php": ">=5.4.0",
30-
"symfony/console": "2.7.*@dev",
30+
31+
"herrera-io/phar-update": "~2.0",
3132
"nikic/php-parser": "dev-features/php-semver-checker",
33+
"symfony/console": "2.7.*@dev",
3234
"phpunit/php-file-iterator": "~1.3"
3335
},
3436
"require-dev": {
35-
"phpunit/phpunit": "~4",
36-
"mockery/mockery": "~0.9"
37+
"mockery/mockery": "~0.9",
38+
"phpunit/phpunit": "~4"
3739
},
3840
"autoload": {
3941
"psr-4": {

src/PHPSemVerChecker/Console/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPSemVerChecker\Console;
44

55
use PHPSemVerChecker\Console\Command\CompareCommand;
6+
use PHPSemVerChecker\Console\Command\SelfUpdateCommand;
67
use Symfony\Component\Console\Application as SymfonyApplication;
78

89
class Application extends SymfonyApplication {
@@ -30,6 +31,7 @@ protected function getDefaultCommands()
3031
{
3132
$commands = parent::getDefaultCommands();
3233
$commands[] = $this->add(new CompareCommand());
34+
$commands[] = $this->add(new SelfUpdateCommand());
3335
return $commands;
3436
}
3537
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Console\Command;
4+
5+
use Herrera\Json\Exception\FileException;
6+
use Herrera\Phar\Update\Manager;
7+
use Herrera\Phar\Update\Manifest;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class SelfUpdateCommand extends Command {
13+
const MANIFEST_FILE = 'https://tomzx.github.io/php-semver-checker/manifest.json';
14+
15+
protected function configure()
16+
{
17+
$this
18+
->setName('self-update')
19+
->setDescription('Update php-semver-checker.phar to the latest version')
20+
;
21+
}
22+
23+
protected function execute(InputInterface $input, OutputInterface $output)
24+
{
25+
$manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
26+
$manager->update($this->getApplication()->getVersion());
27+
}
28+
}

0 commit comments

Comments
 (0)