Skip to content

Commit 06b5a3c

Browse files
committed
[FEATURE] Support TYPO3 v12
* Adapt to the new class structure * Adapt to the new image resource rendering
1 parent 96d2435 commit 06b5a3c

24 files changed

+186
-146
lines changed

.github/workflows/php.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ jobs:
1010
- uses: actions/checkout@v2
1111

1212
- name: OSKAR-PHP-CS-Fixer
13-
uses: OskarStark/php-cs-fixer-ga@2.17.3
13+
uses: OskarStark/php-cs-fixer-ga@3.22.0
1414
with:
1515
args: --diff --dry-run
1616

1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: 7.4
20+
php-version: 8.2
2121
tools: composer
2222
extensions: pdo, sqlite3
2323

2424
- name: composer install
2525
run: composer install -n
2626

2727
- name: phpunit
28-
run: .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit
28+
run: .Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/composer.lock
22
/.Build
3-
/.php_cs.cache
43
/.phpunit.result.cache
4+
/.php-cs-fixer.cache
+22-31
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,54 @@
11
<?php
2-
https://github.com/TYPO3/TYPO3.CMS/blob/5d3f7751abf1914d219554ce8e72105944208c77/Build/.php_cs
32

4-
if (PHP_SAPI !== 'cli') {
5-
die('This script supports command line usage only. Please check your command.');
6-
}
7-
// Define in which folders to search and which folders to exclude
8-
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
9-
$finder = PhpCsFixer\Finder::create()
10-
->exclude('vendor')
11-
->exclude('Configuration')
12-
->in(__DIR__);
3+
declare(strict_types=1);
134

14-
// https://github.com/TYPO3/TYPO3.CMS/blob/5d3f7751abf1914d219554ce8e72105944208c77/Build/.php_cs
155
// Return a Code Sniffing configuration using
16-
// all sniffers needed for PSR-2
6+
// all sniffers needed for PER
177
// and additionally:
188
// - Remove leading slashes in use clauses.
199
// - PHP single-line arrays should not have trailing comma.
2010
// - Single-line whitespace before closing semicolon are prohibited.
2111
// - Remove unused use statements in the PHP source code
2212
// - Ensure Concatenation to have at least one whitespace around
2313
// - Remove trailing whitespace at the end of blank lines.
24-
return PhpCsFixer\Config::create()
14+
return (new \PhpCsFixer\Config())
15+
->setFinder(
16+
(new PhpCsFixer\Finder())
17+
->ignoreVCSIgnored(true)
18+
->in(__DIR__)
19+
)
2520
->setRiskyAllowed(true)
2621
->setRules([
2722
'@DoctrineAnnotation' => true,
28-
'@PSR2' => true,
23+
'@PER' => true,
2924
'array_syntax' => ['syntax' => 'short'],
30-
'blank_line_after_opening_tag' => true,
31-
'braces' => ['allow_single_line_closure' => true],
3225
'cast_spaces' => ['space' => 'none'],
33-
'compact_nullable_typehint' => true,
3426
'concat_space' => ['spacing' => 'one'],
3527
'declare_equal_normalize' => ['space' => 'none'],
28+
'declare_parentheses' => true,
3629
'dir_constant' => true,
30+
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
3731
'function_typehint_space' => true,
38-
'hash_to_slash_comment' => true,
39-
'lowercase_cast' => true,
40-
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
32+
'modernize_strpos' => true,
4133
'modernize_types_casting' => true,
4234
'native_function_casing' => true,
43-
'new_with_braces' => true,
4435
'no_alias_functions' => true,
4536
'no_blank_lines_after_phpdoc' => true,
4637
'no_empty_phpdoc' => true,
4738
'no_empty_statement' => true,
48-
'no_extra_consecutive_blank_lines' => true,
49-
'no_leading_import_slash' => true,
39+
'no_extra_blank_lines' => true,
5040
'no_leading_namespace_whitespace' => true,
5141
'no_null_property_initialization' => true,
5242
'no_short_bool_cast' => true,
5343
'no_singleline_whitespace_before_semicolons' => true,
5444
'no_superfluous_elseif' => true,
55-
'no_trailing_comma_in_singleline_array' => true,
45+
'no_trailing_comma_in_singleline' => true,
5646
'no_unneeded_control_parentheses' => true,
5747
'no_unused_imports' => true,
5848
'no_useless_else' => true,
59-
'no_whitespace_in_blank_line' => true,
60-
'ordered_imports' => true,
61-
'php_unit_construct' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'],
49+
'no_useless_nullsafe_operator' => true,
50+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
51+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
6252
'php_unit_mock_short_will_return' => true,
6353
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
6454
'phpdoc_no_access' => true,
@@ -70,7 +60,8 @@
7060
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
7161
'return_type_declaration' => ['space_before' => 'none'],
7262
'single_quote' => true,
73-
'single_trait_insert_per_statement' => true,
74-
'whitespace_after_comma_in_array' => true,
75-
])
76-
->setFinder($finder);
63+
'single_space_around_construct' => true,
64+
'single_line_comment_style' => ['comment_types' => ['hash']],
65+
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
66+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
67+
]);

