41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace DigiComp\FlowMaintenanceMode\Http;
|
||
|
|
||
|
use DigiComp\FlowMaintenanceMode\MaintenanceModeManagerInterface;
|
||
|
use Neos\Flow\Annotations as Flow;
|
||
|
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
|
||
|
use Neos\Utility\PositionalArraySorter;
|
||
|
|
||
|
class MaintenanceModeMiddlewareFactory
|
||
|
{
|
||
|
protected ObjectManagerInterface $objectManager;
|
||
|
|
||
|
#[Flow\InjectConfiguration(path: 'allowModules')]
|
||
|
protected array $allowModuleNames;
|
||
|
|
||
|
/**
|
||
|
* @param ObjectManagerInterface $objectManager
|
||
|
*/
|
||
|
public function __construct(ObjectManagerInterface $objectManager)
|
||
|
{
|
||
|
$this->objectManager = $objectManager;
|
||
|
}
|
||
|
|
||
|
public function create(): MaintenanceModeMiddleware
|
||
|
{
|
||
|
$allowModules = [];
|
||
|
$sorter = new PositionalArraySorter($this->allowModuleNames);
|
||
|
foreach ($sorter->getSortedKeys() as $moduleName) {
|
||
|
$allowModules[] = $this->objectManager->get($moduleName);
|
||
|
}
|
||
|
|
||
|
return new MaintenanceModeMiddleware(
|
||
|
$this->objectManager->get(MaintenanceModeManagerInterface::class),
|
||
|
...$allowModules
|
||
|
);
|
||
|
}
|
||
|
}
|