PK [GM}o o .travis.ymlnu W+A language: php
php:
- 5.3
- 5.4
before_script:
- composer self-update
- composer install --devPK [GMZΜ README.mdnu W+A Amend
=====
[![Build Status](https://secure.travis-ci.org/kherge/Amend.png?branch=master)](http://travis-ci.org/kherge/Amend)
Integrates [Phar Update](https://github.com/herrera-io/php-phar-update) to [Symfony Console](https://github.com/symfony/Console).
Summary
-------
Uses the Phar Update library to:
1. check for newer versions of the Phar
1. download the Phar
- verify download by SHA1 checksum, and public key if available
1. replace running Phar with downloaded update
Installation
------------
Add it to your list of Composer dependencies:
```sh
$ composer require kherge/amend=3.*
```
Usage
-----
```php
setManifestUri('http://box-project.org/manifest.json');
$app = new Application();
$app->getHelperSet()->set(new Helper());
$app->add($command);
```PK [GM:a> >
.gitignorenu W+A /.idea/
/bin/
/coverage/
/src/vendors/
/*.iml
/composer.lock
PK [GMcl src/lib/KevinGH/Amend/Helper.phpnu W+A
*/
class Helper extends Base
{
/**
* The update manager.
*
* @var Manager
*/
private $manager;
/**
* Returns the update manager.
*
* @param string $uri The manifest file URI.
*
* @return Manager The update manager.
*/
public function getManager($uri)
{
return new Manager(Manifest::loadFile($uri));
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'amend';
}
}PK [GME|~bw
w
! src/lib/KevinGH/Amend/Command.phpnu W+A
*/
class Command extends Base
{
/**
* Disable the ability to upgrade?
*
* @var boolean
*/
private $disableUpgrade = false;
/**
* The manifest file URI.
*
* @var string
*/
private $manifestUri;
/**
* {@inheritDoc}
*
* @param string $name The command name.
* @param boolean $disable Disable upgrading?
*/
public function __construct($name, $disable = false)
{
$this->disableUpgrade = $disable;
parent::__construct($name);
}
/**
* Sets the manifest URI.
*
* @param string $uri The URI.
*/
public function setManifestUri($uri)
{
$this->manifestUri = $uri;
}
/**
* @override
*/
protected function configure()
{
$this->setDescription('Updates the application.');
$this->addOption(
'pre',
'p',
InputOption::VALUE_NONE,
'Allow pre-release updates.'
);
$this->addOption(
'redo',
'r',
InputOption::VALUE_NONE,
'Redownload update if already using current version.'
);
if (false === $this->disableUpgrade) {
$this->addOption(
'upgrade',
'u',
InputOption::VALUE_NONE,
'Upgrade to next major release, if available.'
);
}
}
/**
* @override
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->manifestUri) {
throw new LogicException(
'No manifest URI has been configured.'
);
}
$output->writeln('Looking for updates...');
/** @var $amend Helper */
$amend = $this->getHelper('amend');
$manager = $amend->getManager($this->manifestUri);
if ($manager->update(
$this->getApplication()->getVersion(),
$this->disableUpgrade ?: (false === $input->getOption('upgrade')),
$input->getOption('pre')
)){
$output->writeln('Update successful!');
} else {
$output->writeln('Already up-to-date.');
}
}
}PK [GMu,L L , src/tests/KevinGH/Amend/Tests/HelperTest.phpnu W+A createFile();
file_put_contents($file, '[]');
$this->assertInstanceOf(
'Herrera\\Phar\\Update\\Manager',
$this->helper->getManager($file)
);
}
public function testGetName()
{
$this->assertEquals('amend', $this->helper->getName());
}
protected function setUp()
{
$this->helper = new Helper();
}
}PK [GMvX - src/tests/KevinGH/Amend/Tests/CommandTest.phpnu W+A command->setManifestUri('http://example.com/test.json');
$this->assertEquals(
'http://example.com/test.json',
$this->getPropertyValue($this->command, 'manifestUri')
);
}
public function testConfigure()
{
$definition = $this->command->getDefinition();
$this->assertTrue($definition->hasOption('redo'));
$this->assertTrue($definition->hasOption('upgrade'));
}
public function testConfigureDisabled()
{
$command = new Command('upgrade', true);
$definition = $command->getDefinition();
$this->assertTrue($definition->hasOption('redo'));
$this->assertFalse($definition->hasOption('upgrade'));
}
public function testExecuteNoManifest()
{
$app = new Application('Test', '1.0.0');
$app->getHelperSet()->set(new Helper());
$app->add(new Command('upgrade'));
$tester = new CommandTester($app->get('upgrade'));
$this->setExpectedException(
'LogicException',
'No manifest URI has been configured.'
);
$tester->execute(array('command' => 'upgrade'));
}
public function testExecute()
{
$_SERVER['argv'][0] = $this->createPhar('a.phar', 'alpha');
$b = $this->createPhar('b.phar', 'beta');
$manifest = $this->createFile();
file_put_contents($manifest, json_encode(array(
array(
'name' => 'a.phar',
'sha1' => sha1_file($b),
'url' => $b,
'version' => '1.2.0'
),
array(
'name' => 'a.phar',
'sha1' => 'abcdef0123abcdef0123abcdef0123abcdef0123',
'url' => 'file:///does/not/exist',
'version' => '2.0.0'
)
)));
$command = new Command('upgrade', true);
$command->setManifestUri($manifest);
$app = new Application('Test', '1.0.0');
$app->getHelperSet()->set(new Helper());
$app->add($command);
$tester = new CommandTester($app->get('upgrade'));
$tester->execute(array('command' => 'upgrade'));
$this->assertRegExp(
'/Update successful!/',
$tester->getDisplay()
);
$this->assertEquals(
'beta',
exec('php ' . escapeshellarg($_SERVER['argv'][0]))
);
}
public function testExecuteCurrent()
{
$manifest = $this->createFile();
file_put_contents($manifest, '[]');
$command = new Command('upgrade', true);
$command->setManifestUri($manifest);
$app = new Application('Test', '1.0.0');
$app->getHelperSet()->set(new Helper());
$app->add($command);
$tester = new CommandTester($app->get('upgrade'));
$tester->execute(array('command' => 'upgrade'));
$this->assertRegExp(
'/Already up-to-date\./',
$tester->getDisplay()
);
}
protected function createPhar($name, $echo)
{
unlink($file = $this->createFile($name));
$box = Box::create($file);
$box->addFromString(
'index.php',
'command = new Command('upgrade');
}
}PK [GME^ ^ src/tests/load.phpnu W+A add(null, __DIR__);
PK [GMr2% phpunit.xml.distnu W+A
src/lib/
src/tests/
PK [GMţ! ! LICENSEnu W+A Copyright (c) 2013 Kevin Herrera
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.PK [GM8V> >
composer.jsonnu W+A {
"name": "kherge/amend",
"description": "Integrates Phar Update to Symfony Console.",
"keywords": ["phar", "update", "console"],
"homepage": "http://github.com/box-project/amend",
"license": "MIT",
"authors": [
{
"name": "Kevin Herrera",
"email": "kevin@herrera.io",
"homepage": "http://kevin.herrera.io"
}
],
"support": {
"issues": "https://github.com/box-project/amend/issues",
"source": "https://github.com/box-project/amend"
},
"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.*",
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"KevinGH\\Amend": "src/lib"
}
},
"config": {
"bin-dir": "bin",
"vendor-dir": "src/vendors"
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
}
}
PK [GM}o o .travis.ymlnu W+A PK [GMZΜ README.mdnu W+A PK [GM:a> >
.gitignorenu W+A PK [GMcl src/lib/KevinGH/Amend/Helper.phpnu W+A PK [GME|~bw
w
! ( src/lib/KevinGH/Amend/Command.phpnu W+A PK [GMu,L L , src/tests/KevinGH/Amend/Tests/HelperTest.phpnu W+A PK [GMvX - src/tests/KevinGH/Amend/Tests/CommandTest.phpnu W+A PK [GME^ ^ &