Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Load Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.deps }}-composer
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## Unreleased
### BREAKING
- Add QueryArrayNormalizer middleware to ClientBuilder

## [v0.9.9] - 2024.06.06
### Added
- Add support to API key authorization
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"test": [
"php-cs-fixer fix --dry-run -v",
"php-cs-fixer fix -v",
"phpmd src text phpmd.xml.dist",
"phpspec run --format=dot"
]
Expand Down
2 changes: 2 additions & 0 deletions src/Client/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\HandlerStack;
use Omikron\FactFinder\Communication\Client\Middleware\Authenticator;
use Omikron\FactFinder\Communication\Client\Middleware\HttpErrors;
use Omikron\FactFinder\Communication\Client\Middleware\QueryArrayNormalizer;
use Omikron\FactFinder\Communication\Credentials;
use Omikron\FactFinder\Communication\ServerUrl;
use Omikron\FactFinder\Communication\Version;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function build(): ClientInterface
{
$handler = HandlerStack::create();
$handler->push(new HttpErrors());
$handler->push(new QueryArrayNormalizer());

$config = [
'base_uri' => $this->serverUrl,
Expand Down
47 changes: 47 additions & 0 deletions src/Client/Middleware/QueryArrayNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Omikron\FactFinder\Communication\Client\Middleware;

use Psr\Http\Message\RequestInterface;

class QueryArrayNormalizer
{
public function __invoke(callable $handler)
{
return function (RequestInterface $request, array $options) use ($handler) {

$uri = $request->getUri();
$query = $uri->getQuery();

if (!$query) {
return $handler($request, $options);
}

parse_str($query, $params);

$normalized = [];

foreach ($params as $key => $value) {
if (is_array($value)) {
foreach ($value as $v) {
$normalized[] = rawurlencode($key) . '=' . rawurlencode((string) $v);
}

continue;
}

$normalized[] = rawurlencode($key) . '=' . rawurlencode((string) $value);
}

$newQuery = implode('&', $normalized);

$request = $request->withUri(
$uri->withQuery($newQuery)
);

return $handler($request, $options);
};
}
}
Loading