Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent usage of ContainerAware #2761

Merged
merged 17 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/API/Google/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Google\GoogleHelper;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidTerm;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidDomainName;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\TransientsInterface;
Expand All @@ -16,7 +18,6 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Value\TosAccepted;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\GuzzleHttp\Client;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerExceptionInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\NotFoundExceptionInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Http\Client\ClientExceptionInterface;
use DateTime;
Expand All @@ -38,26 +39,13 @@
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google
*/
class Middleware implements OptionsAwareInterface {
class Middleware implements ContainerAwareInterface, OptionsAwareInterface {

use ContainerAwareTrait;
use ExceptionTrait;
use OptionsAwareTrait;
use PluginHelper;

/**
* @var ContainerInterface
*/
protected $container;

/**
* Middleware constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}

/**
* Get all Merchant Accounts associated with the connected account.
*
Expand Down
18 changes: 4 additions & 14 deletions src/API/Google/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingRateQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingTimeQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\TargetAudience;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WC;
Expand All @@ -17,7 +19,6 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\AccountTax;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\AccountTaxTaxRule as TaxRule;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\ShippingSettings;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;

defined( 'ABSPATH' ) || exit;

Expand All @@ -35,22 +36,11 @@
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google
*/
class Settings {
class Settings implements ContainerAwareInterface {

use ContainerAwareTrait;
use LocationIDTrait;

/** @var ContainerInterface */
protected $container;

/**
* Settings constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}

/**
* Return a set of formatted settings which can be used in tracking.
*
Expand Down
4 changes: 4 additions & 0 deletions src/API/Site/Controllers/Ads/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
/**
* Class ReportsController
*
* ContainerAware used for:
* - AdsReport
* - WP (in parent class)
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\Ads
*/
class ReportsController extends BaseReportsController {
Expand Down
24 changes: 7 additions & 17 deletions src/API/Site/Controllers/BaseReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers;

use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\RESTServer;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WP;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use DateTime;
use WP_REST_Request as Request;

Expand All @@ -14,24 +14,14 @@
/**
* Class BaseReportsController
*
* ContainerAware used for:
* - WP
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers
*/
abstract class BaseReportsController extends BaseController {

/**
* @var ContainerInterface
*/
protected $container;
abstract class BaseReportsController extends BaseController implements ContainerAwareInterface {

/**
* BaseReportsController constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
parent::__construct( $container->get( RESTServer::class ) );
}
use ContainerAwareTrait;

/**
* Get the query params for collections.
Expand Down
4 changes: 4 additions & 0 deletions src/API/Site/Controllers/MerchantCenter/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
/**
* Class ReportsController
*
* ContainerAware used for:
* - MerchantReport
* - WP (in parent class)
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\MerchantCenter
*/
class ReportsController extends BaseReportsController {
Expand Down
23 changes: 7 additions & 16 deletions src/API/Site/Controllers/MerchantCenter/ShippingTimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Automattic\WooCommerce\GoogleListingsAndAds\API\TransportMethods;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingTimeQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ISO3166AwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\RESTServer;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use WP_REST_Request as Request;
use WP_REST_Response as Response;
use WP_Error;
Expand All @@ -20,32 +20,23 @@
/**
* Class ShippingTimeController
*
* ContainerAware used for:
* - ShippingTimeQuery
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\MerchantCenter
*/
class ShippingTimeController extends BaseController implements ISO3166AwareInterface {
class ShippingTimeController extends BaseController implements ContainerAwareInterface, ISO3166AwareInterface {

use ContainerAwareTrait;
use CountryCodeTrait;

/** @var ContainerInterface */
protected $container;

/**
* The base for routes in this controller.
*
* @var string
*/
protected $route_base = 'mc/shipping/times';

/**
* ShippingTimeController constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
parent::__construct( $container->get( RESTServer::class ) );
$this->container = $container;
}

/**
* Register rest routes with WordPress.
*/
Expand Down
25 changes: 7 additions & 18 deletions src/API/Site/RESTControllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,22 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ValidateInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;

/**
* Class RESTControllers
*
* Container used for:
* - classes tagged with 'rest_controller'
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site
*/
class RESTControllers implements Service, Registerable {
class RESTControllers implements ContainerAwareInterface, Service, Registerable {

use ContainerAwareTrait;
use ValidateInterface;

/**
* Our container object.
*
* @var ContainerInterface
*/
protected $container;

/**
* RESTControllers constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}

/**
* Register a service.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Admin/BulkEdit/BulkEditInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Automattic\WooCommerce\GoogleListingsAndAds\Admin\BulkEdit;

use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\AdminConditional;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use WP_Post;
Expand All @@ -16,6 +17,8 @@
*/
class BulkEditInitializer implements Service, Registerable {

use AdminConditional;

/**
* Register a service.
*/
Expand Down
19 changes: 7 additions & 12 deletions src/Ads/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Middleware;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ExceptionWithResponseData;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\AdsAccountState;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\MerchantAccountState;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\TransientsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use Exception;

defined( 'ABSPATH' ) || exit;
Expand All @@ -27,7 +28,6 @@
*
* Container used to access:
* - Ads
* - AdsAccountState
* - AdsConversionAction
* - Connection
* - Merchant
Expand All @@ -38,15 +38,11 @@
* @since 1.11.0
* @package Automattic\WooCommerce\GoogleListingsAndAds\Ads
*/
class AccountService implements OptionsAwareInterface, Service {
class AccountService implements ContainerAwareInterface, OptionsAwareInterface, Service {

use ContainerAwareTrait;
use OptionsAwareTrait;

/**
* @var ContainerInterface
*/
protected $container;

/**
* @var AdsAccountState
*/
Expand All @@ -55,11 +51,10 @@ class AccountService implements OptionsAwareInterface, Service {
/**
* AccountService constructor.
*
* @param ContainerInterface $container
* @param AdsAccountState $state
*/
public function __construct( ContainerInterface $container ) {
$this->state = $container->get( AdsAccountState::class );
$this->container = $container;
public function __construct( AdsAccountState $state ) {
$this->state = $state;
}

/**
Expand Down
25 changes: 8 additions & 17 deletions src/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Middleware;
use Automattic\WooCommerce\GoogleListingsAndAds\API\WP\NotificationsService;
use Automattic\WooCommerce\GoogleListingsAndAds\HelperTraits\GTINMigrationUtilities;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\AdminConditional;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Conditional;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Jobs\CleanupProductsJob;
use Automattic\WooCommerce\GoogleListingsAndAds\Jobs\DeleteAllProducts;
use Automattic\WooCommerce\GoogleListingsAndAds\Jobs\MigrateGTIN;
Expand All @@ -35,31 +39,18 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Product\ProductRepository;
use Automattic\WooCommerce\GoogleListingsAndAds\Product\ProductSyncer;
use Automattic\WooCommerce\GoogleListingsAndAds\Product\ProductSyncerException;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use Jetpack_Options;
use WP_REST_Request as Request;

/**
* Main class for Connection Test.
*/
class ConnectionTest implements Service, Registerable {
class ConnectionTest implements Conditional, ContainerAwareInterface, Service, Registerable {

use PluginHelper;
use AdminConditional;
use ContainerAwareTrait;
use GTINMigrationUtilities;

/**
* @var ContainerInterface
*/
protected $container;

/**
* ConnectionTest constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}
use PluginHelper;

/**
* Register a service.
Expand Down
Loading
Loading