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

Commit 71fe39f

Browse files
committed
feature #221 Checking that symfony installer is up-to-date (jzawadzki)
This PR was squashed before being merged into the 1.0-dev branch (closes #221). Discussion ---------- Checking that symfony installer is up-to-date Hi, regarding our discussion in #220 and #136 I'm sending first draft of checking if installer is up-to-date. I have based my solution of how and when composer is checking it. Please comment and tell if this solution is ok and what should I change to make it better! Thanks, JZ Commits ------- b5225d8 Checking that symfony installer is up-to-date
2 parents 496153c + b5225d8 commit 71fe39f

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

src/Symfony/Installer/Application.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony Installer package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Installer;
13+
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Application as ConsoleApplication;
17+
18+
/**
19+
* This is main Symfony Installer console application class.
20+
*/
21+
class Application extends ConsoleApplication
22+
{
23+
const VERSIONS_URL = 'https://get.symfony.com/symfony.version';
24+
25+
public function doRun(InputInterface $input, OutputInterface $output)
26+
{
27+
$commandName = $this->getCommandName($input);
28+
29+
if ($this->isInPharMode() && in_array($commandName, array('new', 'demo'), true)) {
30+
if (!$this->checkIfInstallerIsUpdated()) {
31+
$output->writeln(
32+
sprintf(
33+
" <comment>[WARNING]</comment> You are using outdated version of Symfony Installer.\n".
34+
' It is recommended to update it by running "%s selfupdate" to get the latest version.',
35+
$_SERVER['PHP_SELF']
36+
)
37+
);
38+
}
39+
40+
}
41+
42+
return parent::doRun($input, $output);
43+
}
44+
45+
public function isInPharMode()
46+
{
47+
return 'phar://' === substr(__DIR__, 0, 7);
48+
}
49+
50+
private function checkIfInstallerIsUpdated()
51+
{
52+
$localVersion = $this->getVersion();
53+
54+
if (false === $remoteVersion = @file_get_contents(self::VERSIONS_URL)) {
55+
// as this is simple checking - we don't care here if versions file is unavailable
56+
return true;
57+
}
58+
59+
if (version_compare($localVersion, $remoteVersion, '>=')) {
60+
return true;
61+
}
62+
63+
return false;
64+
}
65+
66+
}

src/Symfony/Installer/SelfUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private function installerIsUpdated()
122122
$isUpdated = false;
123123
$localVersion = $this->getApplication()->getVersion();
124124

125-
if (false === $remoteVersion = @file_get_contents('http://get.symfony.com/symfony.version')) {
125+
if (false === $remoteVersion = @file_get_contents(Application::VERSIONS_URL)) {
126126
throw new \RuntimeException('The new version of the Symfony Installer couldn\'t be downloaded from the server.');
127127
}
128128

symfony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!isset($_SERVER['PATH']) && isset($_SERVER['Path'])) {
2525
$_SERVER['PATH'] = $_SERVER['Path'];
2626
}
2727

28-
$app = new Symfony\Component\Console\Application('Symfony Installer', $appVersion);
28+
$app = new Symfony\Installer\Application('Symfony Installer', $appVersion);
2929
$app->add(new Symfony\Installer\AboutCommand($appVersion));
3030
$app->add(new Symfony\Installer\NewCommand());
3131
$app->add(new Symfony\Installer\DemoCommand());

0 commit comments

Comments
 (0)