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.

BridgeTwigExtension.php 2.0KB

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