Completed
Push — add/google-calendar-block ( bbd36e...c90e55 )
by
unknown
06:55
created

autoload.php ➔ enqueue_package_file()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 34

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 3
dl 34
loc 34
rs 9.0648
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file `autoload_packages.php`was generated by automattic/jetpack-autoloader.
4
 *
5
 * From your plugin include this file with:
6
 * require_once . plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php';
7
 *
8
 * @package automattic/jetpack-autoloader
9
 */
10
11
// phpcs:disable PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound
12
// phpcs:disable PHPCompatibility.Keywords.NewKeywords.t_namespaceFound
13
// phpcs:disable PHPCompatibility.Keywords.NewKeywords.t_ns_cFound
14
15
namespace Automattic\Jetpack\Autoloader;
16
17
if ( ! function_exists( __NAMESPACE__ . '\enqueue_package_class' ) ) {
18
	global $jetpack_packages_classes;
19
20
	if ( ! is_array( $jetpack_packages_classes ) ) {
21
		$jetpack_packages_classes = array();
22
	}
23
	/**
24
	 * Adds the version of a package to the $jetpack_packages global array so that
25
	 * the autoloader is able to find it.
26
	 *
27
	 * @param string $class_name Name of the class that you want to autoload.
28
	 * @param string $version Version of the class.
29
	 * @param string $path Absolute path to the class so that we can load it.
30
	 */
31
	function enqueue_package_class( $class_name, $version, $path ) {
32
		global $jetpack_packages_classes;
33
34
		if ( ! isset( $jetpack_packages_classes[ $class_name ] ) ) {
35
			$jetpack_packages_classes[ $class_name ] = array(
36
				'version' => $version,
37
				'path'    => $path,
38
			);
39
		}
40
		// If we have a @dev version set always use that one!
41
		if ( 'dev-' === substr( $jetpack_packages_classes[ $class_name ]['version'], 0, 4 ) ) {
42
			return;
43
		}
44
45
		// Always favour the @dev version. Since that version is the same as bleeding edge.
46
		// We need to make sure that we don't do this in production!
47
		if ( 'dev-' === substr( $version, 0, 4 ) ) {
48
			$jetpack_packages_classes[ $class_name ] = array(
49
				'version' => $version,
50
				'path'    => $path,
51
			);
52
53
			return;
54
		}
55
		// Set the latest version!
56
		if ( version_compare( $jetpack_packages_classes[ $class_name ]['version'], $version, '<' ) ) {
57
			$jetpack_packages_classes[ $class_name ] = array(
58
				'version' => $version,
59
				'path'    => $path,
60
			);
61
		}
62
	}
63
}
64
65
if ( ! function_exists( __NAMESPACE__ . '\autoloader' ) ) {
66
	/**
67
	 * Used for autoloading jetpack packages.
68
	 *
69
	 * @param string $class_name Class Name to load.
70
	 */
71
	function autoloader( $class_name ) {
72
		global $jetpack_packages_classes;
73
74
		if ( isset( $jetpack_packages_classes[ $class_name ] ) ) {
75
			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
76
				if ( function_exists( 'did_action' ) && ! did_action( 'plugins_loaded' ) ) {
77
					_doing_it_wrong(
78
						esc_html( $class_name ),
79
						sprintf(
80
							/* translators: %s Name of a PHP Class */
81
							esc_html__( 'Not all plugins have loaded yet but we requested the class %s', 'jetpack' ),
82
							// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
83
							$class_name
84
						),
85
						esc_html( $jetpack_packages_classes[ $class_name ]['version'] )
86
					);
87
				}
88
			}
89
90
			if ( file_exists( $jetpack_packages_classes[ $class_name ]['path'] ) ) {
91
				require_once $jetpack_packages_classes[ $class_name ]['path'];
92
93
				return true;
94
			}
95
		}
96
97
		return false;
98
	}
99
100
	// Add the jetpack autoloader.
101
	spl_autoload_register( __NAMESPACE__ . '\autoloader' );
102
}
103