Completed
Push — add/e2e-connection-purchase-fl... ( d02cce...68beb5 )
by Yaroslav
14:07 queued 04:35
created

functions.php ➔ reset_maps_after_update()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 3
dl 0
loc 38
rs 9.0008
c 0
b 0
f 0
1
<?php
2
/* HEADER */ // phpcs:ignore
3
4
/**
5
 * Used for autoloading jetpack packages.
6
 *
7
 * @param string $class_name Class Name to load.
8
 *
9
 * @return Boolean Whether the class_name was found in the classmap.
10
 */
11
function autoloader( $class_name ) {
12
	global $jetpack_autoloader_loader;
13
	if ( ! isset( $jetpack_autoloader_loader ) ) {
14
		return false;
15
	}
16
17
	$file = $jetpack_autoloader_loader->find_class_file( $class_name );
18
	if ( ! isset( $file ) ) {
19
		return false;
20
	}
21
22
	require_once $file;
23
	return true;
24
}
25
26
/**
27
 * Finds the latest installed autoloader. If this is the latest autoloader, sets
28
 * up the classmap and filemap.
29
 */
30
function set_up_autoloader() {
31
	global $jetpack_autoloader_latest_version;
32
	global $jetpack_autoloader_loader;
33
34
	require_once __DIR__ . '/class-plugins-handler.php';
35
	require_once __DIR__ . '/class-version-selector.php';
36
	require_once __DIR__ . '/class-autoloader-locator.php';
37
	require_once __DIR__ . '/class-autoloader-handler.php';
38
39
	$plugins_handler    = new Plugins_Handler();
40
	$version_selector   = new Version_Selector();
41
	$autoloader_handler = new Autoloader_Handler(
42
		$plugins_handler->get_current_plugin_path(),
43
		$plugins_handler->get_all_active_plugins_paths(),
44
		new Autoloader_Locator( $version_selector ),
45
		$version_selector
46
	);
47
48
	if ( $autoloader_handler->should_autoloader_reset() ) {
49
		/*
50
		 * The autoloader must be reset when an activating plugin that was
51
		 * previously unknown is detected.
52
		 */
53
		$jetpack_autoloader_latest_version = null;
54
		$jetpack_autoloader_loader         = null;
55
	}
56
57
	if ( ! $autoloader_handler->is_latest_autoloader() || isset( $jetpack_autoloader_loader ) ) {
58
		return;
59
	}
60
61
	require_once __DIR__ . '/class-manifest-handler.php';
62
	require_once __DIR__ . '/class-version-loader.php';
63
64
	$jetpack_autoloader_loader = $autoloader_handler->build_autoloader();
65
	$autoloader_handler->update_autoloader_chain();
66
67
	// Now that the autoloader is ready we can load the files in the filemap safely.
68
	$jetpack_autoloader_loader->load_filemap();
69
}
70