• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
    • Help
      • Online help
      • Learn Git
      • Welcome to Bitbucket
      • Keyboard shortcuts
    • Log In
    Blackrock
    1. Blackrock

    main

    Public
    Actions
    • Clone

    Learn more about cloning repositories

    You have read-only access

    Navigation
    • Source
    • Commits
    • Branches
    • All Branches Graph
    • Graphs
    • Forks
    1. Blackrock
    2. main

    Source

    main/wp-content/plugins/woocommerce-admin/vendor/automattic/jetpack-autoloader/src/class-php-autoloader.php
    Артем ШиряевАртем Ширяев committed 554847ddcb906 Apr 2021
    Raw file
    Source viewDiff to previous
     
    1
    <?php
    2
    /* HEADER */ // phpcs:ignore
    3
    ​
    4
    /**
    5
     * This class handles management of the actual PHP autoloader.
    6
     */
    7
    class PHP_Autoloader {
    8
    ​
    9
        /**
    10
         * Registers the autoloader with PHP so that it can begin autoloading classes.
    11
         *
    12
         * @param Version_Loader $version_loader The class loader to use in the autoloader.
    13
         */
    14
        public function register_autoloader( $version_loader ) {
    15
            // Make sure no other autoloaders are registered.
    16
            $this->unregister_autoloader();
    17
    ​
    18
            // Set the global so that it can be used to load classes.
    19
            global $jetpack_autoloader_loader;
    20
            $jetpack_autoloader_loader = $version_loader;
    21
    ​
    22
            // Ensure that the autoloader is first to avoid contention with others.
    23
            spl_autoload_register( array( self::class, 'load_class' ), true, true );
    24
        }
    25
    ​
    26
        /**
    27
         * Unregisters the active autoloader so that it will no longer autoload classes.
    28
         */
    29
        public function unregister_autoloader() {
    30
            // Remove any v2 autoloader that we've already registered.
    31
            $autoload_chain = spl_autoload_functions();
    32
            foreach ( $autoload_chain as $autoloader ) {
    33
                // We can identify a v2 autoloader using the namespace.
    34
                $namespace_check = null;
    35
    ​
    36
                // Functions are recorded as strings.
    37
                if ( is_string( $autoloader ) ) {
    38
                    $namespace_check = $autoloader;
    39
                } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) {
    40
                    // Static method calls have the class as the first array element.
    41
                    $namespace_check = $autoloader[0];
    42
                } else {
    43
                    // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else.
    44
                    continue;
    45
                }
    46
    ​
    47
                // Check for the namespace without the generated suffix.
    48
                if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) {
    49
                    spl_autoload_unregister( $autoloader );
    50
                }
    51
            }
    52
    ​
    53
            // Clear the global now that the autoloader has been unregistered.
    54
            global $jetpack_autoloader_loader;
    55
            $jetpack_autoloader_loader = null;
    56
        }
    57
    ​
    58
        /**
    59
         * Loads a class file if one could be found.
    60
         *
    61
         * Note: This function is static so that the autoloader can be easily unregistered. If
    62
         * it was a class method we would have to unwrap the object to check the namespace.
    63
         *
    • Git repository management for enterprise teams powered by Atlassian Bitbucket
    • Atlassian Bitbucket v5.10.1
    • Documentation
    • Contact Support
    • Request a feature
    • About
    • Contact Atlassian
    Atlassian

    Everything looks good. Well let you know here if theres anything you should know about.