Skip to content

Commit

Permalink
feat!: move processImage to FilesService and make output configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Sep 4, 2024
1 parent ff443b4 commit 9233f2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 15 additions & 0 deletions Classes/Service/FilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;

class FilesService
{
private FileRepository $fileRepository;

private FileUtility $fileUtility;

private ImageService $imageService;

/** @var mixed[] $defaultConfiguration */
private array $defaultConfiguration;

Expand All @@ -29,6 +32,18 @@ public function __construct()
$this->defaultConfiguration = $fullTypoScript ? $fullTypoScript['lib.']['assetProcessingConfiguration.'] : [];
$this->fileUtility = GeneralUtility::makeInstance(FileUtility::class);
$this->fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$this->imageService = GeneralUtility::makeInstance(ImageService::class);
}

/**
* @param mixed[] $configuration
* @return mixed[]
*/
public function processImage(int $uid, array $configuration = []): array
{
$processingConfiguration = $this->getProcessingConfiguration($configuration);
$imageObj = $this->imageService->getImage(strval($uid), null, true);
return $this->fileUtility->process($imageObj, $processingConfiguration);
}

/**
Expand Down
14 changes: 0 additions & 14 deletions Classes/Service/JsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@

namespace Remind\Headless\Service;

use FriendsOfTYPO3\Headless\Utility\FileUtility;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Pagination\PaginationInterface;
use TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Service\ImageService;

class JsonService
{
public function __construct(
private readonly UriBuilder $uriBuilder,
private readonly ImageService $imageService,
private readonly FileUtility $fileUtility,
RequestBuilder $requestBuilder,
) {
$extbaseRequest = $requestBuilder->build($this->getRequest());
Expand Down Expand Up @@ -91,16 +87,6 @@ public function serializePagination(PaginationInterface $pagination, string $que
return $result;
}

/**
* TODO: make output configurable, move to FilesService
* @return mixed[]
*/
public function processImage(int $uid): array
{
$imageObj = $this->imageService->getImage(strval($uid), null, true);
return $this->fileUtility->processFile($imageObj);
}

private function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
Expand Down

0 comments on commit 9233f2d

Please sign in to comment.