AI
1 year ago
AIContent
1 year ago
Assets
3 weeks ago
BlockTypes
1 week ago
Domain
1 month ago
Images
1 year ago
Integrations
2 years ago
Patterns
6 months ago
Payments
5 months ago
Registry
2 years ago
SharedStores
1 month ago
Shipping
7 months ago
Templates
1 month ago
Utils
3 weeks ago
Assets.php
2 years ago
AssetsController.php
3 weeks ago
BlockPatterns.php
7 months ago
BlockTemplatesController.php
7 months ago
BlockTemplatesRegistry.php
10 months ago
BlockTypesController.php
3 weeks ago
DependencyDetection.php
5 months ago
InboxNotifications.php
2 years ago
Installer.php
1 month ago
Library.php
2 years ago
Options.php
2 years ago
Package.php
1 year ago
QueryFilters.php
7 months ago
TemplateOptions.php
1 year ago
Package.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blocks; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Domain\Package as NewPackage; |
| 6 | use Automattic\WooCommerce\Blocks\Domain\Bootstrap; |
| 7 | use Automattic\WooCommerce\Blocks\Registry\Container; |
| 8 | use Automattic\WooCommerce\Blocks\Domain\Services\FeatureGating; |
| 9 | |
| 10 | /** |
| 11 | * Main package class. |
| 12 | * |
| 13 | * Returns information about the package and handles init. |
| 14 | * |
| 15 | * In the context of this plugin, it handles init and is called from the main |
| 16 | * plugin file (woocommerce-gutenberg-products-block.php). |
| 17 | * |
| 18 | * In the context of WooCommerce core, it handles init and is called from |
| 19 | * WooCommerce's package loader. The main plugin file is _not_ loaded. |
| 20 | * |
| 21 | * @since 2.5.0 |
| 22 | */ |
| 23 | class Package { |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * For back compat this is provided. Ideally, you should register your |
| 28 | * class with Automattic\Woocommerce\Blocks\Container and make Package a |
| 29 | * dependency. |
| 30 | * |
| 31 | * @since 2.5.0 |
| 32 | * @return Package The Package instance class |
| 33 | */ |
| 34 | protected static function get_package() { |
| 35 | return self::container()->get( NewPackage::class ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Init the package - load the blocks library and define constants. |
| 40 | * |
| 41 | * @since 2.5.0 Handled by new NewPackage. |
| 42 | */ |
| 43 | public static function init() { |
| 44 | self::container()->get( Bootstrap::class ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Return the version of the package. |
| 49 | * |
| 50 | * @return string |
| 51 | */ |
| 52 | public static function get_version() { |
| 53 | return self::get_package()->get_version(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Return the path to the package. |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public static function get_path() { |
| 62 | return self::get_package()->get_path(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns an instance of the FeatureGating class. |
| 67 | * |
| 68 | * @return FeatureGating |
| 69 | * @deprecated since 9.6, use wp_get_environment_type() instead. |
| 70 | */ |
| 71 | public static function feature() { |
| 72 | wc_deprecated_function( 'Package::feature', '9.6', 'wp_get_environment_type' ); |
| 73 | return new FeatureGating(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Loads the dependency injection container for woocommerce blocks. |
| 78 | * |
| 79 | * @param boolean $reset Used to reset the container to a fresh instance. |
| 80 | * Note: this means all dependencies will be |
| 81 | * reconstructed. |
| 82 | */ |
| 83 | public static function container( $reset = false ) { |
| 84 | static $container; |
| 85 | if ( |
| 86 | ! $container instanceof Container |
| 87 | || $reset |
| 88 | ) { |
| 89 | $container = new Container(); |
| 90 | // register Package. |
| 91 | $container->register( |
| 92 | NewPackage::class, |
| 93 | function ( $container ) { |
| 94 | // leave for automated version bumping. |
| 95 | $version = '11.8.0-dev'; |
| 96 | return new NewPackage( |
| 97 | $version, |
| 98 | dirname( __DIR__, 2 ) |
| 99 | ); |
| 100 | } |
| 101 | ); |
| 102 | // register Bootstrap. |
| 103 | $container->register( |
| 104 | Bootstrap::class, |
| 105 | function ( $container ) { |
| 106 | return new Bootstrap( |
| 107 | $container |
| 108 | ); |
| 109 | } |
| 110 | ); |
| 111 | } |
| 112 | return $container; |
| 113 | } |
| 114 | } |
| 115 |