Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/StoreApi
File: StoreApi.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\StoreApi;
[1] Fix | Delete
[2] Fix | Delete
use Automattic\WooCommerce\Blocks\Registry\Container;
[3] Fix | Delete
use Automattic\WooCommerce\StoreApi\Formatters;
[4] Fix | Delete
use Automattic\WooCommerce\StoreApi\Authentication;
[5] Fix | Delete
use Automattic\WooCommerce\StoreApi\Legacy;
[6] Fix | Delete
use Automattic\WooCommerce\StoreApi\Formatters\CurrencyFormatter;
[7] Fix | Delete
use Automattic\WooCommerce\StoreApi\Formatters\HtmlFormatter;
[8] Fix | Delete
use Automattic\WooCommerce\StoreApi\Formatters\MoneyFormatter;
[9] Fix | Delete
use Automattic\WooCommerce\StoreApi\RoutesController;
[10] Fix | Delete
use Automattic\WooCommerce\StoreApi\SchemaController;
[11] Fix | Delete
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* StoreApi Main Class.
[15] Fix | Delete
*/
[16] Fix | Delete
final class StoreApi {
[17] Fix | Delete
/**
[18] Fix | Delete
* Init and hook in Store API functionality.
[19] Fix | Delete
*/
[20] Fix | Delete
public function init() {
[21] Fix | Delete
add_action(
[22] Fix | Delete
'rest_api_init',
[23] Fix | Delete
function () {
[24] Fix | Delete
if ( ! wc_rest_should_load_namespace( 'wc/store' ) && ! wc_rest_should_load_namespace( 'wc/private' ) ) {
[25] Fix | Delete
return;
[26] Fix | Delete
}
[27] Fix | Delete
self::container()->get( Legacy::class )->init();
[28] Fix | Delete
self::container()->get( RoutesController::class )->register_all_routes();
[29] Fix | Delete
}
[30] Fix | Delete
);
[31] Fix | Delete
// Runs on priority 11 after rest_api_default_filters() which is hooked at 10.
[32] Fix | Delete
add_action(
[33] Fix | Delete
'rest_api_init',
[34] Fix | Delete
function () {
[35] Fix | Delete
if ( ! wc_rest_should_load_namespace( 'wc/store' ) ) {
[36] Fix | Delete
return;
[37] Fix | Delete
}
[38] Fix | Delete
self::container()->get( Authentication::class )->init();
[39] Fix | Delete
},
[40] Fix | Delete
11
[41] Fix | Delete
);
[42] Fix | Delete
[43] Fix | Delete
add_action(
[44] Fix | Delete
'woocommerce_blocks_pre_get_routes_from_namespace',
[45] Fix | Delete
function ( $routes, $ns ) {
[46] Fix | Delete
if ( 'wc/store/v1' !== $ns ) {
[47] Fix | Delete
return $routes;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$routes = array_merge(
[51] Fix | Delete
$routes,
[52] Fix | Delete
self::container()->get( RoutesController::class )->get_all_routes( 'v1' )
[53] Fix | Delete
);
[54] Fix | Delete
[55] Fix | Delete
return $routes;
[56] Fix | Delete
},
[57] Fix | Delete
10,
[58] Fix | Delete
2
[59] Fix | Delete
);
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Loads the DI container for Store API.
[64] Fix | Delete
*
[65] Fix | Delete
* @internal This uses the Blocks DI container. If Store API were to move to core, this container could be replaced
[66] Fix | Delete
* with a different compatible container.
[67] Fix | Delete
*
[68] Fix | Delete
* @param boolean $reset Used to reset the container to a fresh instance. Note: this means all dependencies will be reconstructed.
[69] Fix | Delete
* @return mixed
[70] Fix | Delete
*/
[71] Fix | Delete
public static function container( $reset = false ) {
[72] Fix | Delete
static $container;
[73] Fix | Delete
[74] Fix | Delete
if ( $reset ) {
[75] Fix | Delete
$container = null;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
if ( $container ) {
[79] Fix | Delete
return $container;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
$container = new Container();
[83] Fix | Delete
$container->register(
[84] Fix | Delete
Authentication::class,
[85] Fix | Delete
function () {
[86] Fix | Delete
return new Authentication();
[87] Fix | Delete
}
[88] Fix | Delete
);
[89] Fix | Delete
$container->register(
[90] Fix | Delete
Legacy::class,
[91] Fix | Delete
function () {
[92] Fix | Delete
return new Legacy();
[93] Fix | Delete
}
[94] Fix | Delete
);
[95] Fix | Delete
$container->register(
[96] Fix | Delete
RoutesController::class,
[97] Fix | Delete
function ( $container ) {
[98] Fix | Delete
return new RoutesController(
[99] Fix | Delete
$container->get( SchemaController::class )
[100] Fix | Delete
);
[101] Fix | Delete
}
[102] Fix | Delete
);
[103] Fix | Delete
$container->register(
[104] Fix | Delete
SchemaController::class,
[105] Fix | Delete
function ( $container ) {
[106] Fix | Delete
return new SchemaController(
[107] Fix | Delete
$container->get( ExtendSchema::class )
[108] Fix | Delete
);
[109] Fix | Delete
}
[110] Fix | Delete
);
[111] Fix | Delete
$container->register(
[112] Fix | Delete
ExtendSchema::class,
[113] Fix | Delete
function ( $container ) {
[114] Fix | Delete
return new ExtendSchema(
[115] Fix | Delete
$container->get( Formatters::class )
[116] Fix | Delete
);
[117] Fix | Delete
}
[118] Fix | Delete
);
[119] Fix | Delete
$container->register(
[120] Fix | Delete
Formatters::class,
[121] Fix | Delete
function () {
[122] Fix | Delete
$formatters = new Formatters();
[123] Fix | Delete
$formatters->register( 'money', MoneyFormatter::class );
[124] Fix | Delete
$formatters->register( 'html', HtmlFormatter::class );
[125] Fix | Delete
$formatters->register( 'currency', CurrencyFormatter::class );
[126] Fix | Delete
return $formatters;
[127] Fix | Delete
}
[128] Fix | Delete
);
[129] Fix | Delete
return $container;
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function