Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Checking that symfony installer is up-to-date #221

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Symfony/Installer/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* This file is part of the Symfony Installer package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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(
" <comment>[WARNING]</comment> 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;
}

}
2 changes: 1 addition & 1 deletion src/Symfony/Installer/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down
2 changes: 1 addition & 1 deletion symfony
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down