Classes/ContentObject/PtiContentObject.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,24 @@
55
namespace PrototypeIntegration\PrototypeIntegration\ContentObject;
66

77
use PrototypeIntegration\PrototypeIntegration\DataProcessing\ProcessorRunner;
8-
use PrototypeIntegration\PrototypeIntegration\View\TemplateBasedView;
8+
use PrototypeIntegration\PrototypeIntegration\View\TemplateBasedViewInterface;
99
use PrototypeIntegration\PrototypeIntegration\View\ViewResolver;
1010
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
1111
use TYPO3\CMS\Core\Utility\GeneralUtility;
1212
use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
13-
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1413

1514
class PtiContentObject extends AbstractContentObject
1615
{
17-
protected TypoScriptService $typoScriptService;
18-
19-
protected ProcessorRunner $processorRunner;
20-
2116
protected ViewResolver $viewResolver;
2217

2318
protected array $conf;
2419

2520
protected string $templateName;
2621

27-
public function __construct(ContentObjectRenderer $contentObjectRenderer)
28-
{
29-
parent::__construct($contentObjectRenderer);
30-
31-
$this->typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
32-
$this->processorRunner = GeneralUtility::makeInstance(ProcessorRunner::class);
33-
22+
public function __construct(
23+
protected TypoScriptService $typoScriptService,
24+
protected ProcessorRunner $processorRunner,
25+
) {
3426
$viewResolverClass = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['pti']['view']['viewResolver'];
3527
$this->viewResolver = GeneralUtility::makeInstance($viewResolverClass);
3628
}
@@ -56,7 +48,7 @@ public function render($conf = [])
5648
$view = $this->viewResolver->getViewForContentObject($data, $templateName);
5749
$view->setVariables($data);
5850

59-
if ($view instanceof TemplateBasedView) {
51+
if ($view instanceof TemplateBasedViewInterface) {
6052
$view->setTemplate($templateName);
6153
}
6254

Classes/Processor/ImageProcessor.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PrototypeIntegration\PrototypeIntegration\Processor;
66

77
use TYPO3\CMS\Core\Resource\FileInterface;
8+
use TYPO3\CMS\Core\Utility\PathUtility;
89
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
910
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
1011
use UnexpectedValueException;
@@ -34,13 +35,13 @@ public function renderImage(FileInterface $file, array $conf = []): array
3435
1_678_088_092
3536
);
3637
}
37-
38-
$retinaImageResource = self::renderRetinaImage($file, $conf);
38+
$defaultImagePublicUrl = PathUtility::stripPathSitePrefix($defaultImageResource[3]);
39+
$retinaImagePublicUrl = self::renderRetinaImage($file, $conf);
3940

4041
$assetOptions = [
4142
'uri' => [
42-
'default' => $this->addAbsRefPrefix($defaultImageResource[3]),
43-
'retina2x' => $this->addAbsRefPrefix($retinaImageResource)
43+
'default' => $defaultImagePublicUrl,
44+
'retina2x' => $retinaImagePublicUrl,
4445
],
4546
'width' => $defaultImageResource[0],
4647
'height' => $defaultImageResource[1],
@@ -69,18 +70,7 @@ protected function renderRetinaImage(FileInterface $file, array $configuration):
6970
);
7071
}
7172

72-
return $image[3];
73-
}
74-
75-
/**
76-
* Prepend the absRefPrefix from typoscript configuration to the image file path
77-
*
78-
* @param string $uri
79-
* @return string
80-
*/
81-
protected function addAbsRefPrefix(string $uri): string
82-
{
83-
return $this->tsfe->absRefPrefix . $uri;
73+
return PathUtility::stripPathSitePrefix($image[3]);
8474
}
8575

8676
/**

Classes/Processor/PreviewImageProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class PreviewImageProcessor
2121
{
22-
const FILE_PREVIEW_IMAGE_PROPERTY = 'preview_image';
22+
public const FILE_PREVIEW_IMAGE_PROPERTY = 'preview_image';
2323

2424
protected MetaDataRepository $metaDataRepository;
2525

Classes/Processor/TypoLinkStringProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace PrototypeIntegration\PrototypeIntegration\Processor;
66

7+
use TYPO3\CMS\Core\LinkHandling\TypoLinkCodecService;
78
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
8-
use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
99

1010
class TypoLinkStringProcessor
1111
{

Classes/View/DefaultViewResolver.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
88
use TYPO3\CMS\Core\Utility\GeneralUtility;
9-
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
10-
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
119

1210
class DefaultViewResolver implements ViewResolver
1311
{
@@ -18,20 +16,23 @@ public function __construct(ExtensionConfiguration $extensionConfiguration)
1816
$this->extensionConfiguration = $extensionConfiguration;
1917
}
2018

21-
public function getViewForContentObject(?array $dbRow = [], ?string $template = ''): ViewInterface
19+
public function getViewForContentObject(?array $dbRow = [], ?string $template = ''): PtiViewInterface
2220
{
2321
return $this->getDefaultView();
2422
}
2523

26-
public function getViewForExtbaseAction(ControllerContext $controllerContext, ?string $template): ViewInterface
27-
{
24+
public function getViewForExtbaseAction(
25+
string $controllerObjectName,
26+
string $actionName,
27+
string $format,
28+
?string $template
29+
): PtiViewInterface {
2830
return $this->getDefaultView();
2931
}
3032

31-
protected function getDefaultView(): ViewInterface
33+
protected function getDefaultView(): PtiViewInterface
3234
{
3335
$class = $this->extensionConfiguration->get('pti', 'defaultView');
34-
/** @var ViewInterface $view */
3536
$view = GeneralUtility::makeInstance($class);
3637
return $view;
3738
}

