mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-14 06:06:18 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
51
src/Id/Resources/BaseCollection.php
Normal file
51
src/Id/Resources/BaseCollection.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JsonSerializable;
|
||||
|
||||
abstract class BaseCollection implements JsonSerializable
|
||||
{
|
||||
public function __construct(protected Result $result)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of resources as an array.
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return (array) $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of resources as a JSON string.
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of resources.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function get(): Result
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Resource based on the ID.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
abstract public function find(string $id): ?BaseResource;
|
||||
}
|
||||
Reference in New Issue
Block a user