Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 5ef4b77

Browse filesBrowse files
committed
Made all network connections proxy-compatible
1 parent c0bb1d0 commit 5ef4b77
Copy full SHA for 5ef4b77

File tree

Expand file treeCollapse file tree

5 files changed

+78
-68
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+78
-68
lines changed

‎src/Symfony/Installer/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Installer/Application.php
-33Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,6 @@ class Application extends ConsoleApplication
2626

2727
public function doRun(InputInterface $input, OutputInterface $output)
2828
{
29-
$commandName = $this->getCommandName($input);
30-
31-
if ($this->isInPharMode() && in_array($commandName, array('new', 'demo'), true)) {
32-
if (!$this->checkIfInstallerIsUpdated()) {
33-
$output->writeln(sprintf(
34-
" <comment>[WARNING]</comment> Your Symfony Installer version is outdated.\n".
35-
' Execute the command "%s selfupdate" to get the latest version.',
36-
$_SERVER['PHP_SELF']
37-
));
38-
}
39-
}
40-
4129
return parent::doRun($input, $output);
4230
}
43-
44-
public function isInPharMode()
45-
{
46-
return 'phar://' === substr(__DIR__, 0, 7);
47-
}
48-
49-
private function checkIfInstallerIsUpdated()
50-
{
51-
$localVersion = $this->getVersion();
52-
53-
if (false === $remoteVersion = @file_get_contents(self::VERSIONS_URL)) {
54-
// as this is simple checking - we don't care here if versions file is unavailable
55-
return true;
56-
}
57-
58-
if (version_compare($localVersion, $remoteVersion, '>=')) {
59-
return true;
60-
}
61-
62-
return false;
63-
}
6431
}

