Skip to content

Commit

Permalink
Allow SymfonyHttpClient config in file (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine authored May 11, 2021
1 parent 816b5a2 commit 9f44d97
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ fastcgi: /var/run/php5-fpm.sock
temp_dir: /dev/shm/cachetool
```
Example for the web adapter:
```yml
adapter: web
webClient: SymfonyHttpClient # defaults to FileGetContents
webUrl: http://example.com
webPath: /var/www/example.com/current/web
webBasicAuth: user:password
```
You can define the supported extensions in the config file. By default, `apcu`,
and `opcache` are enabled. To disable `apcu`, add this to your config file:
Expand Down
23 changes: 13 additions & 10 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,27 @@ private function parseConfiguration(InputInterface $input)
}
} elseif ($input->hasParameterOption('--web')) {
$this->config['adapter'] = 'web';
$this->config['webClient'] = $input->hasParameterOption('--web') ?? 'FileGetContents';
$this->config['webPath'] = $input->getParameterOption('--web-path');
$this->config['webUrl'] = $input->getParameterOption('--web-url');
if($this->config['webClient'] === 'SymfonyHttpClient') {
if ($input->hasParameterOption('--web-allow-insecure')) {
$this->config['webAllowInsecure'] = true;
}

if ($input->hasParameterOption('--web-basic-auth')) {
$this->config['webBasicAuth'] = $input->getParameterOption('--web-basic-auth');
}
}
}

switch ($input->getParameterOption('--web') ?? 'FileGetContents') {
if ($this->config['adapter'] === 'web') {
switch ($this->config['webClient']) {
case 'FileGetContents':
$this->config['http'] = new FileGetContents($this->config['webUrl']);
break;

case 'SymfonyHttpClient':
if ($input->hasParameterOption('--web-allow-insecure')) {
$this->config['webAllowInsecure'] = true;
}

if ($input->hasParameterOption('--web-basic-auth')) {
$this->config['webBasicAuth'] = $input->getParameterOption('--web-basic-auth');
}

$symfonyHttpClientConfig = [];

Expand All @@ -228,8 +233,6 @@ private function parseConfiguration(InputInterface $input)
break;

default:
var_dump($this->config);
var_dump($input->getParameterOption('--web', "LOL"));
throw new \RuntimeException("{$this->config["web"]} is not a valid adapter. Possible adapters: FileGetContents or SymfonyHttpClient");
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ public function testWithCustomConfigFile()
$this->assertSame(42, $code);
}

public function testWebSymfonyHttpClientCustomConfigFile()
{
$temp = tempnam(sys_get_temp_dir(), "cfg");
file_put_contents($temp, '
adapter: web
webClient: SymfonyHttpClient
webUrl: http://example.com
webPath: /var/www/example.com/current/web
webBasicAuth: user:password
');

$app = new Application(new Config());
$app->add(new DummyCommand);
$app->setAutoExit(false);

$output = new BufferedOutput();
$code = $app->run(new StringInput("dummy --config=$temp"), $output);

$this->assertSame(42, $code);
}

public function testNoSupportedExtensions()
{
$app = new Application(new Config(['extensions' => []]));
Expand Down

0 comments on commit 9f44d97

Please sign in to comment.