Classes/View/ExtbaseViewAdapter.php

+25-17
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,30 @@
66

77
use PrototypeIntegration\PrototypeIntegration\View\Event\ExtbaseViewAdapterVariablesConvertedEvent;
88
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
9+
use TYPO3\CMS\Core\Utility\Exception\NotImplementedMethodException;
910
use TYPO3\CMS\Core\Utility\GeneralUtility;
10-
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
11-
use TYPO3\CMS\Extbase\Mvc\View\AbstractView;
11+
use TYPO3Fluid\Fluid\View\AbstractView;
1212

13-
abstract class ExtbaseViewAdapter extends AbstractView
13+
abstract class ExtbaseViewAdapter extends AbstractView implements ViewAdapterContextAware
1414
{
1515
protected ?array $settings;
1616

1717
protected ?string $template = null;
1818

1919
protected EventDispatcher $eventDispatcher;
2020

21+
protected ExtbaseViewAdapterContext $viewAdapterContext;
22+
2123
public function injectDispatcher(EventDispatcher $eventDispatcher)
2224
{
2325
$this->eventDispatcher = $eventDispatcher;
2426
}
2527

28+
public function setViewAdapterContext(ExtbaseViewAdapterContext $viewAdapterContext): void
29+
{
30+
$this->viewAdapterContext = $viewAdapterContext;
31+
}
32+
2633
/**
2734
* Renders the view
2835
*
@@ -36,17 +43,19 @@ public function render()
3643
$viewResolver = GeneralUtility::makeInstance($viewResolverClass);
3744

3845
$view = $viewResolver->getViewForExtbaseAction(
39-
$this->controllerContext,
46+
$this->viewAdapterContext->getControllerObjectName(),
47+
$this->viewAdapterContext->getActionName(),
48+
$this->viewAdapterContext->getFormat(),
4049
$this->getTemplate()
4150
);
4251

43-
if ($view instanceof TemplateBasedView) {
52+
if ($view instanceof TemplateBasedViewInterface) {
4453
$view->setTemplate($this->getTemplate());
4554
}
4655

4756
$variables = $this->convertVariables($this->variables);
4857
$variables = $this->eventDispatcher->dispatch(new ExtbaseViewAdapterVariablesConvertedEvent($variables))->getVariables();
49-
$view->assignMultiple($variables);
58+
$view->setVariables($variables);
5059

5160
return $view->render();
5261
}
@@ -56,24 +65,23 @@ protected function convertVariables(array $variables): array
5665
return $variables;
5766
}
5867

59-
public function setControllerContext(ControllerContext $controllerContext)
60-
{
61-
parent::setControllerContext($controllerContext);
62-
}
63-
64-
/**
65-
* @return string
66-
*/
6768
public function getTemplate(): string
6869
{
6970
return $this->template;
7071
}
7172

72-
/**
73-
* @param array $settings
74-
*/
7573
public function injectSettings(?array $settings): void
7674
{
7775
$this->settings = $settings;
7876
}
77+
78+
public function renderSection($sectionName, array $variables = [], $ignoreUnknown = false)
79+
{
80+
throw new NotImplementedMethodException('', 1691402012205);
81+
}
82+
83+
public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = false)
84+
{
85+
throw new NotImplementedMethodException('', 1691402017852);
86+
}
7987
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace PrototypeIntegration\PrototypeIntegration\View;
4+
5+
class ExtbaseViewAdapterContext
6+
{
7+
public function __construct(
8+
protected string $controllerObjectName,
9+
protected string $actionName,
10+
protected string $format
11+
) {
12+
}
13+
14+
public function getControllerObjectName(): string
15+
{
16+
return $this->controllerObjectName;
17+
}
18+
19+
public function getActionName(): string
20+
{
21+
return $this->actionName;
22+
}
23+
24+
public function getFormat(): string
25+
{
26+
return $this->format;
27+
}
28+
}

0 commit comments

Comments
 (0)