Commit | Line | Data |
---|---|---|
711aa5d7 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * Class Civi | |
5 | * | |
6 | * The "Civi" class provides a facade for accessing major subsystems, | |
7 | * such as the service-container and settings manager. It serves as a | |
8 | * bridge which allows procedural code to access important objects. | |
9 | * | |
10 | * General principles: | |
11 | * - Each function provides access to a major subsystem. | |
12 | * - Each function performs a simple lookup. | |
13 | * - Each function returns an interface. | |
14 | * - Whenever possible, interfaces should be well-known (e.g. based | |
15 | * on a standard or well-regarded provider). | |
16 | */ | |
17 | class Civi { | |
18 | ||
19 | /** | |
20 | * A central location for static variable storage. | |
21 | * | |
22 | * @code | |
23 | * `Civi::$statics[__CLASS__]['foo'] = 'bar'; | |
24 | * @endcode | |
25 | */ | |
26 | public static $statics = array(); | |
27 | ||
28 | /** | |
29 | * Get the service container. | |
30 | * | |
31 | * @return \Symfony\Component\DependencyInjection\ContainerInterface | |
32 | */ | |
33 | public static function container() { | |
34 | return Civi\Core\Container::singleton(); | |
35 | } | |
36 | ||
37 | /** | |
38 | * Fetch a service from the container. | |
39 | * | |
40 | * @param string $id | |
41 | * The service ID. | |
42 | * @return mixed | |
43 | */ | |
44 | public static function service($id) { | |
45 | return \Civi\Core\Container::singleton()->get($id); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Reset all ephemeral system state, e.g. statics, | |
50 | * singletons, containers. | |
51 | */ | |
52 | public static function reset() { | |
53 | Civi\Core\Container::singleton(TRUE); | |
54 | self::$statics = array(); | |
55 | } | |
56 | ||
57 | } |