From dc3b6016d28e074e25388e5699194ad3cba616a9 Mon Sep 17 00:00:00 2001 From: Sascha Nowak Date: Sat, 9 Nov 2024 12:54:30 +0100 Subject: [PATCH] feat: TYPO3 13.4 compatibility --- .github/workflows/apply-coding-standard.yml | 6 +- .github/workflows/ci.yml | 8 +- Classes/Middleware/AcceptHeaderHashBase.php | 2 +- Classes/Middleware/AjaxRequestMiddleware.php | 64 +++---- Classes/Mvc/Controller/AjaxController.php | 4 +- Classes/Mvc/View/JsonView.php | 43 +++-- .../Middleware/AjaxRequestMiddlewareTest.php | 81 ++++----- composer.json | 10 +- rector.php | 164 ++++-------------- 9 files changed, 122 insertions(+), 260 deletions(-) diff --git a/.github/workflows/apply-coding-standard.yml b/.github/workflows/apply-coding-standard.yml index fafec9a..09d9765 100644 --- a/.github/workflows/apply-coding-standard.yml +++ b/.github/workflows/apply-coding-standard.yml @@ -16,7 +16,7 @@ jobs: - name: 'Setup PHP' uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.3' tools: composer - name: 'Get Composer Cache Directory' @@ -26,7 +26,7 @@ jobs: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache Composer Dependencies' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: composer @@ -53,7 +53,7 @@ jobs: - name: 'Create pull-request' id: cpr - uses: peter-evans/create-pull-request@v5.0.2 + uses: peter-evans/create-pull-request@v6.0.3 with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: "[automated] Apply Coding Standard" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3c1118..9a4af26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,12 +20,12 @@ permissions: jobs: test: runs-on: ubuntu-latest - name: TYPO3 v12.4 tests on PHP ${{ matrix.php }} + name: TYPO3 v13.4 tests on PHP ${{ matrix.php }} strategy: fail-fast: false matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.3 ] steps: - name: 'Checkout code' @@ -46,7 +46,7 @@ jobs: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache Composer Dependencies' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: composer-php${{ matrix.php }} @@ -72,7 +72,7 @@ jobs: run: .Build/bin/phpcov merge --html .Build/artifacts/coverage/merged --clover .Build/artifacts/coverage/clover.xml .Build/artifacts/coverage/ - name: 'Generate code coverage summary report' - uses: saschanowak/CloverCodeCoverageSummary@0.4.0 + uses: saschanowak/CloverCodeCoverageSummary@1.0.1 with: filename: .Build/artifacts/coverage/clover.xml diff --git a/Classes/Middleware/AcceptHeaderHashBase.php b/Classes/Middleware/AcceptHeaderHashBase.php index 2f804eb..b6220a9 100644 --- a/Classes/Middleware/AcceptHeaderHashBase.php +++ b/Classes/Middleware/AcceptHeaderHashBase.php @@ -15,7 +15,7 @@ class AcceptHeaderHashBase implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $function = function (array &$params) use ($request) { + $function = function (array &$params) use ($request): void { $params['hashParameters'][self::class] = []; $params['hashParameters'][self::class]['REQUEST_METHOD'] = strtoupper((string) $request->getMethod()); diff --git a/Classes/Middleware/AjaxRequestMiddleware.php b/Classes/Middleware/AjaxRequestMiddleware.php index 007825c..cef76cb 100644 --- a/Classes/Middleware/AjaxRequestMiddleware.php +++ b/Classes/Middleware/AjaxRequestMiddleware.php @@ -9,15 +9,12 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use RuntimeException; -use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Cache\CacheTag; use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Http\Stream; use TYPO3\CMS\Core\Routing\PageArguments; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Reflection\ObjectAccess; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; class AjaxRequestMiddleware implements MiddlewareInterface { @@ -28,60 +25,48 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $routeArguments = $routing->getRouteArguments(); if ( - str_contains((string) $request->getHeaderLine('Accept'), 'application/json') + str_contains($request->getHeaderLine('Accept'), 'application/json') && (is_countable($routeArguments) ? count($routeArguments) : 0) > 0 ) { - $controller = $request->getAttribute('frontend.controller'); - assert($controller instanceof TypoScriptFrontendController); - - $controller->preparePageContentGeneration($request); - if (!$controller->tmpl->setup) { - throw new RuntimeException( - 'TypoScript not properly loaded, probably due to cached content.', - 1_593_611_242 - ); - } - $pluginNamespace = array_key_first($routeArguments); [$prefix, $extensionName, $pluginName] = explode('_', (string) $pluginNamespace); $pluginSignature = strtolower($extensionName . '_' . $pluginName); $typoScriptObjectPath = 'tt_content.list.20.' . $pluginSignature; - $setup = $this->getPluginTypoScriptConfiguration($controller, $typoScriptObjectPath); + $setup = $this->getPluginTypoScriptConfiguration($request, $typoScriptObjectPath); $typoScriptObjectName = $setup[$pluginSignature]; $typoScriptObjectConfiguration = $setup[$pluginSignature . '.']; $typoScriptObjectConfiguration['controller'] = $routeArguments[$pluginNamespace]['controller'] ?? ''; $typoScriptObjectConfiguration['action'] = $routeArguments[$pluginNamespace]['action'] ?? ''; - $this->addPluginFormatToRequest($request, $pluginNamespace); + $request = $this->addPluginFormatToRequest($request, $pluginNamespace); $contentContentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); - $contentContentObject->setUserObjectType(ContentObjectRenderer::OBJECTTYPE_USER); + $contentContentObject->setRequest($request); $pageContent = $contentContentObject->cObjGetSingle( $typoScriptObjectName, $typoScriptObjectConfiguration, $typoScriptObjectPath ); + + $pageId = $request->getAttribute('frontend.page.information')->getId(); + $pageCacheTag = new CacheTag('pageId_' . $pageId); if (str_starts_with((string) $pageContent, '