Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Unit

on:
pull_request:

jobs:
tests:
name: Tests (PHP ${{ matrix.php-version }})
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.4']
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2

- run: composer install --no-progress

- run: composer test

tests-lowest:
name: Tests lowest deps (PHP ${{ matrix.php-version }})
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.4']
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2

- run: composer update --prefer-lowest --no-progress

- run: composer test
12 changes: 3 additions & 9 deletions Classes/ConfigurationModuleProvider/AppRoutesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@

class AppRoutesProvider extends AbstractProvider
{
/**
* @var RoutesConfigurationLoader
*/
protected $routesConfigurationLoader;

public function __construct(RoutesConfigurationLoader $routesConfigurationLoader)
{
$this->routesConfigurationLoader = $routesConfigurationLoader;
}
public function __construct(
private readonly RoutesConfigurationLoader $routesConfigurationLoader,
) {}

public function getConfiguration(): array
{
Expand Down
13 changes: 8 additions & 5 deletions Classes/Middleware/AppRoutesMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Aspect\PreviewAspect;
use TYPO3\CMS\Frontend\Page\PageInformation;
use TYPO3\CMS\Frontend\Page\PageParts;

class AppRoutesMiddleware implements MiddlewareInterface
{
Expand Down Expand Up @@ -89,7 +90,7 @@ protected function initializeNeededFrontendComponents(array $parameters, ServerR
$site = $request->getAttribute('site');

// set PageArguments as routing attribute
$keysToRemove = ['handler', 'requiresTsfe', 'requiresTypoScript', 'cache', 'L', '_route'];
$keysToRemove = ['handler', 'requiresTypoScript', 'cache', 'L', '_route'];
$remainingArguments = array_diff_key($request->getQueryParams(), array_flip($keysToRemove));
$request = $request->withAttribute('routing', new PageArguments($site->getRootPageId(), '0', [], [], $remainingArguments));

Expand All @@ -107,11 +108,13 @@ protected function initializeNeededFrontendComponents(array $parameters, ServerR
$pageInformation = $this->frontendInitialization->createPageInformation($request);
$request = $request->withAttribute('frontend.page.information', $pageInformation);

// TSFE
if ($parameters['requiresTsfe'] ?? false) {
$tsfe = $this->frontendInitialization->createTyposcriptFrontendController($request);
$request = $request->withAttribute('frontend.controller', $tsfe);
$pageParts = new PageParts();
$lastChanged = (int)$pageInformation->getPageRecord()['tstamp'];
if ($lastChanged < (int)$pageInformation->getPageRecord()['SYS_LASTCHANGED']) {
$lastChanged = (int)$pageInformation->getPageRecord()['SYS_LASTCHANGED'];
}
$pageParts->setLastChanged($lastChanged);
$request = $request->withAttribute('frontend.page.parts', $pageParts);

// TypoScript
if ($parameters['requiresTypoScript'] ?? false) {
Expand Down
31 changes: 0 additions & 31 deletions Classes/Service/FrontendInitialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScriptFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageInformation;
use TYPO3\CMS\Frontend\Page\PageInformationFactory;

Expand All @@ -29,34 +26,6 @@ public function __construct(
private readonly PhpFrontend $typoScriptCache,
) {}

public function createTyposcriptFrontendController(ServerRequestInterface $request): TypoScriptFrontendController
{
$pageInformation = $this->pageInformationFactory->create($request);

$controller = GeneralUtility::makeInstance(TypoScriptFrontendController::class);
$controller->initializePageRenderer($request);
$controller->initializeLanguageService($request);
$controller->id = $pageInformation->getId();
$controller->page = $pageInformation->getPageRecord();
$controller->contentPid = $pageInformation->getContentFromPid();
$controller->rootLine = $pageInformation->getRootLine();
$controller->config['rootLine'] = $pageInformation->getLocalRootLine();
$controller->register['SYS_LASTCHANGED'] = (int)$pageInformation->getPageRecord()['tstamp'];
if ($controller->register['SYS_LASTCHANGED'] < (int)$pageInformation->getPageRecord()['SYS_LASTCHANGED']) {
$controller->register['SYS_LASTCHANGED'] = (int)$pageInformation->getPageRecord()['SYS_LASTCHANGED'];
}

$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$contentObjectRenderer->start($pageInformation->getPageRecord(), 'pages');
$controller->cObj = $contentObjectRenderer;

$request = $request->withAttribute('frontend.controller', $controller);
$GLOBALS['TYPO3_REQUEST'] = $request;
$GLOBALS['TSFE'] = $controller;

return $controller;
}

public function createPageInformation(ServerRequestInterface $request): PageInformation
{
return $this->pageInformationFactory->create($request);
Expand Down
32 changes: 8 additions & 24 deletions Classes/Service/RoutesConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,20 @@ class RoutesConfigurationLoader
{
public const APP_ROUTES_YAML_PATH = 'Configuration/AppRoutes.yaml';

/**
* @var FrontendInterface
*/
protected $cache;
private readonly FrontendInterface $cache;
private array $routesConfiguration;

/**
* @var PackageManager
*/
protected $packageManager;

/**
* @var array
*/
protected $routesConfiguration;

/**
* @var YamlFileLoader
*/
protected $yamlFileLoader;

public function __construct(CacheManager $cacheManager, PackageManager $packageManager, YamlFileLoader $yamlFileLoader)
{
public function __construct(
CacheManager $cacheManager,
private readonly PackageManager $packageManager,
private readonly YamlFileLoader $yamlFileLoader,
) {
$this->cache = $cacheManager->getCache('app_routes');
$this->packageManager = $packageManager;
$this->yamlFileLoader = $yamlFileLoader;
}

public function getRoutesConfiguration(): array
{
if (!is_array($this->routesConfiguration)) {
if (!isset($this->routesConfiguration)) {
$this->loadRoutesConfiguration();
}
return $this->routesConfiguration;
Expand Down
3 changes: 1 addition & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Everything that is available as YAML configuration option in `symfony/routing` s
This package offers these additional options:

* `defaults.cache: true` - If true, then responses are cached (see more details below). (default: `false`)
* `defaults.requiresTsfe: true` - If true, then the `frontend.controller` request attribute will be initialized before your handler is called (default: `false`).
* `defaults.TypoScript: true` - If true, then the `frontend.typoscript` request attribute will be initialized before your handler is called (default: `false`).
* `defaults.requiresTypoScript: true` - If true, then the `frontend.typoscript` request attribute will be initialized before your handler is called (default: `false`).

### Generate Route URLs

Expand Down
Loading