‪TYPO3CMS  ‪main
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;
25 use TYPO3\CMS\Core\Imaging\IconSize;
28 
35 {
39  protected ‪$iconRegistry;
40 
44  protected ‪$iconFactory;
45 
49  public function ‪__construct()
50  {
51  $this->iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
52  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
53  }
54 
58  public function ‪getCacheIdentifier(): ResponseInterface
59  {
60  return new ‪HtmlResponse(sha1($this->iconRegistry->getBackendIconsCacheIdentifier()));
61  }
62 
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  [‪$identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier] = $requestedIcon;
73 
74  if (empty($overlayIdentifier)) {
75  $overlayIdentifier = null;
76  }
77 
78  $iconState = IconState::tryFrom($iconState);
79  $icon = $this->iconFactory->getIcon(‪$identifier, IconSize::from($size), $overlayIdentifier, $iconState);
80 
81  return new ‪HtmlResponse($icon->render($alternativeMarkupIdentifier));
82  }
83 }
‪TYPO3\CMS\Core\Controller\IconController\$iconFactory
‪IconFactory $iconFactory
Definition: IconController.php:42
‪TYPO3\CMS\Core\Controller
Definition: ErrorPageController.php:18
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Controller\IconController\getCacheIdentifier
‪getCacheIdentifier()
Definition: IconController.php:56
‪TYPO3\CMS\Core\Controller\IconController
Definition: IconController.php:35
‪TYPO3\CMS\Core\Controller\IconController\$iconRegistry
‪IconRegistry $iconRegistry
Definition: IconController.php:38
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:32
‪TYPO3\CMS\Core\Controller\IconController\getIcon
‪getIcon(ServerRequestInterface $request)
Definition: IconController.php:64
‪TYPO3\CMS\Core\Imaging\IconState
‪IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Controller\IconController\__construct
‪__construct()
Definition: IconController.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:28