Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Add support for dynamic arguments (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Oct 8, 2023
1 parent 37fbc3f commit 5846b60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/DI/AresExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\ServiceDefinition;
use Nette\DI\Definitions\Statement;
use Nette\PhpGenerator\Literal;
use Nette\Schema\Expect;
use stdClass;
use Trejjam\Ares;
Expand All @@ -25,7 +26,7 @@ public function getConfigSchema() : Nette\Schema\Schema
'http' => Expect::structure([
'clientFactory' => Expect::anyOf(Expect::string(), Expect::array(), Expect::type(Statement::class))->nullable(),
'caChain' => Expect::anyOf(Expect::string(), Expect::type(Statement::class))->nullable(),
'client' => Expect::array()->default([]),
'client' => Expect::array()->dynamic()->default([]),
]),
'mapper' => Expect::anyOf(Expect::string(), Expect::array(), Expect::type(Statement::class))->default(Mapper::class),
]);
Expand Down Expand Up @@ -64,7 +65,12 @@ public function beforeCompile() : void
$httpClient = $builder->addDefinition($this->prefix('http.client'))->setType(GuzzleHttp\Client::class);
}

if ($http->caChain !== null && !array_key_exists('verify', $http->client)) {
if ($http->client instanceof Literal) {
$http->client = new Literal(
"array_merge(['verify' => '{$http->caChain}'], {$http->client})"
);
}
elseif ($http->caChain !== null && !array_key_exists('verify', $http->client)) {
$http->client['verify'] = $http->caChain;
}

Expand Down

0 comments on commit 5846b60

Please sign in to comment.