Commit c8688256 authored by Igor Wiedler's avatar Igor Wiedler

[console] lightweight silex console

you can get the current version by calling the phar without arguments:

    $ php silex.phar
    Silex version 1ee6b36

there is only one single `update` command:

    $ php silex.phar update

this will fetch the latest version of the phar from silex-project.org
and replace the current one with it.

this makes it easier for users because they can easily update. we could
potentially even provide a changelog on running the command.

this commit also introduces a Silex\Application::VERSION constant that
currently is set to the current git SHA-1, as I proposed in PR 33. This
is done by the Compiler. It can later be adjusted to use `git describe`.

this is an implementation of PR 35 without the console component.
parent 74de1b18
......@@ -34,3 +34,6 @@
[submodule "vendor/monolog"]
path = vendor/monolog
url = https://github.com/Seldaek/monolog.git
[submodule "vendor/Symfony/Component/Process"]
path = vendor/Symfony/Component/Process
url = https://github.com/symfony/Process
......@@ -39,6 +39,8 @@ use Silex\RedirectableUrlMatcher;
*/
class Application extends \Pimple implements HttpKernelInterface, EventSubscriberInterface
{
const VERSION = '@package_version@';
/**
* Constructor.
*/
......
......@@ -13,6 +13,7 @@ namespace Silex;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Process\Process;
/**
* The Compiler class compiles the Silex framework.
......@@ -36,6 +37,7 @@ class Compiler
$finder->files()
->ignoreVCS(true)
->name('*.php')
->notName('Compiler.php')
->in(__DIR__.'/..')
->in(__DIR__.'/../../vendor/pimple')
->in(__DIR__.'/../../vendor/Symfony/Component/ClassLoader')
......@@ -56,8 +58,8 @@ class Compiler
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../autoload.php'));
// Stubs
$phar['_cli_stub.php'] = $this->getStub();
$phar['_web_stub.php'] = $this->getStub();
$phar['_cli_stub.php'] = $this->getCliStub();
$phar['_web_stub.php'] = $this->getWebStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
......@@ -75,10 +77,50 @@ class Compiler
$content = Kernel::stripComments($content);
}
$process = new Process('git rev-parse --short HEAD');
if ($process->run() > 0) {
throw new \RuntimeException('The git binary cannot be found.');
}
$content = str_replace('@package_version@', $process->getOutput(), $content);
$phar->addFromString($path, $content);
}
protected function getStub()
protected function getCliStub()
{
return <<<'EOF'
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
require_once __DIR__.'/autoload.php';
$command = isset($argv[1]) ? $argv[1] : null;
switch ($command) {
case 'update':
$remoteFilename = 'http://silex-project.org/get/silex.phar';
$localFilename = getcwd().'/silex.phar';
file_put_contents($localFilename, file_get_contents($remoteFilename));
break;
default:
echo "Silex version ".Silex\Application::VERSION."\n";
break;
}
__HALT_COMPILER();
EOF;
}
protected function getWebStub()
{
return <<<EOF
<?php
......
Subproject commit 9dce933d7b55f0a0df912621891955750acf102e
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment