diff --git a/src/Symfony/Installer/Application.php b/src/Symfony/Installer/Application.php new file mode 100644 index 0000000..24e2671 --- /dev/null +++ b/src/Symfony/Installer/Application.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Installer; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Application as ConsoleApplication; + +/** + * This is main Symfony Installer console application class. + */ +class Application extends ConsoleApplication +{ + const VERSIONS_URL = 'https://get.symfony.com/symfony.version'; + + public function doRun(InputInterface $input, OutputInterface $output) + { + $commandName = $this->getCommandName($input); + + if ($this->isInPharMode() && in_array($commandName, array('new', 'demo'), true)) { + if (!$this->checkIfInstallerIsUpdated()) { + $output->writeln( + sprintf( + " [WARNING] You are using outdated version of Symfony Installer.\n". + ' It is recommended to update it by running "%s selfupdate" to get the latest version.', + $_SERVER['PHP_SELF'] + ) + ); + } + + } + + return parent::doRun($input, $output); + } + + public function isInPharMode() + { + return 'phar://' === substr(__DIR__, 0, 7); + } + + private function checkIfInstallerIsUpdated() + { + $localVersion = $this->getVersion(); + + if (false === $remoteVersion = @file_get_contents(self::VERSIONS_URL)) { + // as this is simple checking - we don't care here if versions file is unavailable + return true; + } + + if (version_compare($localVersion, $remoteVersion, '>=')) { + return true; + } + + return false; + } + +} diff --git a/src/Symfony/Installer/SelfUpdateCommand.php b/src/Symfony/Installer/SelfUpdateCommand.php index 85b2f34..34325d6 100644 --- a/src/Symfony/Installer/SelfUpdateCommand.php +++ b/src/Symfony/Installer/SelfUpdateCommand.php @@ -122,7 +122,7 @@ private function installerIsUpdated() $isUpdated = false; $localVersion = $this->getApplication()->getVersion(); - if (false === $remoteVersion = @file_get_contents('http://get.symfony.com/symfony.version')) { + if (false === $remoteVersion = @file_get_contents(Application::VERSIONS_URL)) { throw new \RuntimeException('The new version of the Symfony Installer couldn\'t be downloaded from the server.'); } diff --git a/symfony b/symfony index 0eb3115..810f733 100755 --- a/symfony +++ b/symfony @@ -25,7 +25,7 @@ if (!isset($_SERVER['PATH']) && isset($_SERVER['Path'])) { $_SERVER['PATH'] = $_SERVER['Path']; } -$app = new Symfony\Component\Console\Application('Symfony Installer', $appVersion); +$app = new Symfony\Installer\Application('Symfony Installer', $appVersion); $app->add(new Symfony\Installer\AboutCommand($appVersion)); $app->add(new Symfony\Installer\NewCommand()); $app->add(new Symfony\Installer\DemoCommand());