Skip to content

Commit

Permalink
Merge pull request #336 from CPS-IT/0.8/typo3-v12
Browse files Browse the repository at this point in the history
[!!!][FEATURE] Add support for TYPO3 v12 and drop support for v10 and v11
  • Loading branch information
eliashaeussler authored Sep 18, 2024
2 parents 6cb5515 + b780e72 commit ac63943
Show file tree
Hide file tree
Showing 45 changed files with 2,035 additions and 2,270 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cgl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
composer-options: --no-plugins
composer-options: --no-scripts --no-plugins

# Check Composer dependencies
- name: Check dependencies
Expand All @@ -45,11 +45,11 @@ jobs:

# Linting
- name: Lint composer.json
run: composer lint:composer -- --dry-run
run: composer lint:composer
- name: Lint Editorconfig
run: .Build/bin/ec -e .Build
run: composer lint:editorconfig
- name: Lint PHP
run: composer lint:php -- --dry-run
run: composer lint:php
- name: Lint TypoScript
run: composer lint:typoscript -- --fail-on-warnings

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
extensions: intl, mbstring, json, zip, curl
tools: composer:v2
coverage: none
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3-version: ["10.4", "11.5"]
php-version: ["7.4", "8.0", "8.1", "8.2", "8.3"]
typo3-version: ["12.4"]
php-version: ["8.1", "8.2", "8.3"]
dependencies: ["highest", "lowest"]
exclude:
- typo3-version: "10.4"
php-version: "8.0"
- typo3-version: "10.4"
php-version: "8.1"
- typo3-version: "10.4"
php-version: "8.2"
- typo3-version: "10.4"
php-version: "8.3"
steps:
- uses: actions/checkout@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.Build/
/.Build
/config
/Resources/Private/Libs/Build/vendor
/Resources/Private/Libs/vendors.phar
/var/
/var
/.php-cs-fixer.cache
/.phpunit.result.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS extension "handlebars".
*
* Copyright (C) 2024 Elias Häußler <e.haeussler@familie-redlich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->setParallelConfig(\PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());

