[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Package / PseudoServiceProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Package;
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
18 use Psr\Container\ContainerInterface;
19
20 /**
21 * @internal
22 */
23 final class PseudoServiceProvider extends AbstractServiceProvider
24 {
25 /**
26 * @var PackageInterface
27 */
28 private $package;
29
30 /**
31 * @param PackageInterface $package
32 */
33 public function __construct(PackageInterface $package)
34 {
35 $this->package = $package;
36 }
37
38 /**
39 * @return string
40 */
41 protected static function getPackagePath(): string
42 {
43 throw new \BadMethodCallException('PseudoServiceProvider does not support the getPackagePath() method.', 1562354465);
44 }
45
46 /**
47 * @return array
48 */
49 public function getFactories(): array
50 {
51 return [];
52 }
53
54 /**
55 * @return array
56 */
57 public function getExtensions(): array
58 {
59 $packagePath = $this->package->getPackagePath();
60 $extensions = parent::getExtensions();
61
62 // The static configure*() methods in AbstractServiceProvider use the
63 // static getPackagePath() method to retrieve the package path.
64 // We can not provide a static package path for pseudo service providers,
65 // therefore we dynamically inject the package path to the static service
66 // configure methods by wrapping these in a Closure.
67 // AbstractServiceProvider configure methods are aware of this and
68 // provide an optional thrid parameter which is forwarded as
69 // dynamic path to getPackagePath().
70 foreach ($extensions as $serviceName => $previousCallable) {
71 $extensions[$serviceName] = function (ContainerInterface $container, $value) use ($previousCallable, $packagePath) {
72 return ($previousCallable)($container, $value, $packagePath);
73 };
74 }
75
76 return $extensions;
77 }
78 }