76 lines
2.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Twig;
  3. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  4. use Lc\ShopBundle\Context\PageInterface;
  5. use Lc\ShopBundle\Form\Frontend\NewsletterType;
  6. use Lc\ShopBundle\Services\TaxRateUtils;
  7. use Lc\ShopBundle\Services\UnitUtils;
  8. use Lc\ShopBundle\Services\Utils;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFilter;
  11. use Twig\TwigFunction;
  12. class BridgeTwigExtension extends AbstractExtension
  13. {
  14. private $utils ;
  15. private $merchantUtils ;
  16. public function __construct(Utils $utils, MerchantUtilsInterface $merchantUtils)
  17. {
  18. $this->utils = $utils ;
  19. $this->merchantUtils = $merchantUtils ;
  20. }
  21. public function getFunctions()
  22. {
  23. return array(
  24. new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
  25. new TwigFunction('getUnitsList', [$this, 'getUnitsList']),
  26. new TwigFunction('getTaxRatesList', [$this, 'getTaxRatesList']),
  27. new TwigFunction('lc_liip', [$this, 'lcLiip']),
  28. new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']),
  29. );
  30. }
  31. public function getFilters()
  32. {
  33. return [
  34. new TwigFilter('slugify', [$this, 'slugify']),
  35. new TwigFilter('lc_liip', [$this, 'lcLiip']),
  36. ];
  37. }
  38. public function getDayByNumber($number)
  39. {
  40. return $this->utils->getDayByNumber($number) ;
  41. }
  42. public function getUnitsList()
  43. {
  44. return $this->utils->getUnitsList() ;
  45. }
  46. public function getTaxRatesList()
  47. {
  48. return $this->merchantUtils->getTaxRatesList() ;
  49. }
  50. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  51. {
  52. return $this->utils->getElementByDevAlias($devAlias, $class) ;
  53. }
  54. public function slugify($string)
  55. {
  56. return $this->utils->slugify($string) ;
  57. }
  58. public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg'){
  59. return $this->utils->lcLiip($path, $thumb, $default);
  60. }
  61. }