mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-14 14:16:31 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
33
src/Id/Resources/BaseResource.php
Normal file
33
src/Id/Resources/BaseResource.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\MagicProperties;
|
||||
use Anikeen\Id\Result;
|
||||
use JsonSerializable;
|
||||
|
||||
abstract class BaseResource implements JsonSerializable
|
||||
{
|
||||
use MagicProperties;
|
||||
|
||||
public function __construct(protected Result $result)
|
||||
{
|
||||
$this->setMagicProperties($this->result->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of resources as an array.
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return (array) $this->result->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of resources as a JSON string.
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user