Test version without custom autoloader and allow core to generate this after install

This commit is contained in:
Mike Jolley 2019-06-20 13:37:59 +01:00
parent acfaf1a284
commit 9283910e11
5 changed files with 7 additions and 209 deletions

1
.gitattributes vendored
View File

@ -1,5 +1,4 @@
/.* export-ignore /.* export-ignore
classmap.php.bak export-ignore
phpcs.xml export-ignore phpcs.xml export-ignore
phpunit.* export-ignore phpunit.* export-ignore
unit-tests export-ignore unit-tests export-ignore

View File

@ -1,104 +0,0 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = __DIR__;
return array(
'WC_REST_CRUD_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-crud-controller.php',
'WC_REST_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-controller.php',
'WC_REST_Coupons_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-coupons-controller.php',
'WC_REST_Coupons_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-coupons-v1-controller.php',
'WC_REST_Coupons_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php',
'WC_REST_Customer_Downloads_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-customer-downloads-controller.php',
'WC_REST_Customer_Downloads_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-customer-downloads-v1-controller.php',
'WC_REST_Customer_Downloads_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-customer-downloads-v2-controller.php',
'WC_REST_Customers_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-customers-controller.php',
'WC_REST_Customers_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-customers-v1-controller.php',
'WC_REST_Customers_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-customers-v2-controller.php',
'WC_REST_Data_Continents_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-data-continents-controller.php',
'WC_REST_Data_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-data-controller.php',
'WC_REST_Data_Countries_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-data-countries-controller.php',
'WC_REST_Data_Currencies_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-data-currencies-controller.php',
'WC_REST_Network_Orders_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-network-orders-controller.php',
'WC_REST_Network_Orders_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-network-orders-v2-controller.php',
'WC_REST_Order_Notes_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-order-notes-controller.php',
'WC_REST_Order_Notes_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-order-notes-v1-controller.php',
'WC_REST_Order_Notes_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-order-notes-v2-controller.php',
'WC_REST_Order_Refunds_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-order-refunds-controller.php',
'WC_REST_Order_Refunds_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-order-refunds-v1-controller.php',
'WC_REST_Order_Refunds_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php',
'WC_REST_Orders_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-orders-controller.php',
'WC_REST_Orders_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-orders-v1-controller.php',
'WC_REST_Orders_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-orders-v2-controller.php',
'WC_REST_Payment_Gateways_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-payment-gateways-controller.php',
'WC_REST_Payment_Gateways_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-payment-gateways-v2-controller.php',
'WC_REST_Posts_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-posts-controller.php',
'WC_REST_Product_Attribute_Terms_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-attribute-terms-controller.php',
'WC_REST_Product_Attribute_Terms_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-attribute-terms-v1-controller.php',
'WC_REST_Product_Attribute_Terms_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-attribute-terms-v2-controller.php',
'WC_REST_Product_Attributes_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-attributes-controller.php',
'WC_REST_Product_Attributes_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-attributes-v1-controller.php',
'WC_REST_Product_Attributes_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-attributes-v2-controller.php',
'WC_REST_Product_Categories_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-categories-controller.php',
'WC_REST_Product_Categories_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-categories-v1-controller.php',
'WC_REST_Product_Categories_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-categories-v2-controller.php',
'WC_REST_Product_Reviews_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-reviews-controller.php',
'WC_REST_Product_Reviews_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-reviews-v1-controller.php',
'WC_REST_Product_Reviews_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-reviews-v2-controller.php',
'WC_REST_Product_Shipping_Classes_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-shipping-classes-controller.php',
'WC_REST_Product_Shipping_Classes_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-shipping-classes-v1-controller.php',
'WC_REST_Product_Shipping_Classes_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-shipping-classes-v2-controller.php',
'WC_REST_Product_Tags_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-tags-controller.php',
'WC_REST_Product_Tags_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-product-tags-v1-controller.php',
'WC_REST_Product_Tags_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-tags-v2-controller.php',
'WC_REST_Product_Variations_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-product-variations-controller.php',
'WC_REST_Product_Variations_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php',
'WC_REST_Products_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-products-controller.php',
'WC_REST_Products_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-products-v1-controller.php',
'WC_REST_Products_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-products-v2-controller.php',
'WC_REST_Report_Coupons_Totals_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-coupons-totals-controller.php',
'WC_REST_Report_Customers_Totals_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-customers-totals-controller.php',
'WC_REST_Report_Orders_Totals_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-orders-totals-controller.php',
'WC_REST_Report_Products_Totals_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-products-totals-controller.php',
'WC_REST_Report_Reviews_Totals_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-reviews-totals-controller.php',
'WC_REST_Report_Sales_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-sales-controller.php',
'WC_REST_Report_Sales_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-report-sales-v1-controller.php',
'WC_REST_Report_Sales_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-report-sales-v2-controller.php',
'WC_REST_Report_Top_Sellers_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-report-top-sellers-controller.php',
'WC_REST_Report_Top_Sellers_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-report-top-sellers-v1-controller.php',
'WC_REST_Report_Top_Sellers_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-report-top-sellers-v2-controller.php',
'WC_REST_Reports_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-reports-controller.php',
'WC_REST_Reports_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-reports-v1-controller.php',
'WC_REST_Reports_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-reports-v2-controller.php',
'WC_REST_Setting_Options_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-setting-options-controller.php',
'WC_REST_Setting_Options_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php',
'WC_REST_Settings_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-settings-controller.php',
'WC_REST_Settings_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-settings-v2-controller.php',
'WC_REST_Shipping_Methods_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-shipping-methods-controller.php',
'WC_REST_Shipping_Methods_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-shipping-methods-v2-controller.php',
'WC_REST_Shipping_Zone_Locations_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-shipping-zone-locations-controller.php',
'WC_REST_Shipping_Zone_Locations_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-shipping-zone-locations-v2-controller.php',
'WC_REST_Shipping_Zone_Methods_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-shipping-zone-methods-controller.php',
'WC_REST_Shipping_Zone_Methods_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-shipping-zone-methods-v2-controller.php',
'WC_REST_Shipping_Zones_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-shipping-zones-controller.php',
'WC_REST_Shipping_Zones_Controller_Base' => $baseDir . '/src/Controllers/Version3/class-wc-rest-shipping-zones-controller-base.php',
'WC_REST_Shipping_Zones_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-shipping-zones-v2-controller.php',
'WC_REST_System_Status_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-system-status-controller.php',
'WC_REST_System_Status_Tools_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-system-status-tools-controller.php',
'WC_REST_System_Status_Tools_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php',
'WC_REST_System_Status_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-system-status-v2-controller.php',
'WC_REST_Tax_Classes_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-tax-classes-controller.php',
'WC_REST_Tax_Classes_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-tax-classes-v1-controller.php',
'WC_REST_Tax_Classes_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-tax-classes-v2-controller.php',
'WC_REST_Taxes_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-taxes-controller.php',
'WC_REST_Taxes_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-taxes-v1-controller.php',
'WC_REST_Taxes_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-taxes-v2-controller.php',
'WC_REST_Terms_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-terms-controller.php',
'WC_REST_Webhook_Deliveries_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-webhook-deliveries-v1-controller.php',
'WC_REST_Webhook_Deliveries_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-webhook-deliveries-v2-controller.php',
'WC_REST_Webhooks_Controller' => $baseDir . '/src/Controllers/Version3/class-wc-rest-webhooks-controller.php',
'WC_REST_Webhooks_V1_Controller' => $baseDir . '/src/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php',
'WC_REST_Webhooks_V2_Controller' => $baseDir . '/src/Controllers/Version2/class-wc-rest-webhooks-v2-controller.php',
);

View File

@ -8,8 +8,7 @@
"minimum-stability": "dev", "minimum-stability": "dev",
"require-dev": { "require-dev": {
"phpunit/phpunit": "6.5.14", "phpunit/phpunit": "6.5.14",
"woocommerce/woocommerce-sniffs": "0.0.6", "woocommerce/woocommerce-sniffs": "0.0.6"
"slowprog/composer-copy-file": "~0.3"
}, },
"scripts": { "scripts": {
"post-install-cmd": [ "post-install-cmd": [
@ -17,12 +16,6 @@
], ],
"post-update-cmd": [ "post-update-cmd": [
"composer dump-autoload" "composer dump-autoload"
],
"pre-autoload-dump": [
"composer dump-autoload --no-dev --no-scripts",
"SlowProg\\CopyFile\\ScriptHandler::copy",
"sed -i.bak -e 's/\\$baseDir = dirname(\\$vendorDir)/\\$baseDir = __DIR__/g' classmap.php",
"rm classmap.php.bak"
] ]
}, },
"autoload": { "autoload": {
@ -30,14 +23,9 @@
"src/Controllers/Version1", "src/Controllers/Version1",
"src/Controllers/Version2", "src/Controllers/Version2",
"src/Controllers/Version3" "src/Controllers/Version3"
] ],
}, "psr-4": {
"extra": { "WooCommerce\\RestApi\\": "src/"
"copy-file": {
"vendor/composer/autoload_classmap.php": "classmap.php"
},
"copy-file-dev": {
"vendor/composer/autoload_classmap.php": "classmap.php"
} }
} }
} }