‎src/Symfony/Installer/DemoCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Installer/DemoCommand.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6060
{
6161
try {
6262
$this
63+
->checkInstallerVersion()
6364
->checkProjectName()
6465
->checkPermissions()
6566
->download()

‎src/Symfony/Installer/DownloadCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Installer/DownloadCommand.php
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,55 @@ protected function isSymfony3()
477477
return '3' === $this->version[0] || 'latest' === $this->version;
478478
}
479479

480+
/**
481+
* Checks if the installed version is the latest one and displays some
482+
* warning messages if not.
483+
*
484+
* @return $this
485+
*/
486+
protected function checkInstallerVersion()
487+
{
488+
// check update only if installer is running via a PHAR file
489+
if ('phar://' !== substr(__DIR__, 0, 7)) {
490+
return $this;
491+
}
492+
493+
if (!$this->isInstallerUpdated()) {
494+
$this->output->writeln(sprintf(
495+
"\n <bg=red> WARNING </> Your Symfony Installer version (%s) is outdated.\n".
496+
' Execute the command "%s selfupdate" to get the latest version (%s).',
497+
$installedVersion, $_SERVER['PHP_SELF'], $latestVersion
498+
));
499+
}
500+
501+
return $this;
502+
}
503+
504+
/**
505+
* @return boolean Whether the installed version is the latest one
506+
*/
507+
protected function isInstallerUpdated()
508+
{
509+
$installedVersion = $this->getApplication()->getVersion();
510+
$latestVersion = $this->getUrlContents(Application::VERSIONS_URL);
511+
512+
return version_compare($installedVersion, $latestVersion, '>=');
513+
}
514+
515+
/**
516+
* Returns the contents obtained by making a GET request to the given URL.
517+
*
518+
* @param string $url
519+
*
520+
* @return string
521+
*/
522+
protected function getUrlContents($url)
523+
{
524+
$client = $this->getGuzzleClient();
525+
526+
return $client->get($url)->getBody()->getContents();
527+
}
528+
480529
private function enableSignalHandler()
481530
{
482531
if (!function_exists('pcntl_signal')) {

‎src/Symfony/Installer/NewCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Installer/NewCommand.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4848
{
4949
try {
5050
$this
51+
->checkInstallerVersion()
5152
->checkProjectName()
5253
->checkSymfonyVersionIsInstallable()
5354
->checkPermissions()

‎src/Symfony/Installer/SelfUpdateCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Installer/SelfUpdateCommand.php
+27-35Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Installer;
1313

14-
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Input\InputInterface;
1615
use Symfony\Component\Console\Output\OutputInterface;
1716
use Symfony\Component\Filesystem\Filesystem;
@@ -27,16 +26,13 @@
2726
* @author Stephane PY <py.stephane1@gmail.com>
2827
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2928
*/
30-
class SelfUpdateCommand extends Command
29+
class SelfUpdateCommand extends DownloadCommand
3130
{
32-
/** @var Filesystem */
33-
private $fs;
34-
35-
/** @var OutputInterface */
36-
private $output;
37-
3831
private $tempDir;
3932

33+
/** @var string */
34+
private $latestInstallerVersion;
35+
4036
/** @var string the URL where the latest installer version can be downloaded */
4137
private $remoteInstallerFile;
4238

@@ -75,6 +71,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
7571
$this->fs = new Filesystem();
7672
$this->output = $output;
7773

74+
$this->latestInstallerVersion = $this->getUrlContents(Application::VERSIONS_URL);
7875
$this->remoteInstallerFile = 'http://symfony.com/installer';
7976
$this->currentInstallerFile = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
8077
$this->tempDir = sys_get_temp_dir();
@@ -85,8 +82,12 @@ protected function initialize(InputInterface $input, OutputInterface $output)
8582

8683
protected function execute(InputInterface $input, OutputInterface $output)
8784
{
88-
if ($this->installerIsUpdated()) {
85+
if ($this->isInstallerUpdated()) {
86+
$this->output->writeln(sprintf('// Symfony Installer is <info>already updated</info> to the latest version (%s).', $this->latestInstallerVersion));
87+
8988
return;
89+
} else {
90+
$this->output->writeln(sprintf('// <info>updating</info> Symfony Installer to <info>%s</info> version', $this->latestInstallerVersion));
9091
}
9192

9293
try {
@@ -98,44 +99,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
9899
->cleanUp()
99100
;
100101
} catch (IOException $e) {
102+
if ($this->output->isVeryVerbose()) {
103+
$this->output->writeln($e->getMessage());
104+
}
105+
101106
throw new \RuntimeException(sprintf(
102107
"The installer couldn't be updated, probably because of a permissions issue.\n".
103108
"Try to execute the command again with super user privileges:\n".
104109
" sudo %s\n",
105110
$this->getExecutedCommand()
106111
));
107-
108-
if ($output->isVeryVerbose()) {
109-
echo $e->getMessage();
110-
}
111112
} catch (\Exception $e) {
112113
$this->rollback();
113114

114-
if ($output->isVeryVerbose()) {
115-
echo $e->getMessage();
115+
if ($this->output->isVeryVerbose()) {
116+
$this->output->writeln($e->getMessage());
116117
}
117118
}
118119
}
119120

120-
private function installerIsUpdated()
121-
{
122-
$isUpdated = false;
123-
$localVersion = $this->getApplication()->getVersion();
124-
125-
if (false === $remoteVersion = @file_get_contents(Application::VERSIONS_URL)) {
126-
throw new \RuntimeException('The new version of the Symfony Installer couldn\'t be downloaded from the server.');
127-
}
128-
129-
if (version_compare($localVersion, $remoteVersion, '>=')) {
130-
$this->output->writeln('<info>Symfony Installer is already up to date.</info>');
131-
$isUpdated = true;
132-
} else {
133-
$this->output->writeln(sprintf('// <info>updating</info> Symfony Installer to <comment>%s</comment> version', $remoteVersion));
134-
}
135-
136-
return $isUpdated;
137-
}
138-
139121
private function downloadNewVersion()
140122
{
141123
// check for permissions in local filesystem before start downloading files
@@ -147,7 +129,7 @@ private function downloadNewVersion()
147129
throw new \RuntimeException('Symfony Installer update failed: the "'.$this->tempDir.'" directory used to download files temporarily could not be written');
148130
}
149131

150-
if (false === $newInstaller = @file_get_contents($this->remoteInstallerFile)) {
132+
if (false === $newInstaller = $this->getUrlContents($this->remoteInstallerFile)) {
151133
throw new \RuntimeException('The new version of the Symfony Installer couldn\'t be downloaded from the server.');
152134
}
153135

@@ -207,4 +189,14 @@ private function rollback()
207189
$this->fs->copy($this->currentInstallerBackupFile, $this->currentInstallerFile, true);
208190
}
209191
}
192+
193+
protected function getDownloadedApplicationType()
194+
{
195+
return 'Symfony Installer';
196+
}
197+
198+
protected function getRemoteFileUrl()
199+
{
200+
return 'http://symfony.com/installer';
201+
}
210202
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.