Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BridgeTwigExtension.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }