ca9ed93b9a
- Added a new class `ExtendedContainer` that extends League's container. - `add` modified to reject classes not in the root Woo namespace. - Has two new methods, `replace` and `reset_resolved`. - It's used as the underlying container instead of League's one in `Container`, but the new methods are not exposed. - At unit test bootstrap time the globally registered container is replaced with the extended one that `Container` stores (grabbed from private property using reflection). - A new `MockableLegacyProxy` is added. It inherits from `LegacyProxy` and allows to mock functions, static methods and legacy classes. - The registeed `LegacyProxy` is replaced with the mockable version during unit test bootstrap. - A PHPUnit hook is added to reset the mockable proxy to its initial state (so that nothing is mocked) before each test. - `WC_Unit_Test_Case` gets helper methods to mock functions, static methods and classes without having to retrieve the proxy class. |
||
---|---|---|
.. | ||
Admin | ||
Blocks | ||
Checkout/Helpers | ||
DependencyManagement | ||
Internal/WCCom | ||
Proxies | ||
Autoloader.php | ||
Container.php | ||
Packages.php | ||
README.md |
README.md
WooCommerce src
files
This directory is home to new WooCommerce class files under the \Automattic\WooCommerce\ namespace using PSR-4 file naming. This is to take full advantage of autoloading.
Currently, these classes have a PHP 7.0 requirement. No required core classes will be added here until this PHP version is enforced. If running an older version of PHP, these class files will not be used.
Installing Composer
Composer is used to generate autoload class-maps for the files here. The stable release of WooCommerce comes with the autoloader, however, if you're running a development version you'll need to use Composer.
If you don't have Composer installed, go and check how to install Composer and then continue here.
Installing packages
To install the packages WooCommerce requires, from the main directory run:
composer install
To update packages run:
composer update
If you add a class to WooCommerce and want to ensure it's included in the autoloader class-maps, run:
composer dump-autoload
Using classes
To use something a namespaced class you have to declare it at the top of the file before any other instruction, and then use it in the code. For example:
use Automattic\WooCommerce\TestClass;
// other code...
$test_class = new TestClass();
If you need to rule out conflicts, you can alias it:
use Automattic\WooCommerce\TestClass as Test_Class_Alias;
// other code...
$test_class = new Test_Class_Alias();