‪TYPO3CMS  10.4
AbstractServiceProvider.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 
20 use ArrayObject;
21 use Psr\Container\ContainerInterface;
22 use Psr\Log\LoggerAwareInterface;
26 
31 {
39  abstract protected static function ‪getPackagePath(): string;
40 
44  abstract public function ‪getFactories(): array;
45 
49  public function ‪getExtensions(): array
50  {
51  return [
52  'middlewares' => [ static::class, 'configureMiddlewares' ],
53  'backend.routes' => [ static::class, 'configureBackendRoutes' ],
54  ];
55  }
56 
63  public static function ‪configureMiddlewares(ContainerInterface $container, ArrayObject $middlewares, string $path = null): ArrayObject
64  {
65  $packageConfiguration = ($path ?? static::getPackagePath()) . 'Configuration/RequestMiddlewares.php';
66  if (file_exists($packageConfiguration)) {
67  $middlewaresInPackage = require $packageConfiguration;
68  if (is_array($middlewaresInPackage)) {
69  $middlewares->exchangeArray(array_replace_recursive($middlewares->getArrayCopy(), $middlewaresInPackage));
70  }
71  }
72 
73  return $middlewares;
74  }
75 
82  public static function ‪configureBackendRoutes(ContainerInterface $container, ArrayObject $routes, string $path = null): ArrayObject
83  {
84  $path = $path ?? static::getPackagePath();
85  $routesFileNameForPackage = $path . 'Configuration/Backend/Routes.php';
86  if (file_exists($routesFileNameForPackage)) {
87  $definedRoutesInPackage = require $routesFileNameForPackage;
88  if (is_array($definedRoutesInPackage)) {
89  $routes->exchangeArray(array_merge($routes->getArrayCopy(), $definedRoutesInPackage));
90  }
91  }
92  $routesFileNameForPackage = $path . 'Configuration/Backend/AjaxRoutes.php';
93  if (file_exists($routesFileNameForPackage)) {
94  $definedRoutesInPackage = require $routesFileNameForPackage;
95  if (is_array($definedRoutesInPackage)) {
96  foreach ($definedRoutesInPackage as $routeIdentifier => $routeOptions) {
97  // prefix the route with "ajax_" as "namespace"
98  $routeOptions['path'] = '/ajax' . $routeOptions['path'];
99  $routes['ajax_' . $routeIdentifier] = $routeOptions;
100  $routes['ajax_' . $routeIdentifier]['ajax'] = true;
101  }
102  }
103  }
104 
105  return $routes;
106  }
107 
116  protected static function new(ContainerInterface $container, string $className, array $constructorArguments = [])
117  {
118  // Support $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'] (xclasses) and class alias maps
119  $instance = GeneralUtility::makeInstanceForDi($className, ...$constructorArguments);
120 
121  if ($instance instanceof LoggerAwareInterface) {
122  $instance->setLogger($container->get(LogManager::class)->getLogger($className));
123  }
124  return $instance;
125  }
126 }
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:31
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\getPackagePath
‪static string getPackagePath()
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\getExtensions
‪array getExtensions()
Definition: AbstractServiceProvider.php:49
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\configureBackendRoutes
‪static ArrayObject configureBackendRoutes(ContainerInterface $container, ArrayObject $routes, string $path=null)
Definition: AbstractServiceProvider.php:82
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\configureMiddlewares
‪static ArrayObject configureMiddlewares(ContainerInterface $container, ArrayObject $middlewares, string $path=null)
Definition: AbstractServiceProvider.php:63
‪TYPO3\CMS\Core\DependencyInjection\ServiceProviderInterface
Definition: ServiceProviderInterface.php:24
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:30
‪TYPO3\CMS\Core\Package
Definition: AbstractServiceProvider.php:18
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\getFactories
‪array getFactories()
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46