Skip to content

Commit

Permalink
[FEATURE] Introduce ResourceFactory proxy
Browse files Browse the repository at this point in the history
Necessary because of upcoming core changes that make the
class final.
  • Loading branch information
NamelessCoder committed Jan 23, 2025
1 parent c1b468a commit 5030838
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Classes/Form/Transformation/Transformer/FileTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use FluidTYPO3\Flux\Form\FormInterface;
use FluidTYPO3\Flux\Form\OptionCarryingInterface;
use FluidTYPO3\Flux\Form\Transformation\DataTransformerInterface;
use FluidTYPO3\Flux\Proxy\ResourceFactoryProxy;
use FluidTYPO3\Flux\Utility\DoctrineQueryProxy;
use FluidTYPO3\Flux\Utility\ExtensionConfigurationUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ResourceFactory;

/**
* File Transformer
Expand All @@ -30,9 +30,9 @@
class FileTransformer implements DataTransformerInterface
{
private ConnectionPool $connectionPool;
private ResourceFactory $resourceFactory;
private ResourceFactoryProxy $resourceFactory;

public function __construct(ConnectionPool $connectionPool, ResourceFactory $resourceFactory)
public function __construct(ConnectionPool $connectionPool, ResourceFactoryProxy $resourceFactory)
{
$this->connectionPool = $connectionPool;
$this->resourceFactory = $resourceFactory;
Expand Down
32 changes: 32 additions & 0 deletions Classes/Proxy/ResourceFactoryProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ResourceFactory;

/**
* Final/readonly class is unnecessary coercion - and using it in shared libraries is arrogant and very disrespectful.
*
* @codeCoverageIgnore
*/
class ResourceFactoryProxy
{
private ResourceFactory $resourceFactory;

public function __construct(ResourceFactory $resourceFactory)
{
$this->resourceFactory = $resourceFactory;
}

public function getFileReferenceObject(int $uid): FileReference
{
return $this->resourceFactory->getFileReferenceObject($uid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Transformation\Transformer\FileTransformer;
use FluidTYPO3\Flux\Proxy\ResourceFactoryProxy;
use FluidTYPO3\Flux\Tests\Mock\QueryBuilder;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;

class FileTransformerTest extends AbstractTestCase
{
private ConnectionPool $connectionPool;
private ResourceFactory $resourceFactory;
private ResourceFactoryProxy $resourceFactory;
private FileTransformer $subject;

protected function setUp(): void
Expand All @@ -35,7 +35,7 @@ protected function setUp(): void
->disableOriginalConstructor()
->getMock();

$this->resourceFactory = $this->getMockBuilder(ResourceFactory::class)
$this->resourceFactory = $this->getMockBuilder(ResourceFactoryProxy::class)
->onlyMethods(['getFileReferenceObject'])
->disableOriginalConstructor()
->getMock();
Expand Down

0 comments on commit 5030838

Please sign in to comment.