‪TYPO3CMS  10.4
IconController.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
27 
34 {
38  protected ‪$iconRegistry;
39 
43  protected ‪$iconFactory;
44 
48  public function ‪__construct()
49  {
50  $this->iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
51  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52  }
53 
58  public function ‪getCacheIdentifier(): ResponseInterface
59  {
60  return new ‪HtmlResponse($this->iconRegistry->getCacheIdentifier());
61  }
62 
68  public function ‪getIcon(ServerRequestInterface $request): ResponseInterface
69  {
70  $parsedBody = $request->getParsedBody();
71  $queryParams = $request->getQueryParams();
72  $requestedIcon = json_decode($parsedBody['icon'] ?? $queryParams['icon'], true);
73 
74  [$identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier] = $requestedIcon;
75 
76  if (empty($overlayIdentifier)) {
77  $overlayIdentifier = null;
78  }
79 
80  $iconState = ‪IconState::cast($iconState);
81  $icon = $this->iconFactory->getIcon($identifier, $size, $overlayIdentifier, $iconState);
82 
83  return new ‪HtmlResponse($icon->render($alternativeMarkupIdentifier));
84  }
85 }
‪TYPO3\CMS\Core\Controller\IconController\getCacheIdentifier
‪ResponseInterface getCacheIdentifier()
Definition: IconController.php:56
‪TYPO3\CMS\Core\Controller\IconController\$iconFactory
‪IconFactory $iconFactory
Definition: IconController.php:41
‪TYPO3\CMS\Core\Controller
Definition: ErrorPageController.php:18
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Controller\IconController\getIcon
‪ResponseInterface getIcon(ServerRequestInterface $request)
Definition: IconController.php:66
‪TYPO3\CMS\Core\Controller\IconController
Definition: IconController.php:34
‪TYPO3\CMS\Core\Controller\IconController\$iconRegistry
‪IconRegistry $iconRegistry
Definition: IconController.php:37
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:38
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Controller\IconController\__construct
‪__construct()
Definition: IconController.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26