-
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.
Merge pull request #9 from mops1k/1.0.8
1.0.8
- Loading branch information
Showing
7 changed files
with
180 additions
and
3 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,25 @@ | ||
<?php | ||
|
||
namespace ApiClientBundle\HTTP\Context; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class Context implements ContextInterface | ||
{ | ||
public function __construct( | ||
private readonly RequestInterface $request, | ||
private readonly ?ResponseInterface $response, | ||
) { | ||
} | ||
|
||
public function getRequest(): RequestInterface | ||
{ | ||
return $this->request; | ||
} | ||
|
||
public function getResponse(): ?ResponseInterface | ||
{ | ||
return $this->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace ApiClientBundle\HTTP\Context; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
interface ContextInterface | ||
{ | ||
public function __construct(RequestInterface $request, ?ResponseInterface $response); | ||
|
||
public function getRequest(): RequestInterface; | ||
public function getResponse(): ?ResponseInterface; | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace ApiClientBundle\HTTP\Context; | ||
|
||
use ApiClientBundle\Client\QueryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ContextStorage implements ContextStorageInterface | ||
{ | ||
/** | ||
* @var array<string, ContextInterface> | ||
*/ | ||
private static array $collection = []; | ||
|
||
public function add(QueryInterface $query, RequestInterface $request, ?ResponseInterface $response = null): static | ||
{ | ||
self::$collection[\spl_object_hash($query)] = new Context( | ||
request: $request, | ||
response: $response | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
public static function get(QueryInterface $query): ?ContextInterface | ||
{ | ||
if (false === self::has($query)) { | ||
return null; | ||
} | ||
|
||
return self::$collection[\spl_object_hash($query)]; | ||
} | ||
|
||
public static function remove(QueryInterface $query): void | ||
{ | ||
if (true === self::has($query)) { | ||
unset(self::$collection[\spl_object_hash($query)]); | ||
} | ||
} | ||
|
||
public static function has(QueryInterface $query): bool | ||
{ | ||
return \array_key_exists(\spl_object_hash($query), self::$collection); | ||
} | ||
|
||
public static function clear(): void | ||
{ | ||
self::$collection = []; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ApiClientBundle\HTTP\Context; | ||
|
||
use ApiClientBundle\Client\QueryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
interface ContextStorageInterface | ||
{ | ||
public function add(QueryInterface $query, RequestInterface $request, ?ResponseInterface $response): static; | ||
public static function get(QueryInterface $query): ?ContextInterface; | ||
public static function remove(QueryInterface $query): void; | ||
public static function has(QueryInterface $query): bool; | ||
public static function clear(): void; | ||
} |
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