‪TYPO3CMS  ‪main
PseudoServiceProvider.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 Psr\Container\ContainerInterface;
21 
26 {
30  private ‪$package;
31 
33  {
34  $this->package = $package;
35  }
36 
37  protected static function ‪getPackagePath(): string
38  {
39  throw new \BadMethodCallException('PseudoServiceProvider does not support the getPackagePath() method.', 1562354465);
40  }
41 
42  protected static function ‪getPackageName(): string
43  {
44  throw new \BadMethodCallException('PseudoServiceProvider does not support the getPackageName() method.', 1643372902);
45  }
46 
47  public function ‪getFactories(): array
48  {
49  return [];
50  }
51 
52  public function ‪getExtensions(): array
53  {
54  $packagePath = $this->package->getPackagePath();
55  // Fallback to empty string if dealing with an extension in non-composer mode
56  // that still does not provide composer.json.
57  $packageName = $this->package->getValueFromComposerManifest('name') ?? '';
58  $extensions = parent::getExtensions();
59 
60  // The static configure*() methods in AbstractServiceProvider use the
61  // static getPackagePath() method to retrieve the package path.
62  // We can not provide a static package path for pseudo service providers,
63  // therefore we dynamically inject the package path to the static service
64  // configure methods by wrapping these in a Closure.
65  // AbstractServiceProvider configure methods are aware of this and
66  // provide an optional third parameter which is forwarded as
67  // dynamic path to getPackagePath().
68  // Same logic for $packageName.
69  foreach ($extensions as $serviceName => $previousCallable) {
70  $extensions[$serviceName] = static function (ContainerInterface $container, $value) use ($previousCallable, $packagePath, $packageName) {
71  return ($previousCallable)($container, $value, $packagePath, $packageName);
72  };
73  }
74 
75  return $extensions;
76  }
77 }
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:35
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getFactories
‪getFactories()
Definition: PseudoServiceProvider.php:46
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getPackagePath
‪static getPackagePath()
Definition: PseudoServiceProvider.php:36
‪TYPO3\CMS\Core\Package\PackageInterface
Definition: PackageInterface.php:22
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\$package
‪PackageInterface $package
Definition: PseudoServiceProvider.php:29
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getPackageName
‪static getPackageName()
Definition: PseudoServiceProvider.php:41
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getExtensions
‪getExtensions()
Definition: PseudoServiceProvider.php:51
‪TYPO3\CMS\Core\Package\PseudoServiceProvider
Definition: PseudoServiceProvider.php:26
‪TYPO3\CMS\Core\Package
Definition: AbstractServiceProvider.php:18
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\__construct
‪__construct(PackageInterface $package)
Definition: PseudoServiceProvider.php:31