PluginProbe
Multisite Language Switcher / trunk
Multisite Language Switcher vtrunk
3.0.2 3.0.1 trunk 0.1 0.2 0.3 0.4 0.5 0.6.8 0.7.1 0.8 0.9.9.3 1.0.8 2.0.3 2.1.1 2.10.0 2.10.1 2.2.0 2.3.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.2 2.4.3 All 60 releases
multisite-language-switcher / includes / Container.php

Container.php in Multisite Language Switcher trunk, at includes/Container.php

46 lines 997 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare( strict_types=1 );
2
3 namespace lloc\Msls;
4
5 use DI\Container as DiContainer;
6 use DI\ContainerBuilder;
7
8 /**
9 * Accessor for the PHP-DI container.
10 *
11 * The container is built on first use and kept for the rest of the request; requests that
12 * never ask for it never pay for it.
13 *
14 * @package Msls
15 */
16 final class Container {
17
18 /**
19 * The container built by self::get(), kept for the rest of the request.
20 *
21 * @var ?DiContainer
22 */
23 private static ?DiContainer $container = null;
24
25 /**
26 * @throws \Exception If the container cannot be built.
27 */
28 public static function get(): DiContainer {
29 if ( null === self::$container ) {
30 $builder = new ContainerBuilder();
31 $builder->addDefinitions( Plugin::plugin_dir_path( 'config.php' ) );
32
33 self::$container = $builder->build();
34 }
35
36 return self::$container;
37 }
38
39 /**
40 * Drops the built container, so the next call to self::get() builds a new one.
41 */
42 public static function reset(): void {
43 self::$container = null;
44 }
45 }
46