-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Extract request processing from IconFactory
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>
- Loading branch information
Showing
3 changed files
with
66 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters