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

Added support for using proxy servers #132

Closed
wants to merge 2 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
29 changes: 25 additions & 4 deletions src/Symfony/Installer/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class DownloadCommand extends Command
/**
* Returns the type of the downloaded application in a human readable format.
* It's mainly used to display readable error messages.
*
* @return string
*/
abstract protected function getDownloadedApplicationType();
Expand Down Expand Up @@ -112,7 +113,7 @@ protected function download()
$progressBar->setProgress($downloaded);
};

$client = new Client();
$client = $this->getGuzzleClient();
$client->getEmitter()->attach(new Progress(null, $downloadCallback));

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

/**
* Returns the Guzzle client configured according to the system environment
* (e.g. it takes into account whether it should use a proxy server or not).
*
* @return Client
*/
protected function getGuzzleClient()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to make this private?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't call private methods in subclasses :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't used in another class the time I wrote the comment. :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You both are right! Thanks for reviewing the code.

{
$options = array();

// check if the client must use a proxy server
if (!empty($_SERVER['HTTP_PROXY']) || !empty($_SERVER['http_proxy'])) {
$proxy = !empty($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY'];
$options['proxy'] = $proxy;
}

return new Client($options);
}

/**
* Extracts the compressed Symfony file (ZIP or TGZ) using the
* native operating system commands if available or PHP code otherwise.
Expand Down Expand Up @@ -207,7 +227,7 @@ protected function extract()
}

/**
* Checks if environment meets symfony requirements
* Checks if environment meets symfony requirements.
*
* @return Command
*/
Expand Down Expand Up @@ -298,7 +318,7 @@ protected function getErrorMessage(\Requirement $requirement, $lineSize = 70)
}

/**
* Generates a good random value for Symfony's 'secret' option
* Generates a good random value for Symfony's 'secret' option.
*
* @return string
*/
Expand Down Expand Up @@ -340,7 +360,8 @@ protected function getExecutedCommand()
/**
* Checks whether the given directory is empty or not.
*
* @param string $dir the path of the directory to check
* @param string $dir the path of the directory to check
*
* @return bool
*/
protected function isEmptyDirectory($dir)
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Installer;

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

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

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