|
- <?php
-
- namespace Lc\CaracoleBundle\Resolver\Price;
-
- use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
- use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
-
- class PriceResolver
- {
- protected ProductPriceResolver $productPriceResolver;
- protected OrderProductPriceResolver $orderProductPriceResolver;
- protected OrderShopPriceResolver $orderShopPriceResolver;
-
- public function __construct(
- ProductPriceResolver $productPriceResolver,
- OrderProductPriceResolver $orderProductPriceResolver,
- OrderShopPriceResolver $orderShopPriceResolver
- ) {
- $this->productPriceResolver = $productPriceResolver;
- $this->orderProductPriceResolver = $orderProductPriceResolver;
- $this->orderShopPriceResolver = $orderShopPriceResolver;
- }
-
- public function __call($name, $arguments)
- {
- if (strpos($name, 'apply') === false) {
- $entity = $arguments[0];
- $service = '';
-
- if ($entity instanceof ProductPropertyInterface) {
- $service = 'productPriceResolver';
- }
-
- if ($entity instanceof OrderProductInterface) {
- $service = 'orderProductPriceResolver';
- }
-
- if ($entity instanceof OrderShopInterface || is_iterable($entity) || is_array($entity)) {
- $service = 'orderShopPriceResolver';
- }
-
- if (strlen($service) && $entity && method_exists($this->$service, $name)) {
- if (isset($arguments[1]) && isset($arguments[2]) && isset($arguments[3])) {
- return $this->$service->$name($entity, $arguments[1], $arguments[2], $arguments[3]);
- } elseif (isset($arguments[1]) && isset($arguments[2])) {
- return $this->$service->$name($entity, $arguments[1], $arguments[2]);
- } elseif (isset($arguments[1])) {
- return $this->$service->$name($entity, $arguments[1]);
- } else {
- return $this->$service->$name($entity);
- }
- } else {
- if (!strlen($service)) {
- throw new \ErrorException("PriceResolver : le type d'entité n'est pas géré");
- } else {
- if (!method_exists($this->$service, $name)) {
- throw new \ErrorException(
- "PriceResolver : la méthode " . $name . " du service " . $service . " n'existe pas."
- );
- }
- }
- }
-
- return false;
- }
- }
- }
|