-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
254 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jenky\JsonPlaceholder\DTO; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
final class ErrorResponse | ||
{ | ||
public function __construct( | ||
public readonly int $statusCode, | ||
public readonly string $reason, | ||
) { | ||
} | ||
|
||
public static function fromResponse(ResponseInterface $response): self | ||
{ | ||
return new self($response->getStatusCode(), $response->getReasonPhrase()); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jenky\JsonPlaceholder; | ||
|
||
trait HasPagination | ||
{ | ||
private ?int $limit = null; | ||
|
||
private ?int $page = null; | ||
|
||
public function limit(int $limit): self | ||
{ | ||
$clone = clone $this; | ||
$clone->page = $limit; | ||
|
||
return $clone; | ||
} | ||
|
||
public function page(int $page): self | ||
{ | ||
$clone = clone $this; | ||
$clone->page = $page; | ||
|
||
return $clone; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jenky\JsonPlaceholder; | ||
|
||
use Fansipan\Contracts\ConnectorInterface; | ||
|
||
/** | ||
* @template T of ConnectorInterface | ||
*/ | ||
abstract class ResourceBuilder | ||
{ | ||
protected string|int $id; | ||
|
||
/** | ||
* @param T $connector | ||
*/ | ||
public function __construct( | ||
protected ConnectorInterface $connector, | ||
protected array $refs = [], | ||
) { | ||
} | ||
|
||
public function id(string|int $id): static | ||
{ | ||
$clone = clone $this; | ||
$clone->id = $id; | ||
$clone->refs[static::class] = $id; | ||
|
||
return $clone; | ||
} | ||
|
||
/** | ||
* @template TResource of ResourceBuilder | ||
* | ||
* @param class-string<TResource> $builder | ||
* @return TResource | ||
*/ | ||
protected function forward(string $builder): ResourceBuilder | ||
{ | ||
\assert(\is_subclass_of($builder, ResourceBuilder::class, true)); | ||
|
||
return new $builder($this->connector, $this->refs); | ||
} | ||
} |
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.