Skip to content

Commit c349d8b

Browse files
author
Mike van den Hoek
committed
(refactor): pass apiType param to endpoint constructor instead of defining per endpoint class
1 parent e926061 commit c349d8b

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/Contracts/AbstractClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use InvalidArgumentException;
88
use OWC\Zaaksysteem\Endpoints\Endpoint;
9+
use function OWC\Zaaksysteem\Foundation\Helpers\resolve;
910
use OWC\Zaaksysteem\Http\Errors\ResourceNotFoundError;
1011
use OWC\Zaaksysteem\Http\Errors\ServerError;
11-
use OWC\Zaaksysteem\Http\RequestClientInterface;
1212

13-
use function OWC\Zaaksysteem\Foundation\Helpers\resolve;
13+
use OWC\Zaaksysteem\Http\RequestClientInterface;
1414
use function Yard\DigiD\Foundation\Helpers\config;
1515

1616
abstract class AbstractClient implements Client
@@ -92,7 +92,7 @@ protected function fetchFromContainer(string $key): Endpoint
9292

9393
$this->setClientSecretByType($type);
9494

95-
$endpoint = new $class($this, $this->getEndpointUrlByType($type));
95+
$endpoint = new $class($this, $this->getEndpointUrlByType($type), $type);
9696
$this->container[$key] = $endpoint;
9797
}
9898

src/Endpoints/Endpoint.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ abstract class Endpoint
2222

2323
protected Client $client;
2424
protected string $endpointURL = '';
25+
protected string $apiType = '';
2526
protected RequestClientInterface $httpClient;
2627
protected TokenAuthenticator $authenticator;
2728
protected Stack $responseHandlers;
2829

2930
protected string $entityClass = Entity::class;
3031

31-
public function __construct(Client $client, string $endpointURL)
32+
public function __construct(Client $client, string $endpointURL, string $apiType)
3233
{
3334
$this->client = $client;
3435
$this->endpointURL = $endpointURL;
36+
$this->apiType = $apiType;
3537
$this->httpClient = $client->getRequestClient();
3638
$this->authenticator = $client->getAuthenticator();
3739
$this->responseHandlers = Stack::create();
@@ -50,7 +52,7 @@ protected function buildRequestOptions(): RequestOptions
5052
{
5153
return new RequestOptions([
5254
'headers' => [
53-
'Authorization' => $this->apiType !== 'taken' ? $this->authenticator->getAuthString() : $this->authenticator->getApiKeyMijnTaken(),
55+
'Authorization' => 'taken' === $this->apiType ? $this->authenticator->getApiKeyMijnTaken() : $this->authenticator->getAuthString(),
5456
],
5557
]);
5658
}
@@ -72,7 +74,7 @@ protected function buildUriWithExpand(string $uri, ?Filter\AbstractFilter $filte
7274

7375
if ($this->endpointSupportsExpand() && $this->expandIsEnabled()) {
7476
$uri = add_query_arg([
75-
'expand' => implode(',', $this->getExpandableResources())
77+
'expand' => implode(',', $this->getExpandableResources()),
7678
], $uri);
7779
}
7880

src/Endpoints/TakenEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class TakenEndpoint extends Endpoint
1111
{
12-
protected string $apiType = 'taken';
12+
// protected string $apiType = 'taken';
1313
protected string $endpoint = 'taken';
1414
protected string $entityClass = Taak::class;
1515

src/Endpoints/ZakenEndpoint.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
namespace OWC\Zaaksysteem\Endpoints;
66

7-
use OWC\Zaaksysteem\Http\Response;
8-
use OWC\Zaaksysteem\Entities\Zaak;
97
use OWC\Zaaksysteem\Entities\Entity;
108
use OWC\Zaaksysteem\Entities\Status;
9+
use OWC\Zaaksysteem\Entities\Zaak;
10+
use OWC\Zaaksysteem\Http\Response;
11+
use OWC\Zaaksysteem\Resolvers\ContainerResolver;
1112
use OWC\Zaaksysteem\Support\Collection;
1213
use OWC\Zaaksysteem\Support\PagedCollection;
13-
use OWC\Zaaksysteem\Resolvers\ContainerResolver;
1414

1515
class ZakenEndpoint extends Endpoint
1616
{
17-
protected string $apiType = 'zaken';
1817
protected string $endpoint = 'zaken';
1918
protected string $entityClass = Zaak::class;
2019

0 commit comments

Comments
 (0)