Remove old autoloader
This commit is contained in:
parent
e6405ba7bc
commit
d8fb17a0ed
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Custom Autoloader specifically for the REST API.
|
||||
*
|
||||
* This allows us to handle multiple versions (those registered, and the
|
||||
* version in core) so only classes from the latest version are used.
|
||||
*
|
||||
* Uses the class-map file generated by composer.
|
||||
*
|
||||
* @package WooCommerce/Rest_Api
|
||||
*/
|
||||
|
||||
namespace WooCommerce\Rest_Api;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WooCommerce\Rest_Api\Singleton;
|
||||
|
||||
/**
|
||||
* Autoload class.
|
||||
*/
|
||||
class Autoload {
|
||||
use Singleton;
|
||||
|
||||
/**
|
||||
* Hook into WordPress ready to init the REST API as needed.
|
||||
*/
|
||||
public function init() {
|
||||
spl_autoload_register( array( $this, 'autoload' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Autoloader.
|
||||
*
|
||||
* @param string $class Classname.
|
||||
*/
|
||||
public function autoload( $class ) {
|
||||
$class = str_replace( '\\', DIRECTORY_SEPARATOR, str_replace( '\\' . __NAMESPACE__ . '\\', '', $class ) );
|
||||
$file = $this->get_file_name_from_class( $class );
|
||||
$dir = trailingslashit( dirname( __FILE__ ) );
|
||||
|
||||
// Non-namespaced files.
|
||||
if ( stristr( $class, 'WC_REST_' ) ) {
|
||||
if ( stristr( $class, 'WC_REST_Blocks' ) ) {
|
||||
$subdir = 'wc-blocks/';
|
||||
} elseif ( stristr( $class, '_V1_' ) ) {
|
||||
$subdir = 'v1/';
|
||||
} elseif ( stristr( $class, '_V2_' ) ) {
|
||||
$subdir = 'v2/';
|
||||
} else {
|
||||
$subdir = 'v3/';
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $subdir . $file ) ) {
|
||||
include $dir . $subdir . $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $class . '.php' ) ) {
|
||||
include $dir . $class . '.php';
|
||||
return;
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $file ) ) {
|
||||
include $dir . $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,10 @@ namespace WooCommerce;
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
}
|
||||
|
||||
use WooCommerce\Utilities\SingletonTrait;
|
||||
|
||||
/**
|
||||
|
@ -28,10 +32,6 @@ class RestApi {
|
|||
* Hook into WordPress ready to init the REST API as needed.
|
||||
*/
|
||||
public function init() {
|
||||
// Get the autoloader for this version of the API.
|
||||
if ( file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
}
|
||||
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue