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.

70 line
2.1KB

  1. <?php
  2. namespace Lc\ShopBundle\Twig;
  3. use Lc\ShopBundle\Context\PageInterface;
  4. use Lc\ShopBundle\Form\Frontend\NewsletterType;
  5. use Lc\ShopBundle\Services\TaxRateUtils;
  6. use Lc\ShopBundle\Services\UnitUtils;
  7. use Lc\ShopBundle\Services\Utils;
  8. use Twig\Extension\AbstractExtension;
  9. use Twig\TwigFilter;
  10. use Twig\TwigFunction;
  11. class BridgeTwigExtension extends AbstractExtension
  12. {
  13. private $utils ;
  14. private $taxRateUtils ;
  15. private $unitUtils ;
  16. public function __construct(Utils $utils, TaxRateUtils $taxRateUtils, UnitUtils $unitUtils)
  17. {
  18. $this->utils = $utils ;
  19. $this->taxRateUtils = $taxRateUtils ;
  20. $this->unitUtils = $unitUtils ;
  21. }
  22. public function getFunctions()
  23. {
  24. return array(
  25. new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
  26. new TwigFunction('getUnitsList', [$this, 'getUnitsList']),
  27. new TwigFunction('getTaxRatesList', [$this, 'getTaxRatesList']),
  28. new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']),
  29. new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
  30. );
  31. }
  32. public function getFilters()
  33. {
  34. return [
  35. new TwigFilter('slugify', [$this, 'slugify']),
  36. ];
  37. }
  38. public function getDayByNumber($number)
  39. {
  40. return $this->utils->getDayByNumber($number) ;
  41. }
  42. public function getUnitsList()
  43. {
  44. return $this->unitUtils->getUnitsList() ;
  45. }
  46. public function getTaxRatesList()
  47. {
  48. return $this->taxRateUtils->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. }