68 line
2.0KB

  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('getElementByDevAlias', [$this, 'getElementByDevAlias']),
  28. );
  29. }
  30. public function getFilters()
  31. {
  32. return [
  33. new TwigFilter('slugify', [$this, 'slugify']),
  34. ];
  35. }
  36. public function getDayByNumber($number)
  37. {
  38. return $this->utils->getDayByNumber($number) ;
  39. }
  40. public function getUnitsList()
  41. {
  42. return $this->utils->getUnitsList() ;
  43. }
  44. public function getTaxRatesList()
  45. {
  46. return $this->merchantUtils->getTaxRatesList() ;
  47. }
  48. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  49. {
  50. return $this->utils->getElementByDevAlias($devAlias, $class) ;
  51. }
  52. public function slugify($string)
  53. {
  54. return $this->utils->slugify($string) ;
  55. }
  56. }