From 5c0fb04f681f7693d270501e2b007bfb1941cb86 Mon Sep 17 00:00:00 2001
From: Daniel Berthereau <Daniel.github@Berthereau.net>
Date: Mon, 20 Apr 2020 00:00:00 +0200
Subject: [PATCH] Added the ImageSize plugin.

---
 config/module.config.php                         |  1 +
 src/Mvc/Controller/Plugin/ImageSize.php          |  4 ++--
 .../ControllerPlugin/ImageSizeFactory.php        | 16 ++++++++++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 src/Service/ControllerPlugin/ImageSizeFactory.php

diff --git a/config/module.config.php b/config/module.config.php
index 6e1633b..4b5324d 100644
--- a/config/module.config.php
+++ b/config/module.config.php
@@ -38,6 +38,7 @@
             'tileServer' => Mvc\Controller\Plugin\TileServer::class,
         ],
         'factories' => [
+            'imageSize' => Service\ControllerPlugin\ImageSizeFactory::class,
             'tiler' => Service\ControllerPlugin\TilerFactory::class,
         ],
     ],
diff --git a/src/Mvc/Controller/Plugin/ImageSize.php b/src/Mvc/Controller/Plugin/ImageSize.php
index 18b9cf9..42e8eb9 100644
--- a/src/Mvc/Controller/Plugin/ImageSize.php
+++ b/src/Mvc/Controller/Plugin/ImageSize.php
@@ -1,12 +1,12 @@
 <?php
 namespace ImageServer\Mvc\Controller\Plugin;
 
+use Omeka\Api\Representation\AssetRepresentation;
+use Omeka\Api\Representation\MediaRepresentation;
 use Omeka\File\TempFileFactory;
 use Omeka\Mvc\Exception\RuntimeException;
 use Omeka\Stdlib\Message;
 use Zend\Mvc\Controller\Plugin\AbstractPlugin;
-use Omeka\Api\Representation\MediaRepresentation;
-use Omeka\Api\Representation\AssetRepresentation;
 
 class ImageSize extends AbstractPlugin
 {
diff --git a/src/Service/ControllerPlugin/ImageSizeFactory.php b/src/Service/ControllerPlugin/ImageSizeFactory.php
new file mode 100644
index 0000000..fd46277
--- /dev/null
+++ b/src/Service/ControllerPlugin/ImageSizeFactory.php
@@ -0,0 +1,16 @@
+<?php
+namespace ImageServer\Service\ControllerPlugin;
+
+use ImageServer\Mvc\Controller\Plugin\ImageSize;
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+class ImageSizeFactory implements FactoryInterface
+{
+    public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
+    {
+        $basePath = $services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files');
+        $tempFileFactory = $services->get('Omeka\File\TempFileFactory');
+        return new ImageSize($basePath, $tempFileFactory);
+    }
+}