You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Lc\CaracoleBundle\Resolver\Price;
  3. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  5. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  6. class PriceResolver
  7. {
  8. protected ProductPriceResolver $productPriceResolver;
  9. protected OrderProductPriceResolver $orderProductPriceResolver;
  10. protected OrderShopPriceResolver $orderShopPriceResolver;
  11. public function __construct(
  12. ProductPriceResolver $productPriceResolver,
  13. OrderProductPriceResolver $orderProductPriceResolver,
  14. OrderShopPriceResolver $orderShopPriceResolver
  15. ) {
  16. $this->productPriceResolver = $productPriceResolver;
  17. $this->orderProductPriceResolver = $orderProductPriceResolver;
  18. $this->orderShopPriceResolver = $orderShopPriceResolver;
  19. }
  20. public function __call($name, $arguments)
  21. {
  22. if (strpos($name, 'apply') === false) {
  23. $entity = $arguments[0];
  24. $service = '';
  25. if ($entity instanceof ProductPropertyInterface) {
  26. $service = 'productPriceResolver';
  27. }
  28. if ($entity instanceof OrderProductInterface) {
  29. $service = 'orderProductPriceResolver';
  30. }
  31. if ($entity instanceof OrderShopInterface || is_iterable($entity) || is_array($entity)) {
  32. $service = 'orderShopPriceResolver';
  33. }
  34. if (strlen($service) && $entity && method_exists($this->$service, $name)) {
  35. if (isset($arguments[1]) && isset($arguments[2]) && isset($arguments[3])) {
  36. return $this->$service->$name($entity, $arguments[1], $arguments[2], $arguments[3]);
  37. } elseif (isset($arguments[1]) && isset($arguments[2])) {
  38. return $this->$service->$name($entity, $arguments[1], $arguments[2]);
  39. } elseif (isset($arguments[1])) {
  40. return $this->$service->$name($entity, $arguments[1]);
  41. } else {
  42. return $this->$service->$name($entity);
  43. }
  44. } else {
  45. if (!strlen($service)) {
  46. throw new \ErrorException("PriceResolver : le type d'entité n'est pas géré");
  47. } else {
  48. if (!method_exists($this->$service, $name)) {
  49. throw new \ErrorException(
  50. "PriceResolver : la méthode " . $name . " du service " . $service . " n'existe pas."
  51. );
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. }
  58. }