Skip to content

Deprecate triats in favour of interfaces #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/ErrorMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace ApiClients\Foundation\Middleware;

use React\Promise\CancellablePromiseInterface;
use Throwable;

interface ErrorMiddlewareInterface
{
/**
* Transform the throwable into another throwable or exception,
* but never turn it into a successful promise again.
*
* @param Throwable $throwable
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function error(
Throwable $throwable,
string $transactionId,
array $options = []
): CancellablePromiseInterface;
}
2 changes: 1 addition & 1 deletion src/ErrorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use React\Promise\CancellablePromiseInterface;
use Throwable;

use function React\Promise\reject;

trait ErrorTrait
Expand All @@ -13,6 +12,7 @@ trait ErrorTrait
* @param Throwable $throwable
* @param array $options
* @return CancellablePromiseInterface
* @deprecated Will be removed in the next major version.
*/
public function error(
Throwable $throwable,
Expand Down
51 changes: 1 addition & 50 deletions src/MiddlewareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,12 @@

namespace ApiClients\Foundation\Middleware;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use React\Promise\CancellablePromiseInterface;
use Throwable;

/**
* Middleware, when a new request is made an instance specifically for that request is made for each request.
*
* Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre`/`post`/`error`
* and 0 last on `pre`/`post`/`error`.
*/
interface MiddlewareInterface
interface MiddlewareInterface extends PreMiddlewareInterface, PostMiddlewareInterface, ErrorMiddlewareInterface
{
/**
* Return the processed $request via a fulfilled promise.
* When implementing cache or other feature that returns a response, do it with a rejected promise.
* If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
*
* @param RequestInterface $request
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function pre(
RequestInterface $request,
string $transactionId,
array $options = []
): CancellablePromiseInterface;

/**
* Return the processed $response via a promise.
*
* @param ResponseInterface $response
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function post(
ResponseInterface $response,
string $transactionId,
array $options = []
): CancellablePromiseInterface;

/**
* Transform the throwable into another throwable or exception,
* but never turn it into a successful promise again.
*
* @param Throwable $throwable
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function error(
Throwable $throwable,
string $transactionId,
array $options = []
): CancellablePromiseInterface;
}
23 changes: 23 additions & 0 deletions src/PostMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace ApiClients\Foundation\Middleware;

use Psr\Http\Message\ResponseInterface;
use React\Promise\CancellablePromiseInterface;

interface PostMiddlewareInterface
{
/**
* Return the processed $response via a promise.
*
* @param ResponseInterface $response
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function post(
ResponseInterface $response,
string $transactionId,
array $options = []
): CancellablePromiseInterface;
}
1 change: 1 addition & 0 deletions src/PostTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ trait PostTrait
* @param ResponseInterface $response
* @param array $options
* @return CancellablePromiseInterface
* @deprecated Will be removed in the next major version.
*/
public function post(
ResponseInterface $response,
Expand Down
25 changes: 25 additions & 0 deletions src/PreMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace ApiClients\Foundation\Middleware;

use Psr\Http\Message\RequestInterface;
use React\Promise\CancellablePromiseInterface;

interface PreMiddlewareInterface
{
/**
* Return the processed $request via a fulfilled promise.
* When implementing cache or other feature that returns a response, do it with a rejected promise.
* If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
*
* @param RequestInterface $request
* @param array $options
* @param string $transactionId
* @return CancellablePromiseInterface
*/
public function pre(
RequestInterface $request,
string $transactionId,
array $options = []
): CancellablePromiseInterface;
}
1 change: 1 addition & 0 deletions src/PreTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ trait PreTrait
* @param RequestInterface $request
* @param array $options
* @return CancellablePromiseInterface
* @deprecated Will be removed in the next major version.
*/
public function pre(
RequestInterface $request,
Expand Down