‪TYPO3CMS  10.4
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 
36  {
37  $this->package = $package;
38  }
39 
43  protected static function ‪getPackagePath(): string
44  {
45  throw new \BadMethodCallException('PseudoServiceProvider does not support the getPackagePath() method.', 1562354465);
46  }
47 
51  public function ‪getFactories(): array
52  {
53  return [];
54  }
55 
59  public function ‪getExtensions(): array
60  {
61  $packagePath = $this->package->getPackagePath();
62  $extensions = parent::getExtensions();
63 
64  // The static configure*() methods in AbstractServiceProvider use the
65  // static getPackagePath() method to retrieve the package path.
66  // We can not provide a static package path for pseudo service providers,
67  // therefore we dynamically inject the package path to the static service
68  // configure methods by wrapping these in a Closure.
69  // AbstractServiceProvider configure methods are aware of this and
70  // provide an optional third parameter which is forwarded as
71  // dynamic path to getPackagePath().
72  foreach ($extensions as $serviceName => $previousCallable) {
73  $extensions[$serviceName] = function (ContainerInterface $container, $value) use ($previousCallable, $packagePath) {
74  return ($previousCallable)($container, $value, $packagePath);
75  };
76  }
77 
78  return $extensions;
79  }
80 }
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:31
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getFactories
‪array getFactories()
Definition: PseudoServiceProvider.php:50
‪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\getPackagePath
‪static string getPackagePath()
Definition: PseudoServiceProvider.php:42
‪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:34
‪TYPO3\CMS\Core\Package\PseudoServiceProvider\getExtensions
‪array getExtensions()
Definition: PseudoServiceProvider.php:58