src/Twig/OSExtension.php line 89

  1. <?php
  2. namespace App\Twig;
  3. use Symfony\Component\Routing\RouterInterface;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Twig\Extension\AbstractExtension;
  6. use Twig\TwigFilter;
  7. use Twig\TwigFunction;
  8. use OlaSoft\Common;
  9. class OSExtension extends AbstractExtension {
  10.     private $common;
  11.     private $router;
  12.     public function __construct(RouterInterface $router){
  13.         $this->common = new Common;
  14.         $this->router $router;
  15.     }
  16.     public function getFilters(){
  17.         return [
  18.             new TwigFilter('imagecolor', [$this->common'imagecolor']),
  19.             new TwigFilter('imagesize', [$this->common'imagesize']),
  20.             new TwigFilter('filesize', [$this->common'filesize']),
  21.             new TwigFilter('pretty_size', [$this->common'prettySize']),
  22.             new TwigFilter('pretty_date', [$this->common'prettyDate']),
  23.             new TwigFilter('pretty_datetime', [$this->common'prettyDateTime']),
  24.             new TwigFilter('slug', [$this->common'slug']),
  25.             new TwigFilter('frdate', [$this->common'FrDate']),
  26.             new TwigFilter('frdatetime', [$this->common'FrDateTime']),
  27.             new TwigFilter('frmonth', [$this->common'FrMonth']),
  28.             new TwigFilter('strftime', [$this->common'Strftime']),
  29.             new TwigFilter('mobile', [$this->common'mobile']),
  30.             new TwigFilter('desktop', [$this->common'desktop']),
  31.             new TwigFilter('country', [$this->common'country']),
  32.             new TwigFilter('youtubeId', [$this->common'getYoutubeId']),
  33.             new TwigFilter('youtubeEmbed', [$this->common'getYoutubeEmbed']),
  34.             new TwigFilter('youtubeThumbnail', [$this->common'getYoutubeThumbnail']),
  35.             new TwigFilter('vimeoThumbnail', [$this->common'getVimeoThumbnail']),
  36.             new TwigFilter('filterArray', [$this->common'filterArray']),
  37.             new TwigFilter('summary', [$this->common'summary']),
  38.             new TwigFilter('search', [$this'arraySearch']),
  39.             new TwigFilter('values', [$this'arrayValues']),
  40.             new TwigFilter('price', [$this->common'formatPrice']),
  41.             new TwigFilter('amount', [$this->common'formatPrice']),
  42.             new TwigFilter('isRoute', [$this'isRoute']),
  43.             new TwigFilter('os_trans', [$this->common'translate']),
  44.             new TwigFilter('os_trans_text', [$this->common'translateText']),
  45.             new TwigFilter('checkdealine', [$this->common'CheckDealineFilter']),
  46.         ];
  47.     }
  48.     public function getFunctions()
  49.     {
  50.         return [
  51.             new TwigFunction('isMobile', [$this->common'isMobile']),
  52.             new TwigFunction('isDesktop', [$this->common'isDesktop']),
  53.             new TwigFunction('mobile', [$this->common'mobile']),
  54.             new TwigFunction('desktop', [$this->common'desktop']),
  55.             new TwigFunction('downloadPDF', [$this->common'downloadPDF']),
  56.             new TwigFunction('youtubeId', [$this->common'getYoutubeId']),
  57.             new TwigFunction('youtubeEmbed', [$this->common'getYoutubeEmbed']),
  58.             new TwigFunction('youtubeThumbnail', [$this->common'getYoutubeThumbnail']),
  59.             new TwigFunction('vimeoThumbnail', [$this->common'getVimeoThumbnail']),
  60.             new TwigFunction('filterArray', [$this->common'filterArray']),
  61.             new TwigFunction('summary', [$this->common'summary']),
  62.             new TwigFunction('os_param', [$this->common'getParameter']),
  63.             new TwigFunction('price', [$this->common'formatPrice']),
  64.             new TwigFunction('amount', [$this->common'formatPrice']),
  65.             new TwigFunction('isRoute', [$this'isRoute']),
  66.             new TwigFunction('localeIsFr', [$this->common'localeIsFr']),
  67.             new TwigFunction('localeIsEn', [$this->common'localeIsEn']),
  68.             new TwigFunction('locale', [$this->common'getLocale']),
  69.             new TwigFunction('os_trans', [$this->common'translate']),
  70.             new TwigFunction('os_trans_text', [$this->common'translateText']),
  71.             new TwigFunction('checkdealine', [$this->common'CheckDealineFilter']),
  72.         ];
  73.     }
  74.     public function arraySearch($v$t){
  75.         return array_search($v,$t);
  76.     }
  77.     public function arrayValues($t){
  78.         return array_values($t);
  79.     }
  80.     function isRoute($name){
  81.         $router $this->router;
  82.         return (null === $router->getRouteCollection()->get($name)) ? false true;
  83.     }
  84.     public function getName(){
  85.         return 'os_extension';
  86.     }
  87. }