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

Commit 5532128

Browse files
committed
feature #132 Added support for using proxy servers (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #132). Discussion ---------- Added support for using proxy servers I've tested it successfully with some free public proxy servers, but we should definitely test it with "real" proxy servers. Commits ------- f6ffc9b Added support for using proxy servers
2 parents 6362891 + f6ffc9b commit 5532128

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/Symfony/Installer/DownloadCommand.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class DownloadCommand extends Command
4242
/**
4343
* Returns the type of the downloaded application in a human readable format.
4444
* It's mainly used to display readable error messages.
45+
*
4546
* @return string
4647
*/
4748
abstract protected function getDownloadedApplicationType();
@@ -112,7 +113,7 @@ protected function download()
112113
$progressBar->setProgress($downloaded);
113114
};
114115

115-
$client = new Client();
116+
$client = $this->getGuzzleClient();
116117
$client->getEmitter()->attach(new Progress(null, $downloadCallback));
117118

118119
// store the file in a temporary hidden directory with a random name
@@ -149,6 +150,25 @@ protected function download()
149150
return $this;
150151
}
151152

153+
/**
154+
* Returns the Guzzle client configured according to the system environment
155+
* (e.g. it takes into account whether it should use a proxy server or not).
156+
*
157+
* @return Client
158+
*/
159+
protected function getGuzzleClient()
160+
{
161+
$options = array();
162+
163+
// check if the client must use a proxy server
164+
if (!empty($_SERVER['HTTP_PROXY']) || !empty($_SERVER['http_proxy'])) {
165+
$proxy = !empty($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY'];
166+
$options['proxy'] = $proxy;
167+
}
168+
169+
return new Client($options);
170+
}
171+
152172
/**
153173
* Extracts the compressed Symfony file (ZIP or TGZ) using the
154174
* native operating system commands if available or PHP code otherwise.
@@ -207,7 +227,7 @@ protected function extract()
207227
}
208228

209229
/**
210-
* Checks if environment meets symfony requirements
230+
* Checks if environment meets symfony requirements.
211231
*
212232
* @return Command
213233
*/
@@ -298,7 +318,7 @@ protected function getErrorMessage(\Requirement $requirement, $lineSize = 70)
298318
}
299319

300320
/**
301-
* Generates a good random value for Symfony's 'secret' option
321+
* Generates a good random value for Symfony's 'secret' option.
302322
*
303323
* @return string
304324
*/
@@ -340,7 +360,8 @@ protected function getExecutedCommand()
340360
/**
341361
* Checks whether the given directory is empty or not.
342362
*
343-
* @param string $dir the path of the directory to check
363+
* @param string $dir the path of the directory to check
364+
*
344365
* @return bool
345366
*/
346367
protected function isEmptyDirectory($dir)

src/Symfony/Installer/NewCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Installer;
1313

14-
use GuzzleHttp\Client;
1514
use Symfony\Component\Console\Input\InputArgument;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Output\OutputInterface;
@@ -130,7 +129,7 @@ protected function checkSymfonyVersionIsInstallable()
130129
if (preg_match('/^2\.\d$/', $this->version)) {
131130
// Check if we have a minor version in order to retrieve the last patch from symfony.com
132131

133-
$client = new Client();
132+
$client = $this->getGuzzleClient();
134133
$versionsList = $client->get('http://symfony.com/versions.json')->json();
135134

136135
if ($versionsList && isset($versionsList[$this->version])) {

0 commit comments

Comments
 (0)