Skip to content

Commit

Permalink
[FEATURE] Introduce IconFactory proxy
Browse files Browse the repository at this point in the history
Necessary because of upcoming changes in core which makes this class final.
  • Loading branch information
NamelessCoder committed Jan 23, 2025
1 parent 3a426a8 commit eddaa81
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Classes/Integration/HookSubscribers/ContentIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use FluidTYPO3\Flux\Hooks\HookHandler;
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface;
use FluidTYPO3\Flux\Provider\ProviderResolver;
use FluidTYPO3\Flux\Proxy\IconFactoryProxy;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;

Expand All @@ -38,12 +38,12 @@ class ContentIcon
];

protected ProviderResolver $providerResolver;
protected IconFactory $iconFactory;
protected IconFactoryProxy $iconFactory;
protected FrontendInterface $cache;

public function __construct(
ProviderResolver $providerResolver,
IconFactory $iconFactory,
IconFactoryProxy $iconFactory,
CacheManager $cacheManager
) {
$this->providerResolver = $providerResolver;
Expand Down
42 changes: 42 additions & 0 deletions Classes/Proxy/IconFactoryProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace FluidTYPO3\Flux\Proxy;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Imaging\IconState;

/**
* Final/readonly classes is a great way to give all your developer community users the middle finger.
*
* @codeCoverageIgnore
*/
class IconFactoryProxy
{
private IconFactory $iconFactory;

public function __construct(IconFactory $iconFactory)
{
$this->iconFactory = $iconFactory;
}

/**
* @param string|IconSize $size
* @param \TYPO3\CMS\Core\Type\Icon\IconState|IconState|null $state
*/
public function getIcon(
string $identifier,
$size,
?string $overlayIdentifier = null,
$state = null
): Icon {
return $this->iconFactory->getIcon($identifier, $size, $overlayIdentifier, $state);
}
}
6 changes: 3 additions & 3 deletions Tests/Unit/Integration/HookSubscribers/ContentIconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use FluidTYPO3\Flux\Integration\HookSubscribers\ContentIcon;
use FluidTYPO3\Flux\Provider\ProviderInterface;
use FluidTYPO3\Flux\Provider\ProviderResolver;
use FluidTYPO3\Flux\Proxy\IconFactoryProxy;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Lang\LanguageService;
Expand All @@ -30,15 +30,15 @@ class ContentIconTest extends AbstractTestCase
private ?ProviderResolver $providerResolver;
private ?CacheManager $cacheManager;
private ?FrontendInterface $cache;
private ?IconFactory $iconFactory;
private ?IconFactoryProxy $iconFactory;

protected function setUp(): void
{
$this->cache = $this->createStub(FrontendInterface::class);
$this->providerResolver = $this->createStub(ProviderResolver::class);
$this->cacheManager = $this->createStub(CacheManager::class);
$this->cacheManager->method('getCache')->willReturn($this->cache);
$this->iconFactory = $this->createStub(IconFactory::class);
$this->iconFactory = $this->createStub(IconFactoryProxy::class);

parent::setUp();
}
Expand Down

0 comments on commit eddaa81

Please sign in to comment.