選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BridgeTwigExtension.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Utils;
  6. use Twig\Extension\AbstractExtension;
  7. use Twig\TwigFilter;
  8. use Twig\TwigFunction;
  9. class BridgeTwigExtension extends AbstractExtension
  10. {
  11. private $utils ;
  12. public function __construct(Utils $utils)
  13. {
  14. $this->utils = $utils ;
  15. }
  16. public function getFunctions()
  17. {
  18. return array(
  19. new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
  20. new TwigFunction('getUnitsList', [$this, 'getUnitsList']),
  21. new TwigFunction('getTaxRatesList', [$this, 'getTaxRatesList']),
  22. new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']),
  23. new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
  24. );
  25. }
  26. public function getFilters()
  27. {
  28. return [
  29. new TwigFilter('slugify', [$this, 'slugify']),
  30. ];
  31. }
  32. public function getDayByNumber($number)
  33. {
  34. return $this->utils->getDayByNumber($number) ;
  35. }
  36. public function getUnitsList()
  37. {
  38. return $this->utils->getUnitsList() ;
  39. }
  40. public function getTaxRatesList()
  41. {
  42. return $this->utils->getTaxRatesList() ;
  43. }
  44. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  45. {
  46. return $this->utils->getElementByDevAlias($devAlias, $class) ;
  47. }
  48. public function slugify($string)
  49. {
  50. return $this->utils->slugify($string) ;
  51. }
  52. }