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.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Blocks / Domain / Bootstrap.php
woocommerce / src / Blocks / Domain Last commit date
Services 2 months ago Bootstrap.php 5 months ago Package.php 1 year ago
Bootstrap.php
513 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\Domain;
3
4 use Automattic\Jetpack\Constants;
5 use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi;
6 use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
7 use Automattic\WooCommerce\Blocks\AssetsController;
8 use Automattic\WooCommerce\Blocks\BlockPatterns;
9 use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
10 use Automattic\WooCommerce\Blocks\BlockTemplatesController;
11 use Automattic\WooCommerce\Blocks\BlockTypesController;
12 use Automattic\WooCommerce\Blocks\DependencyDetection;
13 use Automattic\WooCommerce\Blocks\Patterns\AIPatterns;
14 use Automattic\WooCommerce\Blocks\Patterns\PatternRegistry;
15 use Automattic\WooCommerce\Blocks\Patterns\PTKClient;
16 use Automattic\WooCommerce\Blocks\Patterns\PTKPatternsStore;
17 use Automattic\WooCommerce\Blocks\QueryFilters;
18 use Automattic\WooCommerce\Blocks\Domain\Services\Notices;
19 use Automattic\WooCommerce\Blocks\Domain\Services\DraftOrders;
20 use Automattic\WooCommerce\Blocks\Domain\Services\GoogleAnalytics;
21 use Automattic\WooCommerce\Blocks\Domain\Services\Hydration;
22 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
23 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldsAdmin;
24 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldsFrontend;
25 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutLink;
26 use Automattic\WooCommerce\Blocks\InboxNotifications;
27 use Automattic\WooCommerce\Blocks\Installer;
28 use Automattic\WooCommerce\Blocks\Payments\Api as PaymentsApi;
29 use Automattic\WooCommerce\Blocks\Payments\Integrations\BankTransfer;
30 use Automattic\WooCommerce\Blocks\Payments\Integrations\CashOnDelivery;
31 use Automattic\WooCommerce\Blocks\Payments\Integrations\Cheque;
32 use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal;
33 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
34 use Automattic\WooCommerce\Blocks\Registry\Container;
35 use Automattic\WooCommerce\Blocks\Templates\ClassicTemplatesCompatibility;
36 use Automattic\WooCommerce\StoreApi\RoutesController;
37 use Automattic\WooCommerce\StoreApi\SchemaController;
38 use Automattic\WooCommerce\StoreApi\StoreApi;
39 use Automattic\WooCommerce\Blocks\Shipping\ShippingController;
40 use Automattic\WooCommerce\Blocks\TemplateOptions;
41
42
43 /**
44 * Takes care of bootstrapping the plugin.
45 *
46 * @since 2.5.0
47 */
48 class Bootstrap {
49
50 /**
51 * Holds the Dependency Injection Container
52 *
53 * @var Container
54 */
55 private $container;
56
57 /**
58 * Holds the Package instance
59 *
60 * @var Package
61 */
62 private $package;
63
64 /**
65 * Constructor
66 *
67 * @param Container $container The Dependency Injection Container.
68 */
69 public function __construct( Container $container ) {
70 $this->container = $container;
71 $this->package = $container->get( Package::class );
72
73 $this->init();
74 /**
75 * Fires when the woocommerce blocks are loaded and ready to use.
76 *
77 * This hook is intended to be used as a safe event hook for when the plugin
78 * has been loaded, and all dependency requirements have been met.
79 *
80 * To ensure blocks are initialized, you must use the `woocommerce_blocks_loaded`
81 * hook instead of the `plugins_loaded` hook. This is because the functions
82 * hooked into plugins_loaded on the same priority load in an inconsistent and unpredictable manner.
83 *
84 * @since 2.5.0
85 */
86 do_action( 'woocommerce_blocks_loaded' );
87 }
88
89 /**
90 * Init the package - load the blocks library and define constants.
91 */
92 protected function init() {
93 $this->register_dependencies();
94 $this->register_payment_methods();
95
96 add_action(
97 'admin_init',
98 function () {
99 // Delete this notification because the blocks are included in WC Core now. This will handle any sites
100 // with lingering notices.
101 InboxNotifications::delete_surface_cart_checkout_blocks_notification();
102 },
103 10,
104 0
105 );
106
107 // We need to initialize BlockTemplatesController and BlockTemplatesRegistry at the end of `after_setup_theme`
108 // so themes had the opportunity to declare support for template parts.
109 add_action(
110 'after_setup_theme',
111 function () {
112 $is_store_api_request = wc()->is_store_api_request();
113
114 if ( ! $is_store_api_request && ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) ) {
115 $this->container->get( BlockTemplatesRegistry::class )->init();
116 $this->container->get( BlockTemplatesController::class )->init();
117 }
118 },
119 999
120 );
121
122 $is_rest = wc()->is_rest_api_request();
123 $is_store_api_request = wc()->is_store_api_request();
124
125 // Initialize Store API in non-admin context.
126 if ( ! is_admin() ) {
127 $this->container->get( StoreApi::class )->init();
128 }
129
130 // Load and init assets.
131 $this->container->get( PaymentsApi::class )->init();
132 $this->container->get( DraftOrders::class )->init();
133 $this->container->get( ShippingController::class )->init();
134 $this->container->get( CheckoutFields::class )->init();
135 $this->container->get( CheckoutLink::class )->init();
136 $this->container->get( AssetDataRegistry::class );
137 $this->container->get( AssetsController::class );
138 $this->container->get( DependencyDetection::class );
139
140 // Load assets in admin and on the frontend.
141 if ( ! $is_rest ) {
142 $this->add_build_notice();
143 $this->container->get( Installer::class )->init();
144 $this->container->get( GoogleAnalytics::class )->init();
145 $this->container->get( is_admin() ? CheckoutFieldsAdmin::class : CheckoutFieldsFrontend::class )->init();
146 }
147
148 // Load assets unless this is a request specifically for the store API.
149 if ( ! $is_store_api_request ) {
150 // Template related functionality. These won't be loaded for store API requests, but may be loaded for
151 // regular rest requests to maintain compatibility with the store editor.
152 $this->container->get( BlockPatterns::class );
153 $this->container->get( BlockTypesController::class );
154 $this->container->get( ClassicTemplatesCompatibility::class );
155 $this->container->get( Notices::class )->init();
156
157 if ( is_admin() || $is_rest ) {
158 $this->container->get( AIPatterns::class );
159 $this->container->get( PTKPatternsStore::class );
160 }
161
162 if ( is_admin() ) {
163 $this->container->get( TemplateOptions::class )->init();
164 }
165 }
166
167 $this->container->get( QueryFilters::class )->init();
168 }
169
170 /**
171 * See if files have been built or not.
172 *
173 * @return bool
174 */
175 protected function is_built() {
176 return file_exists(
177 $this->package->get_path( 'assets/client/blocks/featured-product.js' )
178 );
179 }
180
181 /**
182 * Add a notice stating that the build has not been done yet.
183 */
184 protected function add_build_notice() {
185 if ( $this->is_built() ) {
186 return;
187 }
188 add_action(
189 'admin_notices',
190 function () {
191 echo '<div class="error"><p>';
192 printf(
193 /* translators: %1$s is the node install command, %2$s is the install command, %3$s is the build command, %4$s is the watch command. */
194 esc_html__( 'WooCommerce Blocks development mode requires files to be built. From the root directory, run %1$s to ensure your node version is aligned, run %2$s to install dependencies, %3$s to build the files or %4$s to build the files and watch for changes.', 'woocommerce' ),
195 '<code>nvm use</code>',
196 '<code>pnpm install</code>',
197 '<code>pnpm --filter="@woocommerce/plugin-woocommerce" build</code>',
198 '<code>pnpm --filter="@woocommerce/plugin-woocommerce" watch:build</code>'
199 );
200 echo '</p></div>';
201 }
202 );
203 }
204
205 /**
206 * Register core dependencies with the container.
207 */
208 protected function register_dependencies() {
209 $this->container->register(
210 AssetApi::class,
211 function ( Container $container ) {
212 return new AssetApi( $container->get( Package::class ) );
213 }
214 );
215 $this->container->register(
216 AssetDataRegistry::class,
217 function ( Container $container ) {
218 return new AssetDataRegistry( $container->get( AssetApi::class ) );
219 }
220 );
221 $this->container->register(
222 AssetsController::class,
223 function ( Container $container ) {
224 return new AssetsController( $container->get( AssetApi::class ) );
225 }
226 );
227 $this->container->register(
228 DependencyDetection::class,
229 function () {
230 return new DependencyDetection();
231 }
232 );
233 $this->container->register(
234 PaymentMethodRegistry::class,
235 function () {
236 return new PaymentMethodRegistry();
237 }
238 );
239 $this->container->register(
240 Installer::class,
241 function () {
242 return new Installer();
243 }
244 );
245 $this->container->register(
246 BlockTypesController::class,
247 function ( Container $container ) {
248 $asset_api = $container->get( AssetApi::class );
249 $asset_data_registry = $container->get( AssetDataRegistry::class );
250 return new BlockTypesController( $asset_api, $asset_data_registry );
251 }
252 );
253 $this->container->register(
254 ClassicTemplatesCompatibility::class,
255 function ( Container $container ) {
256 $asset_data_registry = $container->get( AssetDataRegistry::class );
257 return new ClassicTemplatesCompatibility( $asset_data_registry );
258 }
259 );
260 $this->container->register(
261 DraftOrders::class,
262 function ( Container $container ) {
263 return new DraftOrders( $container->get( Package::class ) );
264 }
265 );
266 $this->container->register(
267 GoogleAnalytics::class,
268 function ( Container $container ) {
269 $asset_api = $container->get( AssetApi::class );
270 return new GoogleAnalytics( $asset_api );
271 }
272 );
273 $this->container->register(
274 Notices::class,
275 function ( Container $container ) {
276 return new Notices( $container->get( Package::class ) );
277 }
278 );
279 $this->container->register(
280 Hydration::class,
281 function ( Container $container ) {
282 return new Hydration( $container->get( AssetDataRegistry::class ) );
283 }
284 );
285 $this->container->register(
286 CheckoutFields::class,
287 function ( Container $container ) {
288 return new CheckoutFields( $container->get( AssetDataRegistry::class ) );
289 }
290 );
291 $this->container->register(
292 CheckoutFieldsAdmin::class,
293 function ( Container $container ) {
294 $checkout_fields_controller = $container->get( CheckoutFields::class );
295 return new CheckoutFieldsAdmin( $checkout_fields_controller );
296 }
297 );
298 $this->container->register(
299 CheckoutFieldsFrontend::class,
300 function ( Container $container ) {
301 $checkout_fields_controller = $container->get( CheckoutFields::class );
302 return new CheckoutFieldsFrontend( $checkout_fields_controller );
303 }
304 );
305 $this->container->register(
306 PaymentsApi::class,
307 function ( Container $container ) {
308 $payment_method_registry = $container->get( PaymentMethodRegistry::class );
309 $asset_data_registry = $container->get( AssetDataRegistry::class );
310 return new PaymentsApi( $payment_method_registry, $asset_data_registry );
311 }
312 );
313 $this->container->register(
314 CheckoutLink::class,
315 function () {
316 return new CheckoutLink();
317 }
318 );
319 $this->container->register(
320 StoreApi::class,
321 function () {
322 return new StoreApi();
323 }
324 );
325 $this->container->register(
326 TemplateOptions::class,
327 function () {
328 return new TemplateOptions();
329 }
330 );
331 // Maintains backwards compatibility with previous Store API namespace.
332 $this->container->register(
333 'Automattic\WooCommerce\Blocks\StoreApi\Formatters',
334 function ( Container $container ) {
335 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '6.4.0', 'Automattic\WooCommerce\StoreApi\Formatters', '6.5.0' );
336 return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Formatters::class );
337 }
338 );
339 $this->container->register(
340 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi',
341 function ( Container $container ) {
342 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '6.4.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '6.5.0' );
343 return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class );
344 }
345 );
346 $this->container->register(
347 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController',
348 function ( Container $container ) {
349 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '6.4.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '6.5.0' );
350 return $container->get( StoreApi::class )->container()->get( SchemaController::class );
351 }
352 );
353 $this->container->register(
354 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController',
355 function ( Container $container ) {
356 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '6.4.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '6.5.0' );
357 return $container->get( StoreApi::class )->container()->get( RoutesController::class );
358 }
359 );
360 $this->container->register(
361 PTKClient::class,
362 function () {
363 return new PTKClient();
364 }
365 );
366 $this->container->register(
367 PTKPatternsStore::class,
368 function () {
369 return new PTKPatternsStore( $this->container->get( PTKClient::class ) );
370 }
371 );
372 $this->container->register(
373 BlockPatterns::class,
374 function () {
375 return new BlockPatterns(
376 $this->package,
377 new PatternRegistry(),
378 $this->container->get( PTKPatternsStore::class )
379 );
380 }
381 );
382 $this->container->register(
383 AIPatterns::class,
384 function () {
385 return new AIPatterns();
386 }
387 );
388 $this->container->register(
389 ShippingController::class,
390 function ( $container ) {
391 $asset_api = $container->get( AssetApi::class );
392 $asset_data_registry = $container->get( AssetDataRegistry::class );
393 return new ShippingController( $asset_api, $asset_data_registry );
394 }
395 );
396 $this->container->register(
397 QueryFilters::class,
398 function () {
399 return new QueryFilters();
400 }
401 );
402 $this->container->register(
403 BlockTemplatesRegistry::class,
404 function () {
405 return new BlockTemplatesRegistry();
406 }
407 );
408 $this->container->register(
409 BlockTemplatesController::class,
410 function () {
411 return new BlockTemplatesController();
412 }
413 );
414 }
415
416 /**
417 * Throws a deprecation notice for a dependency without breaking requests.
418 *
419 * @param string $function Class or function being deprecated.
420 * @param string $version Version in which it was deprecated.
421 * @param string $replacement Replacement class or function, if applicable.
422 * @param string $trigger_error_version Optional version to start surfacing this as a PHP error rather than a log. Defaults to $version.
423 */
424 protected function deprecated_dependency( $function, $version, $replacement = '', $trigger_error_version = '' ) {
425 if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
426 return;
427 }
428
429 $trigger_error_version = $trigger_error_version ? $trigger_error_version : $version;
430 $error_message = $replacement ? sprintf(
431 '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
432 $function,
433 $version,
434 $replacement
435 ) : sprintf(
436 '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
437 $function,
438 $version
439 );
440 /**
441 * Fires when a deprecated function is called.
442 *
443 * @since 7.3.0
444 */
445 do_action( 'deprecated_function_run', $function, $replacement, $version );
446
447 $log_error = false;
448
449 // If headers have not been sent yet, log to avoid breaking the request.
450 if ( ! headers_sent() ) {
451 $log_error = true;
452 }
453
454 // If the $trigger_error_version was not yet reached, only log the error.
455 if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $trigger_error_version, '<' ) ) {
456 $log_error = true;
457 }
458
459 /**
460 * Filters whether to trigger an error for deprecated functions. (Same as WP core)
461 *
462 * @since 7.3.0
463 *
464 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
465 */
466 if ( ! apply_filters( 'deprecated_function_trigger_error', true ) ) {
467 $log_error = true;
468 }
469
470 if ( $log_error ) {
471 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
472 error_log( $error_message );
473 } else {
474 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
475 trigger_error( $error_message, E_USER_DEPRECATED );
476 }
477 }
478
479 /**
480 * Register payment method integrations with the container.
481 */
482 protected function register_payment_methods() {
483 $this->container->register(
484 Cheque::class,
485 function ( Container $container ) {
486 $asset_api = $container->get( AssetApi::class );
487 return new Cheque( $asset_api );
488 }
489 );
490 $this->container->register(
491 PayPal::class,
492 function ( Container $container ) {
493 $asset_api = $container->get( AssetApi::class );
494 return new PayPal( $asset_api );
495 }
496 );
497 $this->container->register(
498 BankTransfer::class,
499 function ( Container $container ) {
500 $asset_api = $container->get( AssetApi::class );
501 return new BankTransfer( $asset_api );
502 }
503 );
504 $this->container->register(
505 CashOnDelivery::class,
506 function ( Container $container ) {
507 $asset_api = $container->get( AssetApi::class );
508 return new CashOnDelivery( $asset_api );
509 }
510 );
511 }
512 }
513