From 3cd0f0f0194a16898ddc0b4c2b87a811c7eca6a4 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 14 Apr 2022 14:36:44 +0200 Subject: [PATCH] refactor: Use `loophp/psr17` dependency. --- composer.json | 5 ++ spec/EcPhp/CasLib/CasSpec.php | 71 ++++++++++-------- .../CasLib/Handler/ProxyCallbackSpec.php | 19 +++-- spec/EcPhp/CasLib/Redirect/LoginSpec.php | 30 +++++--- spec/EcPhp/CasLib/Redirect/LogoutSpec.php | 10 ++- spec/EcPhp/CasLib/Service/ProxySpec.php | 8 +- .../CasLib/Service/ProxyValidateSpec.php | 10 ++- spec/tests/EcPhp/CasLib/CasSpec.php | 12 +-- .../CasLib/Service/ProxyValidateSpec.php | 34 +++------ src/Cas.php | 75 ++++--------------- src/Handler/Handler.php | 40 +++------- src/Handler/ProxyCallback.php | 2 +- src/Redirect/Redirect.php | 2 +- src/Service/Service.php | 26 ++----- tests/Service/ProxyValidate.php | 24 ------ 15 files changed, 135 insertions(+), 233 deletions(-) diff --git a/composer.json b/composer.json index 217acad..20aa809 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "friends-of-phpspec/phpspec-code-coverage": "^6.0.0", "infection/infection": "^0.23 || ^0.24", "infection/phpspec-adapter": "^0.1.2", + "loophp/psr17": "^1.0", "monolog/monolog": "^1.0", "nyholm/psr7": "^1.4", "nyholm/psr7-server": "^1.0.0", @@ -40,6 +41,10 @@ "symfony/cache": "^5.2", "symfony/http-client": "^5.2" }, + "suggest": { + "loophp/psr17": "Provides a PSR17 synthetic implementation", + "nyholm/psr7": "A super lightweight PSR-7 implementation" + }, "autoload": { "psr-4": { "EcPhp\\CasLib\\": "./src/" diff --git a/spec/EcPhp/CasLib/CasSpec.php b/spec/EcPhp/CasLib/CasSpec.php index a03ad3e..c26da80 100644 --- a/spec/EcPhp/CasLib/CasSpec.php +++ b/spec/EcPhp/CasLib/CasSpec.php @@ -28,12 +28,7 @@ use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Log\LoggerInterface; use spec\EcPhp\CasLib\Cas as CasSpecUtils; use Symfony\Component\Cache\CacheItem; @@ -72,20 +67,16 @@ public function it_can_authenticate() } /** - * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Message\ServerRequestInterface $serverRequest * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Client\ClientInterface $client - * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Message\UriFactoryInterface $uriFactory - * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Message\RequestFactoryInterface $requestFactory - * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Message\ResponseFactoryInterface $responseFactory - * @param \PhpSpec\Wrapper\Collaborator|\Psr\Http\Message\StreamFactoryInterface $streamFactory * @param \PhpSpec\Wrapper\Collaborator|\Psr\Cache\CacheItemPoolInterface $cache * @param \PhpSpec\Wrapper\Collaborator|\Psr\Log\LoggerInterface $logger * * @throws \Psr\Cache\InvalidArgumentException */ - public function it_can_authenticate_a_request(ServerRequestInterface $serverRequest, ClientInterface $client, UriFactoryInterface $uriFactory, RequestFactoryInterface $requestFactory, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_can_authenticate_a_request(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -99,7 +90,7 @@ public function it_can_authenticate_a_request(ServerRequestInterface $serverRequ ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request('GET', UtilsUri::withParams(new Uri('http://from'), ['ticket' => 'ST-TICKET-VALID'])); @@ -154,6 +145,7 @@ public function it_can_authenticate_a_request(ServerRequestInterface $serverRequ public function it_can_authenticate_a_request_in_proxy_mode(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -175,7 +167,7 @@ public function it_can_authenticate_a_request_in_proxy_mode(ClientInterface $cli ->hasItem('pgtIouWithPgtIdNull') ->willReturn(false); - $this->beConstructedWith(CasSpecUtils::getTestPropertiesWithPgtUrl(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestPropertiesWithPgtUrl(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request('GET', UtilsUri::withParams(new Uri('http://from'), ['ticket' => 'ST-TICKET-VALID'])); @@ -266,8 +258,9 @@ public function it_can_be_constructed_without_base_url(LoggerInterface $logger, $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $request = new ServerRequest('GET', 'http://foo'); @@ -280,6 +273,7 @@ public function it_can_be_constructed_without_base_url(LoggerInterface $logger, public function it_can_check_if_the_logger_works_during_a_failed_authentication_of_service_ticket(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -293,7 +287,7 @@ public function it_can_check_if_the_logger_works_during_a_failed_authentication_ ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -328,9 +322,10 @@ public function it_can_check_if_the_logger_works_during_a_failed_authentication_ ->shouldHaveBeenCalledOnce(); } - public function it_can_check_if_the_logger_works_during_a_failed_proxy_validate_request(ServerRequestInterface $serverRequest, ClientInterface $client, UriFactoryInterface $uriFactory, RequestFactoryInterface $requestFactory, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_can_check_if_the_logger_works_during_a_failed_proxy_validate_request(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -352,7 +347,7 @@ public function it_can_check_if_the_logger_works_during_a_failed_proxy_validate_ ) ); - $this->beConstructedWith(CasSpecUtils::getTestPropertiesWithPgtUrl(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestPropertiesWithPgtUrl(), $client, $psr17, $cache, $logger, new Introspector()); $this ->requestProxyValidate($request) @@ -363,9 +358,10 @@ public function it_can_check_if_the_logger_works_during_a_failed_proxy_validate_ ->shouldHaveBeenCalledOnce(); } - public function it_can_check_if_the_logger_works_during_a_failed_service_validate_request(ServerRequestInterface $serverRequest, ClientInterface $client, UriFactoryInterface $uriFactory, RequestFactoryInterface $requestFactory, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_can_check_if_the_logger_works_during_a_failed_service_validate_request(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -379,7 +375,7 @@ public function it_can_check_if_the_logger_works_during_a_failed_service_validat ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -398,9 +394,10 @@ public function it_can_check_if_the_logger_works_during_a_failed_service_validat ->shouldHaveBeenCalledOnce(); } - public function it_can_check_if_the_logger_works_during_a_successful_authentication_of_service_ticket(ServerRequestInterface $serverRequest, ClientInterface $client, UriFactoryInterface $uriFactory, RequestFactoryInterface $requestFactory, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_can_check_if_the_logger_works_during_a_successful_authentication_of_service_ticket(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $cacheItem = new CacheItem(); @@ -414,7 +411,7 @@ public function it_can_check_if_the_logger_works_during_a_successful_authenticat ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -541,8 +538,9 @@ public function it_can_detect_wrong_url(LoggerInterface $logger, CacheItemPoolIn $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $parameters = [ 'service' => 'service', @@ -818,7 +816,8 @@ public function it_can_parse_a_bad_proxy_request_response(CacheItemPoolInterface { $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -838,7 +837,8 @@ public function it_can_parse_a_good_proxy_request_response(CacheItemPoolInterfac { $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -874,7 +874,8 @@ public function it_can_parse_json_in_a_response(LoggerInterface $logger, CacheIt $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -916,8 +917,8 @@ public function it_can_request_a_proxy_ticket(LoggerInterface $logger, CacheItem { $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -965,8 +966,8 @@ public function it_can_validate_a_bad_proxy_ticket(LoggerInterface $logger, Cach $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'POST', @@ -986,7 +987,8 @@ public function it_can_validate_a_bad_service_validate_request(LoggerInterface $ { $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith(CasSpecUtils::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'POST', @@ -1058,7 +1060,8 @@ public function it_can_validate_a_good_proxy_ticket(LoggerInterface $logger, Cac $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -1146,7 +1149,8 @@ public function it_can_validate_a_good_service_validate_request(LoggerInterface $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -1228,6 +1232,7 @@ public function let(LoggerInterface $logger, CacheItemPoolInterface $cache, Cach $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $cacheItemPgtIou ->set('pgtId') @@ -1281,6 +1286,6 @@ public function let(LoggerInterface $logger, CacheItemPoolInterface $cache, Cach ->getItem('pgtIouWithPgtIdNull') ->willReturn($cacheItemPgtIdNull); - $this->beConstructedWith($properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith($properties, $client, $psr17, $cache, $logger, new Introspector()); } } diff --git a/spec/EcPhp/CasLib/Handler/ProxyCallbackSpec.php b/spec/EcPhp/CasLib/Handler/ProxyCallbackSpec.php index 545bbc7..56cbdfb 100644 --- a/spec/EcPhp/CasLib/Handler/ProxyCallbackSpec.php +++ b/spec/EcPhp/CasLib/Handler/ProxyCallbackSpec.php @@ -14,6 +14,7 @@ use EcPhp\CasLib\Handler\ProxyCallback; use EcPhp\CasLib\Utils\Uri as UtilsUri; use Exception; +use loophp\psr17\Psr17; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Request; use Nyholm\Psr7\Uri; @@ -28,6 +29,7 @@ class ProxyCallbackSpec extends ObjectBehavior public function it_can_catch_issue_with_the_cache(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $request = new Request( 'GET', @@ -58,7 +60,7 @@ public function it_can_catch_issue_with_the_cache(CacheItemPoolInterface $cache, ->save($cacheItem) ->willReturn(true); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $this ->handle($request); @@ -92,8 +94,9 @@ public function it_can_test_if_the_cache_is_working(CacheItemPoolInterface $cach public function it_can_test_the_logger_when_missing_pgtId(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -116,8 +119,9 @@ public function it_can_test_the_logger_when_missing_pgtId(CacheItemPoolInterface public function it_can_test_the_logger_when_missing_pgtIou(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -140,8 +144,9 @@ public function it_can_test_the_logger_when_missing_pgtIou(CacheItemPoolInterfac public function it_can_test_the_logger_when_no_parameter_is_in_the_url(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -162,6 +167,7 @@ public function it_can_test_the_logger_when_no_parameter_is_in_the_url(CacheItem public function it_can_test_the_logger_when_parameters_are_in_the_url(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $cacheItem ->set('pgtId') @@ -179,7 +185,7 @@ public function it_can_test_the_logger_when_parameters_are_in_the_url(CacheItemP ->save($cacheItem) ->willReturn(true); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -208,6 +214,7 @@ public function it_is_initializable() public function let(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $cacheItem ->set('pgtId') @@ -225,6 +232,6 @@ public function let(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem ->save($cacheItem) ->willReturn(true); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); } } diff --git a/spec/EcPhp/CasLib/Redirect/LoginSpec.php b/spec/EcPhp/CasLib/Redirect/LoginSpec.php index ce5f80c..551043c 100644 --- a/spec/EcPhp/CasLib/Redirect/LoginSpec.php +++ b/spec/EcPhp/CasLib/Redirect/LoginSpec.php @@ -12,6 +12,8 @@ namespace spec\EcPhp\CasLib\Redirect; use EcPhp\CasLib\Redirect\Login; +use loophp\psr17\Psr17; +use loophp\psr17\Psr17Interface; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Request; use Nyholm\Psr7\Uri; @@ -26,17 +28,18 @@ class LoginSpec extends ObjectBehavior public function it_can_deal_with_array_parameters(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); - - $request = new Request( - 'GET', - new Uri('http://from/it_can_deal_with_array_parameters') - ); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $parameters = [ 'custom' => range(1, 5), ]; - $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger); + + $request = new Request( + 'GET', + new Uri('http://from/it_can_deal_with_array_parameters') + ); $this ->handle($request) @@ -51,6 +54,7 @@ public function it_can_deal_with_array_parameters(CacheItemPoolInterface $cache, public function it_can_deal_with_renew_and_gateway_parameters(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $parameters = [ 'renew' => true, @@ -58,7 +62,7 @@ public function it_can_deal_with_renew_and_gateway_parameters(CacheItemPoolInter 'service' => 'service', ]; - $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -91,13 +95,14 @@ public function it_can_deal_with_renew_and_gateway_parameters(CacheItemPoolInter public function it_can_deal_with_renew_parameter(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $parameters = [ 'renew' => 'coin', 'gateway' => false, ]; - $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -121,7 +126,9 @@ public function it_can_deal_with_renew_parameter(CacheItemPoolInterface $cache, public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -133,10 +140,9 @@ public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInter ->shouldBeAnInstanceOf(ResponseInterface::class); } - public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17) { - $psr17Factory = new Psr17Factory(); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $this->shouldHaveType(Login::class); } diff --git a/spec/EcPhp/CasLib/Redirect/LogoutSpec.php b/spec/EcPhp/CasLib/Redirect/LogoutSpec.php index e186ecb..38fff0d 100644 --- a/spec/EcPhp/CasLib/Redirect/LogoutSpec.php +++ b/spec/EcPhp/CasLib/Redirect/LogoutSpec.php @@ -12,6 +12,8 @@ namespace spec\EcPhp\CasLib\Redirect; use EcPhp\CasLib\Redirect\Logout; +use loophp\psr17\Psr17; +use loophp\psr17\Psr17Interface; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Request; use Nyholm\Psr7\Uri; @@ -26,7 +28,8 @@ class LogoutSpec extends ObjectBehavior public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $request = new Request( 'GET', @@ -38,10 +41,9 @@ public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInter ->shouldBeAnInstanceOf(ResponseInterface::class); } - public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger) + public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17) { - $psr17Factory = new Psr17Factory(); - $this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); + $this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger); $this->shouldHaveType(Logout::class); } diff --git a/spec/EcPhp/CasLib/Service/ProxySpec.php b/spec/EcPhp/CasLib/Service/ProxySpec.php index fcd33e8..f93ed6b 100644 --- a/spec/EcPhp/CasLib/Service/ProxySpec.php +++ b/spec/EcPhp/CasLib/Service/ProxySpec.php @@ -13,7 +13,7 @@ use EcPhp\CasLib\Introspection\Introspector; use EcPhp\CasLib\Service\Proxy; -use Nyholm\Psr7\Factory\Psr17Factory; +use loophp\psr17\Psr17Interface; use Nyholm\Psr7\Response; use PhpSpec\ObjectBehavior; use Psr\Cache\CacheItemPoolInterface; @@ -58,10 +58,8 @@ public function it_is_initializable() $this->shouldHaveType(Proxy::class); } - public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) + public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17) { - $psr17Factory = new Psr17Factory(); - - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); } } diff --git a/spec/EcPhp/CasLib/Service/ProxyValidateSpec.php b/spec/EcPhp/CasLib/Service/ProxyValidateSpec.php index 7443395..b2ecd6b 100644 --- a/spec/EcPhp/CasLib/Service/ProxyValidateSpec.php +++ b/spec/EcPhp/CasLib/Service/ProxyValidateSpec.php @@ -13,6 +13,7 @@ use EcPhp\CasLib\Introspection\Introspector; use EcPhp\CasLib\Service\ProxyValidate; +use loophp\psr17\Psr17; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Request; use Nyholm\Psr7\Response; @@ -41,6 +42,7 @@ public function it_can_detect_when_no_credentials() public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); @@ -68,7 +70,7 @@ public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, Cach ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith([], Cas::getTestPropertiesWithPgtUrl(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestPropertiesWithPgtUrl(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -92,10 +94,11 @@ public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, Cach public function it_can_get_credentials_without_pgtUrl(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $request = new Request( 'GET', @@ -124,7 +127,8 @@ public function it_is_initializable() public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); } } diff --git a/spec/tests/EcPhp/CasLib/CasSpec.php b/spec/tests/EcPhp/CasLib/CasSpec.php index 048bced..96ff142 100644 --- a/spec/tests/EcPhp/CasLib/CasSpec.php +++ b/spec/tests/EcPhp/CasLib/CasSpec.php @@ -31,16 +31,14 @@ public function it_can_test_the_proxy_mode_with_pgtUrl() $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $introspector = new Introspector(); $this->beConstructedWith(new Cas( $properties, $client, - $psr17Factory, - $psr17Factory, - $psr17Factory, - $psr17Factory, + $psr17, new ArrayAdapter(), new NullLogger(), $introspector @@ -64,16 +62,14 @@ public function it_can_test_the_proxy_mode_without_pgtUrl() $client = new Psr18Client(CasSpecUtils::getHttpClientMock()); $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $introspector = new Introspector(); $this->beConstructedWith(new Cas( $properties, $client, - $psr17Factory, - $psr17Factory, - $psr17Factory, - $psr17Factory, + $psr17, new ArrayAdapter(), new NullLogger(), $introspector diff --git a/spec/tests/EcPhp/CasLib/Service/ProxyValidateSpec.php b/spec/tests/EcPhp/CasLib/Service/ProxyValidateSpec.php index da297e5..92fbfdc 100644 --- a/spec/tests/EcPhp/CasLib/Service/ProxyValidateSpec.php +++ b/spec/tests/EcPhp/CasLib/Service/ProxyValidateSpec.php @@ -13,6 +13,7 @@ use EcPhp\CasLib\Introspection\Contract\IntrospectorInterface; use EcPhp\CasLib\Introspection\Introspector; +use loophp\psr17\Psr17; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Request; use Nyholm\Psr7\Response; @@ -21,10 +22,6 @@ use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\ResponseFactoryInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Log\LoggerInterface; use spec\EcPhp\CasLib\Cas; use Symfony\Component\HttpClient\Psr18Client; @@ -35,6 +32,7 @@ class ProxyValidateSpec extends ObjectBehavior public function it_can_check_the_visibility_of_some_methods(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(Cas::getHttpClientMock()); @@ -62,7 +60,7 @@ public function it_can_check_the_visibility_of_some_methods(CacheItemPoolInterfa ->getItem('pgtIou') ->willReturn($cacheItem); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $this ->getClient() @@ -76,22 +74,6 @@ public function it_can_check_the_visibility_of_some_methods(CacheItemPoolInterfa ->getCache() ->shouldBeAnInstanceOf(CacheItemPoolInterface::class); - $this - ->getUriFactory() - ->shouldBeAnInstanceOf(UriFactoryInterface::class); - - $this - ->getStreamFactory() - ->shouldBeAnInstanceOf(StreamFactoryInterface::class); - - $this - ->getRequestFactory() - ->shouldBeAnInstanceOf(RequestFactoryInterface::class); - - $this - ->getResponseFactory() - ->shouldBeAnInstanceOf(ResponseFactoryInterface::class); - $this ->getIntrospector() ->shouldBeAnInstanceOf(IntrospectorInterface::class); @@ -129,14 +111,14 @@ public function it_can_detect_when_no_credentials() public function it_can_log_debugging_information_when_trying_to_get_unexisting_pgtIou(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); - + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(Cas::getHttpClientMock()); $cache ->hasItem('pgtIou') ->willReturn(false); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $response = [ 'serviceResponse' => [ @@ -158,10 +140,11 @@ public function it_can_log_debugging_information_when_trying_to_get_unexisting_p public function it_can_parse_a_response(CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); $client = new Psr18Client(Cas::getHttpClientMock()); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); $response = new Response(200, [], 'foo'); $request = new Request( @@ -186,7 +169,8 @@ public function it_is_initializable() public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger) { $psr17Factory = new Psr17Factory(); + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); - $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector()); + $this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector()); } } diff --git a/src/Cas.php b/src/Cas.php index 283920c..6e5b07a 100644 --- a/src/Cas.php +++ b/src/Cas.php @@ -21,14 +21,11 @@ use EcPhp\CasLib\Service\ProxyValidate; use EcPhp\CasLib\Service\ServiceValidate; use EcPhp\CasLib\Utils\Uri; +use loophp\psr17\Psr17Interface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Log\LoggerInterface; use function array_key_exists; @@ -47,34 +44,22 @@ final class Cas implements CasInterface private PropertiesInterface $properties; - private RequestFactoryInterface $requestFactory; - - private ResponseFactoryInterface $responseFactory; - - private StreamFactoryInterface $streamFactory; - - private UriFactoryInterface $uriFactory; + private Psr17Interface $psr17; public function __construct( PropertiesInterface $properties, ClientInterface $client, - UriFactoryInterface $uriFactory, - ResponseFactoryInterface $responseFactory, - RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory, + Psr17Interface $psr17, CacheItemPoolInterface $cache, LoggerInterface $logger, IntrospectorInterface $introspector ) { - $this->properties = $properties; - $this->client = $client; - $this->uriFactory = $uriFactory; - $this->responseFactory = $responseFactory; - $this->requestFactory = $requestFactory; - $this->streamFactory = $streamFactory; $this->cache = $cache; - $this->logger = $logger; + $this->client = $client; $this->introspector = $introspector; + $this->logger = $logger; + $this->properties = $properties; + $this->psr17 = $psr17; } public function authenticate(RequestInterface $request, array $parameters = []): ?array @@ -108,9 +93,7 @@ public function handleProxyCallback( $proxyCallback = new ProxyCallback( $parameters, $this->getProperties(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger() ); @@ -123,9 +106,7 @@ public function login(RequestInterface $request, array $parameters = []): ?Respo $login = new Login( $parameters, $this->getProperties(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger() ); @@ -138,9 +119,7 @@ public function logout(RequestInterface $request, array $parameters = []): ?Resp $logout = new Logout( $parameters, $this->getProperties(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger() ); @@ -156,10 +135,7 @@ public function requestProxyTicket( $parameters, $this->getProperties(), $this->getHttpClient(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getRequestFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger(), $this->getIntrospector() @@ -192,10 +168,7 @@ public function requestProxyValidate( $parameters, $this->getProperties(), $this->getHttpClient(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getRequestFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger(), $this->getIntrospector() @@ -228,10 +201,7 @@ public function requestServiceValidate( $parameters, $this->getProperties(), $this->getHttpClient(), - $this->getUriFactory(), - $this->getResponseFactory(), - $this->getRequestFactory(), - $this->getStreamFactory(), + $this->getPsr17(), $this->getCache(), $this->getLogger(), $this->getIntrospector() @@ -305,24 +275,9 @@ private function getLogger(): LoggerInterface return $this->logger; } - private function getRequestFactory(): RequestFactoryInterface - { - return $this->requestFactory; - } - - private function getResponseFactory(): ResponseFactoryInterface - { - return $this->responseFactory; - } - - private function getStreamFactory(): StreamFactoryInterface - { - return $this->streamFactory; - } - - private function getUriFactory(): UriFactoryInterface + private function getPsr17(): Psr17Interface { - return $this->uriFactory; + return $this->psr17; } private function proxyMode(): bool diff --git a/src/Handler/Handler.php b/src/Handler/Handler.php index 8bcf6af..8a30694 100644 --- a/src/Handler/Handler.php +++ b/src/Handler/Handler.php @@ -13,11 +13,9 @@ use EcPhp\CasLib\Configuration\PropertiesInterface; use EcPhp\CasLib\Utils\Uri; +use loophp\psr17\Psr17Interface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseFactoryInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; @@ -33,11 +31,7 @@ abstract class Handler private PropertiesInterface $properties; - private ResponseFactoryInterface $responseFactory; - - private StreamFactoryInterface $streamFactory; - - private UriFactoryInterface $uriFactory; + private Psr17Interface $psr17; /** * @param array[]|string[] $parameters @@ -45,19 +39,15 @@ abstract class Handler public function __construct( array $parameters, PropertiesInterface $properties, - UriFactoryInterface $uriFactory, - ResponseFactoryInterface $responseFactory, - StreamFactoryInterface $streamFactory, + Psr17Interface $psr17, CacheItemPoolInterface $cache, LoggerInterface $logger ) { - $this->parameters = $parameters; - $this->properties = $properties; - $this->uriFactory = $uriFactory; - $this->responseFactory = $responseFactory; - $this->streamFactory = $streamFactory; $this->cache = $cache; $this->logger = $logger; + $this->parameters = $parameters; + $this->properties = $properties; + $this->psr17 = $psr17; } /** @@ -101,7 +91,7 @@ static function ($item): bool { } ); - return $this->getUriFactory() + return $this->getPsr17() ->createUri($properties['base_url']) ->withPath($baseUrl['path'] . $properties['protocol'][$name]['path']) ->withQuery(http_build_query($query)) @@ -127,7 +117,7 @@ static function ($parameter) { ); if (true === array_key_exists('service', $parameters)) { - $service = $this->getUriFactory()->createUri( + $service = $this->getPsr17()->createUri( $parameters['service'] ); @@ -175,18 +165,8 @@ protected function getProtocolProperties(RequestInterface $request): array return []; } - protected function getResponseFactory(): ResponseFactoryInterface - { - return $this->responseFactory; - } - - protected function getStreamFactory(): StreamFactoryInterface - { - return $this->streamFactory; - } - - protected function getUriFactory(): UriFactoryInterface + protected function getPsr17(): Psr17Interface { - return $this->uriFactory; + return $this->psr17; } } diff --git a/src/Handler/ProxyCallback.php b/src/Handler/ProxyCallback.php index 56a3796..6dd26cb 100644 --- a/src/Handler/ProxyCallback.php +++ b/src/Handler/ProxyCallback.php @@ -21,7 +21,7 @@ final class ProxyCallback extends Handler implements HandlerInterface public function handle(RequestInterface $request): ?ResponseInterface { $response = $this - ->getResponseFactory() + ->getPsr17() ->createResponse(200); // POST parameters prevails over GET parameters. diff --git a/src/Redirect/Redirect.php b/src/Redirect/Redirect.php index f908170..fe746c3 100644 --- a/src/Redirect/Redirect.php +++ b/src/Redirect/Redirect.php @@ -23,7 +23,7 @@ protected function createRedirectResponse(string $url): ResponseInterface ->debug('Building service response redirection to {url}.', ['url' => $url]); return $this - ->getResponseFactory() + ->getPsr17() ->createResponse(302) ->withHeader('Location', $url); } diff --git a/src/Service/Service.php b/src/Service/Service.php index 7defb34..96c6793 100644 --- a/src/Service/Service.php +++ b/src/Service/Service.php @@ -16,15 +16,12 @@ use EcPhp\CasLib\Introspection\Contract\IntrospectorInterface; use EcPhp\CasLib\Introspection\Contract\ServiceValidate; use InvalidArgumentException; +use loophp\psr17\Psr17Interface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; @@ -38,16 +35,11 @@ abstract class Service extends Handler private IntrospectorInterface $introspector; - private RequestFactoryInterface $requestFactory; - public function __construct( array $parameters, PropertiesInterface $properties, ClientInterface $client, - UriFactoryInterface $uriFactory, - ResponseFactoryInterface $responseFactory, - RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory, + Psr17Interface $psr17, CacheItemPoolInterface $cache, LoggerInterface $logger, IntrospectorInterface $introspector @@ -55,15 +47,12 @@ public function __construct( parent::__construct( $parameters, $properties, - $uriFactory, - $responseFactory, - $streamFactory, + $psr17, $cache, $logger ); $this->client = $client; - $this->requestFactory = $requestFactory; $this->introspector = $introspector; } @@ -123,7 +112,7 @@ public function getCredentials(ResponseInterface $response): ?ResponseInterface ->debug('Proxy validation service successful.'); return $response - ->withBody($this->getStreamFactory()->createStream($body)) + ->withBody($this->getPsr17()->createStream($body)) ->withHeader('Content-Type', 'application/json'); } @@ -152,11 +141,6 @@ protected function getIntrospector(): IntrospectorInterface return $this->introspector; } - protected function getRequestFactory(): RequestFactoryInterface - { - return $this->requestFactory; - } - /** * Get the URI. */ @@ -258,7 +242,7 @@ private function normalize(RequestInterface $request, ResponseInterface $respons ->debug('Response normalization succeeded.', ['body' => $body]); return $response - ->withBody($this->getStreamFactory()->createStream($body)) + ->withBody($this->getPsr17()->createStream($body)) ->withHeader('Content-Type', 'application/json'); } } diff --git a/tests/Service/ProxyValidate.php b/tests/Service/ProxyValidate.php index 0a86745..01662ff 100644 --- a/tests/Service/ProxyValidate.php +++ b/tests/Service/ProxyValidate.php @@ -16,12 +16,8 @@ use EcPhp\CasLib\Utils\Uri; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; @@ -47,26 +43,6 @@ public function getLogger(): LoggerInterface return parent::getLogger(); } - public function getRequestFactory(): RequestFactoryInterface - { - return parent::getRequestFactory(); - } - - public function getResponseFactory(): ResponseFactoryInterface - { - return parent::getResponseFactory(); - } - - public function getStreamFactory(): StreamFactoryInterface - { - return parent::getStreamFactory(); - } - - public function getUriFactory(): UriFactoryInterface - { - return parent::getUriFactory(); - } - public function parse(RequestInterface $request, ResponseInterface $response): array { return parent::parse($request, $response);