‪TYPO3CMS  9.5
IconController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
25 
32 {
36  protected ‪$iconRegistry;
37 
41  protected ‪$iconFactory;
42 
46  public function ‪__construct()
47  {
48  $this->iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
49  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
50  }
51 
56  public function ‪getCacheIdentifier(): ResponseInterface
57  {
58  return new ‪HtmlResponse($this->iconRegistry->getCacheIdentifier());
59  }
60 
66  public function ‪getIcon(ServerRequestInterface $request): ResponseInterface
67  {
68  $parsedBody = $request->getParsedBody();
69  $queryParams = $request->getQueryParams();
70  $requestedIcon = json_decode($parsedBody['icon'] ?? $queryParams['icon'], true);
71 
72  list($identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier) = $requestedIcon;
73 
74  if (empty($overlayIdentifier)) {
75  $overlayIdentifier = null;
76  }
77 
78  $iconState = ‪IconState::cast($iconState);
79  $icon = $this->iconFactory->getIcon($identifier, $size, $overlayIdentifier, $iconState);
80 
81  return new ‪HtmlResponse($icon->render($alternativeMarkupIdentifier));
82  }
83 }
‪TYPO3\CMS\Core\Controller\IconController\getCacheIdentifier
‪ResponseInterface getCacheIdentifier()
Definition: IconController.php:54
‪TYPO3\CMS\Core\Controller\IconController\$iconFactory
‪IconFactory $iconFactory
Definition: IconController.php:39
‪TYPO3\CMS\Core\Controller
Definition: ErrorPageController.php:3
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Core\Controller\IconController\getIcon
‪ResponseInterface getIcon(ServerRequestInterface $request)
Definition: IconController.php:64
‪TYPO3\CMS\Core\Controller\IconController
Definition: IconController.php:32
‪TYPO3\CMS\Core\Controller\IconController\$iconRegistry
‪IconRegistry $iconRegistry
Definition: IconController.php:35
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:34
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:23
‪TYPO3\CMS\Core\Controller\IconController\__construct
‪__construct()
Definition: IconController.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25