Expand Down
12 changes: 3 additions & 9 deletions Classes/Cache/HandlebarsCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@
*/
class HandlebarsCache implements CacheInterface
{
/**
* @var FrontendInterface
*/
protected $cache;

public function __construct(FrontendInterface $cache)
{
$this->cache = $cache;
}
public function __construct(
protected readonly FrontendInterface $cache,
) {}

public function get(string $template): ?string
{
Expand Down
66 changes: 34 additions & 32 deletions Classes/Compatibility/View/ExtbaseViewAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,27 @@
namespace Fr\Typo3Handlebars\Compatibility\View;

use Fr\Typo3Handlebars\DataProcessing\DataProcessorInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\CMS\Fluid\View\AbstractTemplateView;

/**
* ExtbaseViewAdapter
*
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-2.0-or-later
*/
class ExtbaseViewAdapter implements ViewInterface
class ExtbaseViewAdapter extends AbstractTemplateView
{
/**
* @var ControllerContext
*/
protected $controllerContext;

/**
* @var DataProcessorInterface
*/
protected $processor;

/**
* @var array<string, mixed>
*/
protected $renderData = [];
protected array $renderData = [];

public function __construct(DataProcessorInterface $processor)
{
$this->processor = $processor;
}

public function setControllerContext(ControllerContext $controllerContext): void
{
$this->controllerContext = $controllerContext;
public function __construct(
protected readonly DataProcessorInterface $processor,
) {
parent::__construct();
}

public function assign($key, $value): self
Expand All @@ -78,27 +65,42 @@ public function assignMultiple(array $values): self
return $this;
}

public function canRender(ControllerContext $controllerContext): bool
public function render($actionName = null): string
{
return true;
}
$renderingContext = $this->getRenderingContext();
$controller = null;
$request = null;

public function render(): string
{
$request = $this->controllerContext->getRequest();
if ($renderingContext instanceof RenderingContext) {
$request = $renderingContext->getRequest();
}
if ($request instanceof Request) {
$controller = $request->getControllerObjectName();
}

return $this->processor->process('', [
'extbaseViewConfiguration' => [
'controller' => $request->getControllerObjectName(),
'action' => $request->getControllerActionName(),
'controller' => $controller,
'action' => $actionName,
'request' => $request,
'variables' => $this->renderData,
],
]);
}

public function initializeView(): void
/**
* @param array<string, mixed> $variables
*/
public function renderSection($sectionName, array $variables = [], $ignoreUnknown = false): string
{
return '';
}

/**
* @param array<string, mixed> $variables
*/
public function renderPartial($partialName, $sectionName = null, array $variables = [], $ignoreUnknown = false): string
{
// Intentionally left blank.
return '';
}
}
27 changes: 11 additions & 16 deletions Classes/Compatibility/View/HandlebarsViewResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
namespace Fr\Typo3Handlebars\Compatibility\View;

use Fr\Typo3Handlebars\DataProcessing\DataProcessorInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\View\GenericViewResolver;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3Fluid\Fluid\View\ViewInterface;

/**
* HandlebarsViewResolver
Expand All @@ -38,19 +38,9 @@
class HandlebarsViewResolver extends GenericViewResolver
{
/**
* @var array<string, array<string, DataProcessorInterface>>
* @var array<class-string, array<string, DataProcessorInterface>>
*/
protected $processorMap = [];

/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;

public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
{
$this->configurationManager = $configurationManager;
}
protected array $processorMap = [];

public function resolve(string $controllerObjectName, string $actionName, string $format): ViewInterface
{
Expand Down Expand Up @@ -86,7 +76,7 @@ protected function getProcessor(string $controllerClassName, string $actionName)
return null;
}

$contentObjectRenderer = $this->configurationManager->getContentObject();
$contentObjectRenderer = $this->getRequest()->getAttribute('currentContentObject');
if ($contentObjectRenderer !== null && method_exists($processor, 'setContentObjectRenderer')) {
$processor->setContentObjectRenderer($contentObjectRenderer);
}
Expand All @@ -95,11 +85,16 @@ protected function getProcessor(string $controllerClassName, string $actionName)
}

/**
* @param array<string, array<string, DataProcessorInterface>> $processorMap
* @param array<class-string, array<string, DataProcessorInterface>> $processorMap
*/
public function setProcessorMap(array $processorMap): self
{
$this->processorMap = $processorMap;
return $this;
}

protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
17 changes: 5 additions & 12 deletions Classes/Data/Response/SimpleProviderResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,27 @@
*/
class SimpleProviderResponse implements ProviderResponseInterface, \ArrayAccess
{
/**
* @var array<string, mixed>
*/
protected $data;

/**
* @param array<string, mixed> $data
*/
public function __construct(array $data = [])
{
$this->data = $data;
}
public function __construct(
protected array $data = [],
) {}

public function offsetExists($offset): bool
{
return \array_key_exists($offset, $this->data);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
if ($this->offsetExists($offset)) {
return $this->data[$offset];
}
return null;
}

public function offsetSet($offset, $value): void
public function offsetSet($offset, mixed $value): void
{
$this->data[$offset] = $value;
}
Expand Down
39 changes: 10 additions & 29 deletions Classes/DataProcessing/AbstractDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,16 @@ abstract class AbstractDataProcessor implements DataProcessorInterface, LoggerAw
use ErrorHandlingTrait;
use LoggerAwareTrait;

/**
* @var ContentObjectRenderer
*/
public $cObj;

/**
* @var string
*/
protected $content;
protected ?ConfigurationManagerInterface $configurationManager = null;
protected ?ContentObjectRenderer $contentObjectRenderer = null;
protected ?PresenterInterface $presenter = null;
protected ?DataProviderInterface $provider = null;
protected string $content = '';

/**
* @var array<string|int, mixed>
*/
protected $configuration;

/**
* @var PresenterInterface
*/
protected $presenter;

/**
* @var DataProviderInterface
*/
protected $provider;

/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;
protected array $configuration = [];

/**
* @todo Move to constructor with next BC break
Expand Down Expand Up @@ -113,9 +94,9 @@ public function setProvider(DataProviderInterface $provider): DataProcessorInter
return $this;
}

public function setContentObjectRenderer(ContentObjectRenderer $cObj): self
public function setContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer): self
{
$this->cObj = $cObj;
$this->contentObjectRenderer = $contentObjectRenderer;
return $this;
}

Expand All @@ -132,13 +113,13 @@ public function setContentObjectRenderer(ContentObjectRenderer $cObj): self
*/
protected function initializeConfigurationManager(): void
{
if ($this->configurationManager !== null && $this->cObj !== null) {
if ($this->configurationManager !== null && $this->contentObjectRenderer !== null) {
$fullConfiguration = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
// setConfiguration() resets extensionName and pluginName
$this->configurationManager->setConfiguration($fullConfiguration);
$this->configurationManager->setContentObject($this->cObj);
$this->configurationManager->setContentObject($this->contentObjectRenderer);
}
}

Expand Down
Loading

0 comments on commit ac63943

Please sign in to comment.