View File

@ -6,12 +6,9 @@
*/ */
return function() { return function() {
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php'; return;
} else {
require __DIR__ . '/src/Autoloader.php';
$classmap = require 'classmap.php';
\WooCommerce\RestApi\Autoloader::register( $classmap );
} }
require __DIR__ . '/vendor/autoload.php';
\WooCommerce\RestApi\Server::instance()->init(); \WooCommerce\RestApi\Server::instance()->init();
}; };

View File

@ -1,82 +0,0 @@
<?php
/**
* Custom Autoloader used when included inside another project as a package.
*
* Since this package can be included multiple times, but we want to ensure the latest version
* is loaded (rather than the first package found), we need a custom autoloader.
*
* This autoloader is only loaded for the chosen (latest) package.
*
* For version 4 onwards, we use psr-4 class naming.
* For version 3 and below, we use a classmap to maintain class naming/backwards compatibility.
*
* @package WooCommerce/RestApi
*/
namespace WooCommerce\RestApi;
defined( 'ABSPATH' ) || exit;
/**
* Autoloader class.
*/
class Autoloader {
/**
* Holds the classmap.
*
* @var array
*/
protected static $classmap = [];
/**
* Register the autoloader.
*
* @param array $classmap Classmap of files to include.
*/
public static function register( $classmap ) {
self::$classmap = (array) $classmap;
spl_autoload_register( array( __CLASS__, 'autoload_class' ) );
}
/**
* Try to autoload a class.
*
* @param string $class Class being autoloaded.
* @return boolean
*/
public static function autoload_class( $class ) {
$prefix = 'WooCommerce\\RestApi\\';
$base_dir = __DIR__ . '/';
// does the class use the namespace prefix?
$len = strlen( $prefix );
if ( strncmp( $prefix, $class, $len ) !== 0 ) {
return self::autoload_from_classmap( $class );
}
$relative_class = substr( $class, $len );
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
if ( file_exists( $file ) ) {
return include $file;
}
}
/**
* Try to autoload a class from a classmap.
*
* @param string $class Class being autoloaded.
* @return boolean
*/
protected static function autoload_from_classmap( $class ) {
if ( empty( self::$classmap ) ) {
return false;
}
if ( array_key_exists( $class, self::$classmap ) ) {
return include self::$classmap[ $class ];
}
}
}