1 | <?php |
||
23 | class App { |
||
24 | |||
25 | /** |
||
26 | * Flag if Carbon Fields has been booted |
||
27 | * |
||
28 | * @var bool |
||
29 | */ |
||
30 | public $booted = false; |
||
31 | |||
32 | /** |
||
33 | * Inversion of Control container instance |
||
34 | * |
||
35 | * @var PimpleContainer |
||
36 | */ |
||
37 | protected $ioc = null; |
||
38 | |||
39 | /** |
||
40 | * Singleton implementation |
||
41 | * |
||
42 | * @return App |
||
43 | */ |
||
44 | public static function instance() { |
||
45 | static $instance = null; |
||
46 | if ( $instance === null ) { |
||
47 | $instance = new static(); |
||
48 | } |
||
49 | return $instance; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get default IoC container dependencies |
||
54 | * |
||
55 | * @return PimpleContainer |
||
56 | */ |
||
57 | protected static function get_default_ioc() { |
||
108 | |||
109 | /** |
||
110 | * Resolve a dependency through IoC |
||
111 | * |
||
112 | * @param string $key |
||
113 | * @return mixed |
||
114 | */ |
||
115 | public static function resolve( $key ) { |
||
118 | |||
119 | /** |
||
120 | * Resolve a service through IoC |
||
121 | * |
||
122 | * @param string $service_name |
||
123 | * @return mixed |
||
124 | */ |
||
125 | public static function service( $service_name ) { |
||
128 | |||
129 | /** |
||
130 | * Replace the ioc container for the App |
||
131 | * |
||
132 | * @param PimpleContainer $ioc |
||
133 | */ |
||
134 | public function install( PimpleContainer $ioc ) { |
||
137 | |||
138 | /** |
||
139 | * Boot Carbon Fields with default IoC dependencies |
||
140 | */ |
||
141 | public static function boot() { |
||
142 | if ( static::is_booted() ) { |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | if ( defined( __NAMESPACE__ . '\VERSION' ) ) { |
||
147 | return; // Possibly attempting to load multiple versions of Carbon Fields; bail in favor of already loaded version |
||
148 | } |
||
149 | |||
150 | static::instance()->install( static::get_default_ioc() ); |
||
151 | static::resolve( 'loader' )->boot(); |
||
152 | static::instance()->booted = true; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Check if Carbon Fields has booted |
||
157 | */ |
||
158 | public static function is_booted() { |
||
161 | |||
162 | /** |
||
163 | * Throw exception if Carbon Fields has not been booted |
||
164 | */ |
||
165 | public static function verify_boot() { |
||
170 | } |