Completed
Push — try/composer ( 5fde13...b3c737 )
by
unknown
17:40 queued 10:19
created

Bootstrap::loaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
  * Rules:
5
  * - only major versions may break APIs - internal OR external (since libraries may be loaded from one instance into another)
6
  * - minor versions may conflict-resolve (load only one instance)
7
  * - major versions must be able to run alongside each other (perhaps with a warning), including versioning all public-facing REST APIs AND having non-conflicting data
8
  * -
9
  */
10
11
/**
12
 * TODO
13
 *
14
 * - connection
15
 * - API
16
 * - UI
17
 * - etc
18
 */
19
20
21
namespace Jetpack\V7\Core;
22
23
// declare as internal var because declaring const here would throw error if another
24
// instance of this library is already loaded
25
$my_version = '7.2.1';
26
$primary_class = '\\Jetpack\\V7\\Core\\Bootstrap';
27
28
error_log("loading bootstrap " . getmypid());
29
30
// we need autoload = FALSE here otherwise it reports the class exists even if the class itself hasn't been defined yet
31
if ( class_exists( $primary_class, false ) ) {
32
	$reflector = new \ReflectionClass( $primary_class );
33
	error_log( "$primary_class was already defined in " . $reflector->getFileName() );
34
35
	$primary_class_instance = new $primary_class();
36
37
	if ( $primary_class_instance->version() !== $my_version ) {
38
		error_log("Multiple versions of $primary_class detected: $my_version <> " . $primary_class_instance->version() );
39
	}
40
	return;
41
}
42
43
class Bootstrap {
44
	public function version() {
45
		return \Jetpack\V7\Core\Constants::VERSION;
46
	}
47
48
	public function load() {
49
		// This will be used as a check if we have already loaded the plugin.
50
		if ( $this->loaded() ) {
51
			return;
52
		} // or raise exception??
53
54
		define( 'Jetpack_V7_Core_Loaded', true );
55
	}
56
57
	public function loaded() {
58
		return defined( 'Jetpack_V7_Core_Loaded' );
59
	}
60
}