automattic
6 years ago
composer
6 years ago
autoload.php
6 years ago
autoload_packages.php
6 years ago
autoload_packages.php
130 lines
| 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 | // TODO ideally we shouldn't skip any of these, see: https://github.com/Automattic/jetpack/pull/12646. |
| 77 | $ignore = in_array( |
| 78 | $class_name, |
| 79 | array( |
| 80 | 'Automattic\Jetpack\JITM', |
| 81 | 'Automattic\Jetpack\Connection\Manager', |
| 82 | 'Automattic\Jetpack\Connection\Manager_Interface', |
| 83 | 'Automattic\Jetpack\Connection\XMLRPC_Connector', |
| 84 | 'Jetpack_Options', |
| 85 | 'Jetpack_Signature', |
| 86 | 'Automattic\Jetpack\Sync\Main', |
| 87 | 'Automattic\Jetpack\Constants', |
| 88 | 'Automattic\Jetpack\Tracking', |
| 89 | 'Automattic\Jetpack\Plugin\Tracking', |
| 90 | ), |
| 91 | true |
| 92 | ); |
| 93 | if ( ! $ignore && function_exists( 'did_action' ) && ! did_action( 'plugins_loaded' ) ) { |
| 94 | _doing_it_wrong( |
| 95 | esc_html( $class_name ), |
| 96 | sprintf( |
| 97 | /* translators: %s Name of a PHP Class */ |
| 98 | esc_html__( 'Not all plugins have loaded yet but we requested the class %s', 'jetpack' ), |
| 99 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 100 | $class_name |
| 101 | ), |
| 102 | esc_html( $jetpack_packages_classes[ $class_name ]['version'] ) |
| 103 | ); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if ( file_exists( $jetpack_packages_classes[ $class_name ]['path'] ) ) { |
| 108 | require_once $jetpack_packages_classes[ $class_name ]['path']; |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | // Add the jetpack autoloader. |
| 118 | spl_autoload_register( __NAMESPACE__ . '\autoloader' ); |
| 119 | } |
| 120 | /** |
| 121 | * Prepare all the classes for autoloading. |
| 122 | */ |
| 123 | function enqueue_packages_67b4dc326b951b44846b2b0eeab5f3c2() { |
| 124 | $class_map = require_once dirname( __FILE__ ) . '/composer/autoload_classmap_package.php'; |
| 125 | foreach ( $class_map as $class_name => $class_info ) { |
| 126 | enqueue_package_class( $class_name, $class_info['version'], $class_info['path'] ); |
| 127 | } |
| 128 | } |
| 129 | enqueue_packages_67b4dc326b951b44846b2b0eeab5f3c2(); |
| 130 |