[TASK] Extract request processing from IconFactory 21/56321/4
authorMathias Brodala <mbrodala@pagemachine.de>
Sat, 17 Mar 2018 15:58:26 +0000 (16:58 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Mar 2018 17:11:48 +0000 (18:11 +0100)
Change-Id: If23a7a356e62a17dad4f22a746c365ef094999da
Resolves: #84408
Releases: master
Reviewed-on: https://review.typo3.org/56321
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php
typo3/sysext/core/Classes/Controller/IconController.php [new file with mode: 0644]
typo3/sysext/core/Classes/Imaging/IconFactory.php

index b9ac917..7cc756d 100644 (file)
@@ -219,7 +219,7 @@ return [
     // Get icon from IconFactory
     'icons' => [
         'path' => '/icons',
-        'target' => \TYPO3\CMS\Core\Imaging\IconFactory::class . '::processAjaxRequest'
+        'target' => \TYPO3\CMS\Core\Controller\IconController::class . '::getIcon'
     ],
 
     // Encode typolink parts on demand
diff --git a/typo3/sysext/core/Classes/Controller/IconController.php b/typo3/sysext/core/Classes/Controller/IconController.php
new file mode 100644 (file)
index 0000000..acdc1eb
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Controller;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Type\Icon\IconState;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Controller for icon handling
+ */
+class IconController
+{
+    /**
+     * @var IconFactory
+     */
+    protected $iconFactory;
+
+    /**
+     * Set up dependencies
+     */
+    public function __construct()
+    {
+        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+    }
+
+    /**
+     * @param ServerRequestInterface $request
+     * @return ResponseInterface
+     * @internal
+     */
+    public function getIcon(ServerRequestInterface $request): ResponseInterface
+    {
+        $parsedBody = $request->getParsedBody();
+        $queryParams = $request->getQueryParams();
+        $requestedIcon = json_decode($parsedBody['icon'] ?? $queryParams['icon'], true);
+
+        list($identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier) = $requestedIcon;
+
+        if (empty($overlayIdentifier)) {
+            $overlayIdentifier = null;
+        }
+
+        $iconState = IconState::cast($iconState);
+        $icon = $this->iconFactory->getIcon($identifier, $size, $overlayIdentifier, $iconState);
+
+        return new HtmlResponse($icon->render($alternativeMarkupIdentifier));
+    }
+}
index 6416893..f9b6574 100644 (file)
@@ -14,9 +14,6 @@ namespace TYPO3\CMS\Core\Imaging;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\Resource\InaccessibleFolder;
@@ -71,28 +68,6 @@ class IconFactory
     }
 
     /**
-     * @param ServerRequestInterface $request
-     * @return ResponseInterface
-     * @internal
-     */
-    public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface
-    {
-        $parsedBody = $request->getParsedBody();
-        $queryParams = $request->getQueryParams();
-        $requestedIcon = json_decode(
-            $parsedBody['icon'] ?? $queryParams['icon'],
-            true
-        );
-
-        list($identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier) = $requestedIcon;
-        if (empty($overlayIdentifier)) {
-            $overlayIdentifier = null;
-        }
-        $iconState = IconState::cast($iconState);
-        return new HtmlResponse($this->getIcon($identifier, $size, $overlayIdentifier, $iconState)->render($alternativeMarkupIdentifier));
-    }
-
-    /**
      * @param string $identifier
      * @param string $size "large", "small" or "default", see the constants of the Icon class
      * @param string $overlayIdentifier