Browse Source

fixes for new classes in newer version of guzzlehttp but still needing to support old methods

d9_islandora
ezoller 4 years ago
parent
commit
8606a96662
  1. 15
      src/Flysystem/Adapter/FedoraAdapter.php
  2. 8
      src/GeminiLookup.php
  3. 22
      tests/src/Kernel/FedoraAdapterTest.php

15
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] == '<http://www.w3.org/ns/ldp#NonRDFSource>') {
$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');

8
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], '<>');

22
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);

Loading…
Cancel
Save