Skip to content

Commit

Permalink
[TASK] Show ordered PSR-15 middlewares in Configuration module
Browse files Browse the repository at this point in the history
In order to find out what middlewares are called in which order,
the Configuration module now has an additional list of all
registered middlewares for "frontend" and "backend" stack.

Resolves: #83882
Releases: master
Change-Id: I99d8478bb07437efa65d292221ccdb03d5dd3161
Reviewed-on: https://review.typo3.org/55597
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
bmack authored and lolli42 committed Feb 14, 2018
1 parent 340f4ea commit 5278a23
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Http\MiddlewareStackResolver;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand Down Expand Up @@ -99,6 +104,10 @@ class ConfigurationController
'label' => 'routes',
'type' => 'routes',
],
'httpMiddlewareStacks' => [
'label' => 'httpMiddlewareStacks',
'type' => 'httpMiddlewareStacks',
],
];

/**
Expand Down Expand Up @@ -163,6 +172,7 @@ public function mainAction(ServerRequestInterface $request, ResponseInterface $r
$moduleState['regexSearch'] = (bool)($postValues['regexSearch'] ?? $moduleState['regexSearch'] ?? false);

// Prepare main array
$sortKeysByName = true;
if ($selectedTreeDetails['type'] === 'global') {
$globalArrayKey = $selectedTreeDetails['globalKey'];
$renderArray = $GLOBALS[$globalArrayKey];
Expand Down Expand Up @@ -201,10 +211,33 @@ public function mainAction(ServerRequestInterface $request, ResponseInterface $r
'options' => $route->getOptions()
];
}
} elseif ($selectedTreeDetails['type'] === 'httpMiddlewareStacks') {
// Keep the order of the keys
$sortKeysByName = false;
// Fake a PHP frontend with a null backend to avoid PHP Opcache conflicts
// When using >requireOnce() multiple times in one request
$cache = GeneralUtility::makeInstance(
PhpFrontend::class,
'middleware',
GeneralUtility::makeInstance(NullBackend::class, 'Production')
);
$stackResolver = GeneralUtility::makeInstance(
MiddlewareStackResolver::class,
GeneralUtility::makeInstance(PackageManager::class),
GeneralUtility::makeInstance(DependencyOrderingService::class),
$cache
);
$renderArray = [];
foreach (['frontend', 'backend'] as $stackName) {
// reversing the array allows the admin to read the stack from top to bottom
$renderArray[$stackName] = array_reverse($stackResolver->resolve($stackName));
}
} else {
throw new \RuntimeException('Unknown array type "' . $selectedTreeDetails['type'] . '"', 1507845662);
}
ArrayUtility::naturalKeySortRecursive($renderArray);
if ($sortKeysByName) {
ArrayUtility::naturalKeySortRecursive($renderArray);
}

// Prepare array renderer class, apply search and expand / collapse states
$arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<trans-unit id="routes">
<source>Backend Routes</source>
</trans-unit>
<trans-unit id="httpMiddlewareStacks">
<source>HTTP Middlewares (PSR-15)</source>
</trans-unit>
<trans-unit id="t3services">
<source>$GLOBALS['T3_SERVICES'] (Registered Services)</source>
</trans-unit>
Expand Down

0 comments on commit 5278a23

Please sign in to comment.