-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add type declarations to all endpoints
- Loading branch information
Showing
40 changed files
with
383 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Endpoints; | ||
|
||
use Mollie\Api\Contracts\SingleResourceEndpoint; | ||
use Mollie\Api\Exceptions\ApiException; | ||
use Mollie\Api\MollieApiClient; | ||
|
||
abstract class BaseEndpoint | ||
{ | ||
public const REST_CREATE = MollieApiClient::HTTP_POST; | ||
public const REST_UPDATE = MollieApiClient::HTTP_PATCH; | ||
public const REST_READ = MollieApiClient::HTTP_GET; | ||
public const REST_LIST = MollieApiClient::HTTP_GET; | ||
public const REST_DELETE = MollieApiClient::HTTP_DELETE; | ||
|
||
protected MollieApiClient $client; | ||
|
||
protected string $resourcePath; | ||
|
||
protected ?string $parentId; | ||
|
||
public function __construct(MollieApiClient $api) | ||
{ | ||
$this->client = $api; | ||
} | ||
|
||
/** | ||
* @param array $filters | ||
* @return string | ||
*/ | ||
protected function buildQueryString(array $filters): string | ||
{ | ||
if (empty($filters)) { | ||
return ""; | ||
} | ||
|
||
foreach ($filters as $key => $value) { | ||
if ($value === true) { | ||
$filters[$key] = "true"; | ||
} | ||
|
||
if ($value === false) { | ||
$filters[$key] = "false"; | ||
} | ||
} | ||
|
||
return "?" . http_build_query($filters, "", "&"); | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws ApiException | ||
*/ | ||
public function getResourcePath(): string | ||
{ | ||
if (strpos($this->resourcePath, "_") !== false) { | ||
[$parentResource, $childResource] = explode("_", $this->resourcePath, 2); | ||
|
||
if (empty($this->parentId)) { | ||
throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); | ||
} | ||
|
||
return "$parentResource/{$this->parentId}/$childResource"; | ||
} | ||
|
||
return $this->resourcePath; | ||
} | ||
|
||
protected function getPathToSingleResource(string $id): string | ||
{ | ||
if ($this instanceof SingleResourceEndpoint) { | ||
return $this->getResourcePath(); | ||
} | ||
|
||
return "{$this->getResourcePath()}/{$id}"; | ||
} | ||
|
||
/** | ||
* @param array $body | ||
* @return null|string | ||
*/ | ||
protected function parseRequestBody(array $body): ?string | ||
{ | ||
if (empty($body)) { | ||
return null; | ||
} | ||
|
||
return @json_encode($body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.