Make WordPress Core


Ignore:
Timestamp:
08/27/2016 09:15:01 AM (9 years ago)
Author:
wonderboymusic
Message:

Bootstrap: Autoload classes using a Composer-generated PHP 5.2-compatible Autoloader.

  • wp-admin and wp-includes are scanned for classes to autoload
  • Several 3rd-party and Ryan McCue-shaped libraries are excluded when the classmap is generated, see composer.json: autoload.exclude-from-classmap
  • wp-vendor/autoload_52.php is included at the top of wp-settings.php - no changes need to be made to unit tests to include the autoloader
  • An avalanche of require() and require_once() calls that loaded class files have been removed from the codebase.

The following files have been added to svn:ignore - they are not 5.2-compatible and fail during pre-commit:

  • src/wp-vendor/autoload.php
  • src/wp-vendor/composer/autoload_real.php
  • src/wp-vendor/composer/autoload_static.php
  • src/wp-vendor/composer/ClassLoader.php

We favor these files instead:

  • src/wp-vendor/autoload_52.php
  • src/wp-vendor/composer/autoload_real_52.php
  • src/wp-vendor/composer/ClassLoader52.php

When new PHP classes are added to the codebase, simply run composer install or composer update from the project root to update the autoloader.

The future is now.

See #36335.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r38294 r38399  
    738738    mbstring_binary_safe_encoding();
    739739
    740     require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
    741 
    742740    $archive = new PclZip($file);
    743741
     
    887885    global $wp_filesystem;
    888886
    889     require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
    890 
    891887    $method = get_filesystem_method( $args, $context, $allow_relaxed_file_ownership );
    892888
     
    894890        return false;
    895891
    896     if ( ! class_exists( "WP_Filesystem_$method" ) ) {
     892    $map = array(
     893        'base' => 'WP_Filesystem_Base',
     894        'direct' => 'WP_Filesystem_Direct',
     895        'ftpext' => 'WP_Filesystem_FTPext',
     896        'ftpsockets' => 'WP_Filesystem_ftpsockets',
     897        'ssh2' => 'WP_Filesystem_SSH2',
     898    );
     899
     900    $l = strtolower( $method );
     901    if ( array_key_exists( $l, $map ) ) {
     902        $classname = $map[ $l ];
     903    } else {
     904        $classname = "WP_Filesystem_{$method}";
     905    }
     906
     907    if ( ! class_exists( $classname ) ) {
    897908
    898909        /**
     
    908919        $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
    909920
    910         if ( ! file_exists($abstraction_file) )
     921        if ( ! file_exists( $abstraction_file ) ) {
    911922            return;
    912 
    913         require_once($abstraction_file);
    914     }
    915     $method = "WP_Filesystem_$method";
    916 
    917     $wp_filesystem = new $method($args);
     923        }
     924
     925        require_once( $abstraction_file );
     926    }
     927
     928    $wp_filesystem = new $classname( $args );
    918929
    919930    //Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default.
Note: See TracChangeset for help on using the changeset viewer.