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.

PriceUtils.php 3.1KB

4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Lc\ShopBundle\Services\Price;
  3. use Lc\ShopBundle\Context\OrderProductInterface;
  4. use Lc\ShopBundle\Context\OrderShopInterface;
  5. use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface;
  6. use Lc\ShopBundle\Context\PriceUtilsInterface;
  7. use Lc\ShopBundle\Context\ProductPropertyInterface;
  8. class PriceUtils implements PriceUtilsInterface
  9. {
  10. protected $productPriceUtils;
  11. protected $orderProductPriceUtils;
  12. protected $orderShopPriceUtils;
  13. public function __construct(ProductPriceUtils $productPriceUtils, OrderProductPriceUtils $orderProductPriceUtils, OrderShopPriceUtilsInterface $orderShopPriceUtils)
  14. {
  15. $this->productPriceUtils = $productPriceUtils;
  16. $this->orderProductPriceUtils = $orderProductPriceUtils;
  17. $this->orderShopPriceUtils = $orderShopPriceUtils;
  18. }
  19. public function __call($name, $arguments)
  20. {
  21. if (strpos($name, 'apply') === false) {
  22. $entity = $arguments[0];
  23. $service = '';
  24. if ($entity instanceof ProductPropertyInterface) {
  25. $service = 'productPriceUtils';
  26. }
  27. if ($entity instanceof OrderProductInterface) {
  28. $service = 'orderProductPriceUtils';
  29. }
  30. if ($entity instanceof OrderShopInterface || is_iterable($entity) || is_array($entity)) {
  31. $service = 'orderShopPriceUtils';
  32. }
  33. if (strlen($service) && $entity && method_exists($this->$service, $name)) {
  34. if (isset($arguments[1]) && isset($arguments[2]) && isset($arguments[3])) {
  35. return $this->$service->$name($entity, $arguments[1], $arguments[2], $arguments[3]);
  36. } elseif (isset($arguments[1]) && isset($arguments[2])) {
  37. return $this->$service->$name($entity, $arguments[1], $arguments[2]);
  38. } elseif (isset($arguments[1])) {
  39. return $this->$service->$name($entity, $arguments[1]);
  40. } else {
  41. return $this->$service->$name($entity);
  42. }
  43. } else {
  44. if (!strlen($service)) {
  45. throw new \ErrorException("PriceUtils : le type d'entité n'est pas géré");
  46. } else {
  47. if (!method_exists($this->$service, $name)) {
  48. throw new \ErrorException("PriceUtils : la méthode " . $name . " du service " . $service . " n'existe pas.");
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. }
  55. }