Skip to content

Commit

Permalink
Use Flysystem Bundle 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ipf committed Aug 30, 2021
1 parent 5b35250 commit 9f774bf
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 131 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@
*/Entity/*~
/.php_cs.cache
composer.lock
.phpunit.result.cache
60 changes: 0 additions & 60 deletions EventListener/UrlManipulatorListener.php

This file was deleted.

5 changes: 0 additions & 5 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ services:
Subugoe\IIIFBundle\Service\PresentationService:
arguments: ["@router", "%image%", "%presentation%"]

Subugoe\IIIFBundle\EventListener\UrlManipulatorListener:
arguments: ['%image%', '%presentation%', '@router']
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }

#
# The following definition is an example on how to create the translator
#
Expand Down
16 changes: 8 additions & 8 deletions Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@

namespace Subugoe\IIIFBundle\Service;

use League\Flysystem\FilesystemInterface;
use League\Flysystem\Filesystem;

/**
* Wrapper around cache and source filesystems.
*/
class FileService
{
/**
* @var FilesystemInterface
* @var Filesystem
*/
private $cacheFilesystem;

/**
* @var FilesystemInterface
* @var Filesystem
*/
private $sourceFilesystem;

public function __construct(FilesystemInterface $cacheFilesystem, FilesystemInterface $sourceFilesystem)
public function __construct(Filesystem $cacheFilesystem, Filesystem $sourceFilesystem)
{
$this->cacheFilesystem = $cacheFilesystem;
$this->sourceFilesystem = $sourceFilesystem;
}

/**
* @return FilesystemInterface
* @return Filesystem
*/
public function getCacheFilesystem(): FilesystemInterface
public function getCacheFilesystem(): Filesystem
{
return $this->cacheFilesystem;
}

/**
* @return FilesystemInterface
* @return Filesystem
*/
public function getSourceFilesystem(): FilesystemInterface
public function getSourceFilesystem(): Filesystem
{
return $this->sourceFilesystem;
}
Expand Down
20 changes: 10 additions & 10 deletions Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ public function getOriginalFileContents(\Subugoe\IIIFModel\Model\Image\Image $im
$originalImageCacheFile = sprintf('/orig/%s.%s', $image->getIdentifier(), $document->getImageFormat());

if ($this->imageConfiguration['originals_caching']) {
if (!$cacheFilesystem->has($originalImageCacheFile)) {
if (!$cacheFilesystem->fileExists($originalImageCacheFile)) {
$sourceImage = $sourceFilesystem->read($filename);
$cacheFilesystem->write($originalImageCacheFile, $sourceImage);
}
}

if ($cacheFilesystem->has($originalImageCacheFile)) {
if ($cacheFilesystem->fileExists($originalImageCacheFile)) {
return $cacheFilesystem->read($originalImageCacheFile);
}

if (!$sourceFilesystem->has($filename)) {
if (!$sourceFilesystem->fileExists($filename)) {
return false;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ private function getRegion(string $region, ImageInterface $image): ImageInterfac

if ('square' === $region) {
$regionSort = 'squareBased';
} elseif (strstr($region, 'pct')) {
} elseif (strpos($region, 'pct') !== false) {
$regionSort = 'percentageBased';
} else {
$regionSort = 'pixelBased';
Expand Down Expand Up @@ -315,19 +315,19 @@ private function getSize(string $size, ImageInterface $image): ImageInterface
}

$rawSize = $size;
if (strstr($size, '!')) {
if (strpos($size, '!') !== false) {
$size = str_replace('!', '', $size);
}
$regionWidth = $image->getSize()->getWidth();
$regionHeight = $image->getSize()->getHeight();
if (!strstr($size, 'pct')) {
if (strpos($size, 'pct') === false) {
$requestedSize = explode(',', $size);
if (2 != count($requestedSize)) {
throw new BadRequestHttpException(sprintf('Bad Request: Size syntax %s is not valid.', $size));
}
$width = $requestedSize[0];
$height = $requestedSize[1];
if (strstr($rawSize, '!')) {
if (strpos($rawSize, '!') !== false) {
$w = (($regionWidth / $regionHeight) * $height);
$h = (($regionHeight / $regionWidth) * $width);
} else {
Expand All @@ -343,7 +343,7 @@ private function getSize(string $size, ImageInterface $image): ImageInterface
}
}
$image->resize(new Box($w, $h));
} elseif (strstr($size, 'pct')) {
} elseif (strpos($size, 'pct') !== false) {
$requestedPercentage = explode(':', $size)[1];
if (is_numeric($requestedPercentage)) {
$w = (($regionWidth * $requestedPercentage) / 100);
Expand Down Expand Up @@ -380,8 +380,8 @@ private function getRotation(string $rotation, ImageInterface $image): ImageInte

if (isset($rotation) && !empty($rotation)) {
$rotationDegree = str_replace('!', '', $rotation);
if (intval($rotationDegree) <= 360) {
if (strstr($rotation, '!')) {
if ((int)$rotationDegree <= 360) {
if (strpos($rotation, '!') !== false) {
$image->flipVertically();
}
$image->rotate(str_replace('!', '', $rotation));
Expand Down
8 changes: 5 additions & 3 deletions Service/PresentationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ private function setRoutingContext(string $type): RequestContext
->setScheme($urlParts['scheme']);

return $context;
} elseif (array_key_exists('host', $this->presentationConfiguration['http']) && $type === static::CONTEXT_MANIFESTS) {
}

if (array_key_exists('host', $this->presentationConfiguration['http']) && $type === static::CONTEXT_MANIFESTS) {
$context = new RequestContext();

$url = sprintf('%s://%s', $this->presentationConfiguration['http']['scheme'], $this->presentationConfiguration['http']['host']);
Expand All @@ -345,9 +347,9 @@ private function setRoutingContext(string $type): RequestContext
$context->setScheme($urlParts['scheme']);

return $context;
} else {
return $this->router->getContext();
}

return $this->router->getContext();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/DocumentTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\Subugoe\IIIFBundle\Model;
namespace Subugoe\IIIFBundle\Tests\Model;

use PHPUnit\Framework\TestCase;
use Subugoe\IIIFModel\Model\Document;
Expand All @@ -12,7 +12,7 @@ class DocumentTest extends TestCase
*/
private $document;

public function setUp()
protected function setUp(): void
{
$this->document = new Document();
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/Image/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace tests\Subugoe\IIIFModel\Model\Image;
namespace Subugoe\IIIFModel\Tests\Model;

use PHPUnit\Framework\TestCase;
use Subugoe\IIIFModel\Model\Image\Image;
Expand All @@ -14,7 +14,7 @@ class ImageTest extends TestCase
*/
protected $fixture;

public function setUp()
protected function setUp(): void
{
$this->fixture = new Image();
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/LogicalStructureTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\Subugoe\IIIFBundle\Model;
namespace Subugoe\IIIFBundle\Tests\Model;

use PHPUnit\Framework\TestCase;
use Subugoe\IIIFModel\Model\LogicalStructure;
Expand All @@ -15,7 +15,7 @@ class LogicalStructureTest extends TestCase
*/
private $logicalStructure;

public function setUp()
protected function setUp(): void
{
$this->logicalStructure = new LogicalStructure();
}
Expand Down
15 changes: 7 additions & 8 deletions Tests/Service/FileServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

namespace Subugoe\IIIFBundle\Tests;
namespace Subugoe\IIIFBundle\Tests\Service;

use League\Flysystem\Adapter\NullAdapter;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use PHPUnit\Framework\TestCase;
use Subugoe\IIIFBundle\Service\FileService;

Expand All @@ -15,17 +14,17 @@ class FileServiceTest extends TestCase
*/
protected $fileService;

public function setUp()
protected function setUp(): void
{
$cache = new Filesystem(new NullAdapter());
$cache = new Filesystem(new InMemoryFilesystemAdapter());
$source = clone $cache;

$this->fileService = new FileService($cache, $source);
}

public function testRetrievalOfCacheFilesystemReturnsFilesystemInterface()
public function testRetrievalOfCacheFilesystemReturnsFilesystem()
{
$this->assertInstanceOf(FilesystemInterface::class, $this->fileService->getCacheFilesystem());
$this->assertInstanceOf(FilesystemInterface::class, $this->fileService->getSourceFilesystem());
$this->assertInstanceOf(Filesystem::class, $this->fileService->getCacheFilesystem());
$this->assertInstanceOf(Filesystem::class, $this->fileService->getSourceFilesystem());
}
}
8 changes: 4 additions & 4 deletions Tests/Service/ImageServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Subugoe\IIIFBundle\Tests;
namespace Subugoe\IIIFBundle\Tests\Service;

use PHPUnit\Framework\TestCase;
use Subugoe\IIIFModel\Model\Image\Image;
Expand All @@ -13,12 +13,12 @@ class ImageServiceTest extends TestCase
*/
protected $imageService;

public function setUp()
protected function setUp(): void
{
$imageService = $this
->getMockBuilder(ImageService::class)
->disableOriginalConstructor()
->setMethods(['getImageHash'])
->onlyMethods(['getImageHash'])
->getMock();

$this->imageService = $imageService;
Expand All @@ -30,6 +30,6 @@ public function testIdentifierCalculation()
$image->setFormat('jpg');
$identifier = $this->imageService->getCachedFileIdentifier($image);

$this->assertSame('a/7ece429f5899ac0466fe0cb626a6f394e1c83fb2099cea96d0d9ad68a77ec3ec.jpg', $identifier);
$this->assertSame('a/9bbf4fcfccd6f56f1c01728cacee96e01da5379855d85da9a19d759a79349a49.jpg', $identifier);
}
}
9 changes: 5 additions & 4 deletions Tests/Service/PresentationServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Subugoe\IIIFBundle\Tests;
namespace Subugoe\IIIFBundle\Tests\Service;

use PHPUnit\Framework\TestCase;
use Subugoe\IIIFBundle\Service\PresentationService;
Expand All @@ -20,7 +20,7 @@ class PresentationServiceTest extends TestCase
*/
private $translator;

public function setUp()
protected function setUp(): void
{
$router = $this->getRouterMock();
$this->translator = new TranslatorMock();
Expand Down Expand Up @@ -135,12 +135,13 @@ protected function getRouterMock()
{
$mock = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->setMethods(['generate', 'supports', 'exists'])
->addMethods(['supports', 'exists'])
->onlyMethods(['generate'])
->getMockForAbstractClass();

$mock->expects($this->any())
->method('generate')
->will($this->returnValue('https://gdz.sub.uni-goettingen.de'));
->willReturn('https://gdz.sub.uni-goettingen.de');

return $mock;
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/Translator/TranslatorMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Subugoe\IIIFBundle\Tests\Translator;

use Subugoe\IIIFModel\Model\Document;
use Subugoe\IIIFModel\Model\DocumentInterface;
use Subugoe\IIIFModel\Model\DocumentTypes;
use Subugoe\IIIFModel\Model\LogicalStructure;
use Subugoe\IIIFModel\Model\PhysicalStructure;
Expand Down Expand Up @@ -8317,4 +8318,9 @@ private function getMetadata(): array

return $metadata;
}

public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface
{
// TODO: Implement getDocumentBy() method.
}
}
Loading

0 comments on commit 9f774bf

Please sign in to comment.