woocommerce-paypal-payments/modules/ppcp-api-client/src/Repository/CartRepository.php
Anton Ukhanev d4c8282518 Use Composer modules and convert modules to PSR-4
PSR-4 is much more robust and predictable. But to do this,
a source root dir must be specified for every module.
This could be done in the root file, but this is not very modular.
Instead, now every module declares its own source root by using
the amazing Composer Merge Plugin. This approach allows each module
to also declare its own dependencies. Together, these changes allow
modules to be easily extractable to separate pacakges when the need
arises, and in general improves modularity significantly.
2021-08-26 11:01:20 +02:00

45 lines
996 B
PHP

<?php
/**
* The cart repository returns the purchase units from the current \WC_Cart.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Repository
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
/**
* Class CartRepository
*/
class CartRepository implements PurchaseUnitRepositoryInterface {
/**
* The purchase unit factory.
*
* @var PurchaseUnitFactory
*/
private $factory;
/**
* CartRepository constructor.
*
* @param PurchaseUnitFactory $factory The purchase unit factory.
*/
public function __construct( PurchaseUnitFactory $factory ) {
$this->factory = $factory;
}
/**
* Returns all Pur of the WooCommerce cart.
*
* @return PurchaseUnit[]
*/
public function all(): array {
$cart = WC()->cart ?? new \WC_Cart();
return array( $this->factory->from_wc_cart( $cart ) );
}
}