generated from cerbero90/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
14 changed files
with
332 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Cerbero\LazyJsonPages\Exceptions; | ||
|
||
/** | ||
* The exception thrown when a source did not send any HTTP request. | ||
*/ | ||
class RequestNotSentException extends LazyJsonPagesException | ||
{ | ||
/** | ||
* Instantiate the class. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct("The source did not send any HTTP request."); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Sources; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* The user-defined source. | ||
* | ||
* @property-read Source $source | ||
*/ | ||
class CustomSource extends Source | ||
{ | ||
/** | ||
* Determine whether this class can handle the source. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->source instanceof Source; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request. | ||
*/ | ||
public function request(): RequestInterface | ||
{ | ||
return $this->source->request(); | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP response. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function response(): ResponseInterface | ||
{ | ||
return $this->source->response(); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Sources; | ||
|
||
use Cerbero\LazyJsonPages\Services\Client; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Illuminate\Http\Client\Request; | ||
|
||
/** | ||
* The Laravel HTTP client source. | ||
* | ||
* @property-read Request $source | ||
*/ | ||
class LaravelClientRequest extends Source | ||
{ | ||
/** | ||
* Determine whether this class can handle the source. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->source instanceof Request; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request. | ||
*/ | ||
public function request(): RequestInterface | ||
{ | ||
return $this->source->toPsrRequest(); | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP response. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function response(): ResponseInterface | ||
{ | ||
return Client::instance()->send($this->request()); | ||
} | ||
} |
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 Cerbero\LazyJsonPages\Sources; | ||
|
||
use Cerbero\LazyJsonPages\Exceptions\RequestNotSentException; | ||
use Cerbero\LazyJsonPages\Services\Client; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Illuminate\Http\Client\Response; | ||
|
||
/** | ||
* The Laravel HTTP client source. | ||
* | ||
* @property-read Response $source | ||
*/ | ||
class LaravelClientResponse extends Source | ||
{ | ||
/** | ||
* Determine whether this class can handle the source. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->source instanceof Response; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request. | ||
*/ | ||
public function request(): RequestInterface | ||
{ | ||
return $this->source->transferStats?->getRequest() | ||
?: throw new RequestNotSentException(); | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP response. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function response(): ResponseInterface | ||
{ | ||
return $this->source->toPsrResponse(); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Sources; | ||
|
||
use Cerbero\LazyJsonPages\Services\Client; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* The PSR-7 request source. | ||
* | ||
* @property-read RequestInterface $source | ||
*/ | ||
class Psr7Request extends Source | ||
{ | ||
/** | ||
* Determine whether this class can handle the source. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->source instanceof RequestInterface; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request. | ||
*/ | ||
public function request(): RequestInterface | ||
{ | ||
return $this->source; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP response. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function response(): ResponseInterface | ||
{ | ||
return Client::instance()->send($this->source); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Sources; | ||
|
||
use Cerbero\LazyJsonPages\Services\Client; | ||
use GuzzleHttp\Psr7\Request as Psr7Request; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* The Symfony request source. | ||
* | ||
* @property-read Request $source | ||
*/ | ||
class SymfonyRequest extends Source | ||
{ | ||
/** | ||
* Determine whether this class can handle the source. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->source instanceof Request; | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request. | ||
*/ | ||
public function request(): RequestInterface | ||
{ | ||
return new Psr7Request( | ||
$this->source->getMethod(), | ||
$this->source->getUri(), | ||
$this->source->headers->all(), | ||
$this->source->getContent() ?: null, | ||
); | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP response. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function response(): ResponseInterface | ||
{ | ||
return Client::instance()->send($this->request()); | ||
} | ||
} |
Oops, something went wrong.