‪TYPO3CMS  ‪main
DriverMiddlewareService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
25 class DriverMiddlewareService
26 {
27  public function __construct(private readonly DependencyOrderingService $dependencyOrderingService) {}
28 
29  public function order(array $middlewares): array
30  {
31  return $this->dependencyOrderingService->orderByDependencies($middlewares);
32  }
33 
34  public function normalizeMiddlewareConfiguration(string ‪$identifier, array|string $middleware): array
35  {
36  // @deprecated class-string middleware configuration since v13. Remove this in v14 or throw an exception.
37  if (is_string($middleware)) {
38  trigger_error(
39  sprintf(
40  'DriverMiddleware registration with class-string is deprecated since v13 for "%s". Please configure as array.',
42  ),
43  E_USER_DEPRECATED
44  );
45  if ($middleware === '') {
46  $middleware = [
47  'disabled' => true,
48  ];
49  } else {
50  $middleware = [
51  'target' => $middleware,
52  'after' => [
53  'typo3/core/custom-platform-driver-middleware',
54  ],
55  ];
56  }
57  }
58 
59  return $middleware;
60  }
61 
66  public function ensureCompleteMiddlewareConfiguration(array $middleware): array
67  {
68  $target = (string)($middleware['target'] ?? '');
69  if ($target === '' || !class_exists($target)) {
70  throw new \RuntimeException(
71  'Doctrine DBAL driver middleware registration requires a valid class-name as "target".',
72  1701546655
73  );
74  }
75  $targetImplements = $target !== '' && class_exists($target) ? (class_implements($target) ?: []) : [];
76  return [
77  'target' => $target,
78  'disabled' => (bool)($middleware['disabled'] ?? false),
79  'after' => (array)($middleware['after'] ?? []),
80  'before' => (array)($middleware['before'] ?? []),
81  'type' => '',
82  ];
83  }
84 }
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Database
Definition: Connection.php:18