Commit Graph

28 Commits

Author SHA1 Message Date
Nestor Soriano 064ae558ab Changes in the overall organization of the dependency injection:
- The `Container` class now implements `Psr\Container\ContainerInterface`
  (and registers itself as such), holding a private instance of the
  real container. This way it's a read-only container from the point
  of view of plugins (which should use their own containers, but
  can still use this to get WooCommerce classes).
- All registrations are now done in the `Container` constructor via
  service providers.
- The container instance is now held in a global variable, set in
  `woocommerce.php`
- Added the `wc_get_container` function for old code.
- Added the `AbstractServiceProvider` class, which inherits with the
  corresponding League's class and adds some utility methods,
  most notably `add/shareWithAutoArguments`.
- Added the `ActionsProxy` and `LegacyProxy` classes, they are
  registered via a dedicated service provider.
- `WC_Queue_Interface` is no longer resolvable via the container
  (which is for classes inside `src` only).
- All the method names in the new classes have the format `fooBarFizz`
  to be PSR4 compliant, so the MethodNameInvalid error has been
  disabled in phpcs.xml for the `src` directory.
- Introduced the `@public` annotation for public API classes
  (classes that plugins can use and whose backwards compatibility
  we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now.
- Removed the hack for the autoloader as now it doesn't work anyway.
  For the changes in this branch to work, now WP_DEBUG must be false.
2020-07-24 09:23:01 +02:00
Nestor Soriano a7829525eb Changes in the dependency injection container:
- Renamed from `ObjectContainer` to `Container`.
- It now inherits from PHP League's `Container`.
- It has now a `defineAsSharedAutowired` method.
- Initialization moved to the `WooCommerce::init_container` method.
- The static method for object resolution is now `WooCommerce::get_instance_of`.
2020-07-24 09:20:24 +02:00
Nestor Soriano 281ec18158 Undo the registration of old singletons in the DI container.
The container will in principle be used only to register classes
in the `src` directory.

Also, CustomerProvider class removed.
2020-07-24 09:20:24 +02:00
Nestor Soriano 518c52b829 Move PSR4 autoloading from woocommerce.php to the Autoloader class 2020-07-24 09:20:24 +02:00
Nestor Soriano 312383ae47 First steps towards introducing a dependency injection framework.
- Add PHP League's Container package via Composer.
- Add an ObjectContainer class that encapsulates all the configuration
  and insulates the codebase from the concrete DI engine used.
- Add an improved ReflectionContainer class that will allow to
  register individual classes as singletons while autowiring.
- Use ObjectContainer to resolve the WooCommerce class, everything
  instantiated with "new" inside it, and all singletons that are
  usually obtained via WC() function.
- Introduce the CustomerProvider class.
- Introduce a service provider to resolve WC_Queue_Interface,
  this replaces the WC_Queue class.
- Mark as obsolete all the replaced "instance()" methods,
  and the entire WC_Queue class.
2020-07-24 09:20:21 +02:00
Vedanshu Jain a34835e489
Merge pull request #26932 from woocommerce/fix/25442
Show community forum link if wccom is not connected
2020-07-16 00:14:52 +05:30
vedanshujain aabf4bfe37 Add unit tests. 2020-07-15 15:27:34 +05:30
vedanshujain 4500e86198 Shorten class and method names to reduce redundancy in naming. 2020-07-15 15:20:18 +05:30
vedanshujain 1e68ce5dc9 Move function to src for better code architecture 2020-07-14 23:31:56 +05:30
Peter Fabian d54a2c3b2f Removed type hints.
Based on the design committee, we've decided not to use 'old' classes from the includes folder in new code in the 'src' directory. Thus removing those type hints, but leaving them in the docblock to not lose the information.
2020-07-06 15:36:33 +02:00
Mike Jolley 00f1246553 Update reserved stock when a row already exists 2020-06-18 12:09:57 +01:00
vedanshujain d21cc596df Return early in release stock function if stock reservation is disabled. 2020-06-15 18:40:03 +05:30
vedanshujain 79e13edff0 This commit adds two changes for reserved stock functionality:
1. Use '0000-00-00 00:00:00' instead of CURRENT_TIMESTAMP as default value to support MySQL 5.6
2. Return early if DB version is less than 430 because then it would mean that required wc_reserved_stock table might not be present.
2020-06-05 19:20:06 +05:30
Vedanshu Jain b45373fe0c Revert "Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout"" 2020-06-05 15:18:01 +05:30
Christopher Allford 1b2f5ab4ad Added handling to prevent namespace conflicts with included packages
The root namespace of Core is Automattic\WooCommerce, but both the blocks and wc-admin plugins exist in this namespace. In an effort to prevent possible conflicts, we should not allow for overlap in our repository. The rationale behind doing this as opposed to renaming our root namespace feels reasonable. In the case of Blocks, all of the tooling is already set up in their repository, so all blocks should go there anyway. In the case of WC-Admin, we shouldn't be refactoring admin classes, as that would duplicate work done to revamp them entirely.
2020-04-28 14:04:00 -07:00
Vedanshu Jain ee119e0a7e
Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout" 2020-04-21 15:37:21 +05:30
Christopher Allford 09df1205de Updated the minimum PHP version to 7.0 2020-04-06 17:07:33 -07:00
Mike Jolley 0cce3c5c45 Missing abspath check 2020-04-03 16:16:20 +01:00
Mike Jolley f248902454 Update versions 2020-04-03 15:56:43 +01:00
Mike Jolley 107879950e Remove get_query_for_stock as it's part of data-store 2020-04-03 15:55:15 +01:00
Mike Jolley c983677a6f Implement stock functions 2020-04-03 15:55:15 +01:00
Mike Jolley d2d0967ac0 Introduce class to handle stock reservation 2020-04-03 15:55:14 +01:00
Ron Rennick 22d5dce682 change the namespace of the WC Admin Package class 2020-02-24 22:56:32 -04:00
Paul Sealock 6c9e78850a wc-admin: Include package 2020-01-16 17:40:30 -07:00
Rodrigo Primo 179dd7003e Fix Generic.Arrays.DisallowShortArraySyntax violations
This commit fixes all violations of the
Generic.Arrays.DisallowShortArraySyntax sniff automatically using
phpcbf.
2019-12-20 14:18:04 -03:00
Mike Jolley 9a8e8dacff Add integration tests 2019-06-25 15:57:44 +01:00
Mike Jolley db6aa55eda Add readme file explaining use of src folder 2019-06-25 13:13:20 +01:00
Mike Jolley f8d6b26e2e Add dedicated Packages loader and Autoloader to init functionality 2019-06-25 13:13:04 +01:00