| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.4/wp-content/plugins/woocommerce/src/StoreApi/ |
Upload File : |
<?php
namespace Automattic\WooCommerce\StoreApi;
use Automattic\WooCommerce\Blocks\Registry\Container;
use Automattic\WooCommerce\StoreApi\Formatters;
use Automattic\WooCommerce\StoreApi\Authentication;
use Automattic\WooCommerce\StoreApi\Legacy;
use Automattic\WooCommerce\StoreApi\Formatters\CurrencyFormatter;
use Automattic\WooCommerce\StoreApi\Formatters\HtmlFormatter;
use Automattic\WooCommerce\StoreApi\Formatters\MoneyFormatter;
use Automattic\WooCommerce\StoreApi\RoutesController;
use Automattic\WooCommerce\StoreApi\SchemaController;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
/**
* StoreApi Main Class.
*/
final class StoreApi {
/**
* Init and hook in Store API functionality.
*/
public function init() {
/**
* Authentication instance.
*
* @var Authentication $authentication
*/
$authentication = self::container()->get( Authentication::class );
add_filter( 'woocommerce_session_handler', array( $authentication, 'maybe_use_store_api_session_handler' ), 0 );
add_action(
'rest_api_init',
function () {
if ( ! wc_rest_should_load_namespace( 'wc/store' ) && ! wc_rest_should_load_namespace( 'wc/private' ) ) {
return;
}
self::container()->get( Legacy::class )->init();
self::container()->get( RoutesController::class )->register_all_routes();
}
);
// Runs on priority 11 after rest_api_default_filters() which is hooked at 10.
add_action(
'rest_api_init',
function () {
if ( ! wc_rest_should_load_namespace( 'wc/store' ) ) {
return;
}
self::container()->get( Authentication::class )->init();
},
11
);
add_action(
'woocommerce_blocks_pre_get_routes_from_namespace',
function ( $routes, $ns ) {
if ( 'wc/store/v1' !== $ns ) {
return $routes;
}
$routes = array_merge(
$routes,
self::container()->get( RoutesController::class )->get_all_routes( 'v1' )
);
return $routes;
},
10,
2
);
}
/**
* Loads the DI container for Store API.
*
* @internal This uses the Blocks DI container. If Store API were to move to core, this container could be replaced
* with a different compatible container.
*
* @param boolean $reset Used to reset the container to a fresh instance. Note: this means all dependencies will be reconstructed.
* @return mixed
*/
public static function container( $reset = false ) {
static $container;
if ( $reset ) {
$container = null;
}
if ( $container ) {
return $container;
}
$container = new Container();
$container->register(
Authentication::class,
function () {
return new Authentication();
}
);
$container->register(
Legacy::class,
function () {
return new Legacy();
}
);
$container->register(
RoutesController::class,
function ( $container ) {
return new RoutesController(
$container->get( SchemaController::class )
);
}
);
$container->register(
SchemaController::class,
function ( $container ) {
return new SchemaController(
$container->get( ExtendSchema::class )
);
}
);
$container->register(
ExtendSchema::class,
function ( $container ) {
return new ExtendSchema(
$container->get( Formatters::class )
);
}
);
$container->register(
Formatters::class,
function () {
$formatters = new Formatters();
$formatters->register( 'money', MoneyFormatter::class );
$formatters->register( 'html', HtmlFormatter::class );
$formatters->register( 'currency', CurrencyFormatter::class );
return $formatters;
}
);
return $container;
}
}