From 8606a96662791b9c3ceea9d201131c63130754ba Mon Sep 17 00:00:00 2001 From: ezoller Date: Thu, 17 Dec 2020 17:01:07 +0000 Subject: [PATCH] fixes for new classes in newer version of guzzlehttp but still needing to support old methods --- src/Flysystem/Adapter/FedoraAdapter.php | 15 ++++++++++++--- src/GeminiLookup.php | 8 ++++++-- tests/src/Kernel/FedoraAdapterTest.php | 22 ++++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 3fbfa8ab..04aa8102 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -7,7 +7,6 @@ use League\Flysystem\AdapterInterface; use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait; use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait; use League\Flysystem\Config; -use GuzzleHttp\Psr7\Header; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\StreamWrapper; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; @@ -144,7 +143,12 @@ class FedoraAdapter implements AdapterInterface { // NonRDFSource's are considered files. Everything else is a // directory. $type = 'dir'; - $links = Header::parse($response->getHeader('Link')); + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $links = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + } + else { + $links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + } foreach ($links as $link) { if ($link['rel'] == 'type' && $link[0] == '') { $type = 'file'; @@ -377,7 +381,12 @@ class FedoraAdapter implements AdapterInterface { $return = NULL; if ($response->getStatusCode() == 410) { $return = FALSE; - $link_headers = Header::parse($response->getHeader('Link')); + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $link_headers = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + } + else { + $link_headers = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + } if ($link_headers) { $tombstones = array_filter($link_headers, function ($o) { return (isset($o['rel']) && $o['rel'] == 'hasTombstone'); diff --git a/src/GeminiLookup.php b/src/GeminiLookup.php index e753c88c..435a0d76 100644 --- a/src/GeminiLookup.php +++ b/src/GeminiLookup.php @@ -5,7 +5,6 @@ namespace Drupal\islandora; use Drupal\Core\Entity\EntityInterface; use Drupal\islandora\MediaSource\MediaSourceService; use Drupal\jwt\Authentication\Provider\JwtAuth; -use GuzzleHttp\Psr7\Header; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Islandora\Crayfish\Commons\Client\GeminiClient; @@ -136,7 +135,12 @@ class GeminiLookup { $urls['fedora'], ['allow_redirects' => FALSE, 'headers' => ['Authorization' => $token]] ); - $links = Header::parse($head->getHeader("Link")); + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $links = \GuzzleHttp\Psr7\Header::parse($head->getHeader('Link')); + } + else { + $links = \GuzzleHttp\Psr7\parse_header($head->getHeader('Link')); + } foreach ($links as $link) { if ($link['rel'] == 'describedby') { return trim($link[0], '<>'); diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index 1f5dde3a..becf5bfb 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\islandora\Kernel; use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; -use GuzzleHttp\Psr7\Utils; use GuzzleHttp\Psr7\Response; use Islandora\Chullo\IFedoraApi; use League\Flysystem\Config; @@ -52,7 +51,12 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(Utils::streamFor("DERP")); + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + } + else { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + } $response = $prophecy->reveal(); $prophecy = $this->prophesize(IFedoraApi::class); @@ -118,7 +122,12 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(Utils::streamFor("DERP")); + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + } + else { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + } $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); @@ -610,7 +619,12 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(Utils::streamFor("DERP")); + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + } + else { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + } $response = $prophecy->reveal(); $fedora_prophecy = $this->prophesize(IFedoraApi::class);