vendor/pimcore/pimcore/lib/Templating/HelperBroker/HelperShortcuts.php line 111

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace Pimcore\Templating\HelperBroker;
  15. use Pimcore\Http\RequestHelper;
  16. use Pimcore\Templating\Helper\Translate;
  17. use Pimcore\Templating\PhpEngine;
  18. use Symfony\Bundle\FrameworkBundle\Templating\Helper\RouterHelper;
  19. use Symfony\Component\HttpFoundation\Request;
  20. /**
  21.  * Shortcuts available as $this->method() on the engine
  22.  *
  23.  * @deprecated
  24.  */
  25. class HelperShortcuts implements HelperBrokerInterface
  26. {
  27.     /**
  28.      * @var RequestHelper
  29.      */
  30.     protected $requestHelper;
  31.     /**
  32.      * Supported methods
  33.      *
  34.      * @var array
  35.      */
  36.     protected $shortcuts = [
  37.         'getLocale',
  38.         'getRequest',
  39.         'path',
  40.         'url',
  41.         't',
  42.     ];
  43.     /**
  44.      * @param RequestHelper $requestHelper
  45.      */
  46.     public function __construct(RequestHelper $requestHelper)
  47.     {
  48.         $this->requestHelper $requestHelper;
  49.     }
  50.     /**
  51.      * @inheritDoc
  52.      */
  53.     public function supports(PhpEngine $engine$method)
  54.     {
  55.         return in_array($method$this->shortcuts);
  56.     }
  57.     /**
  58.      * @inheritDoc
  59.      */
  60.     public function helper(PhpEngine $engine$method, array $arguments)
  61.     {
  62.         return call_user_func_array([$this$method], [$engine$arguments]);
  63.     }
  64.     /**
  65.      * @return string
  66.      */
  67.     protected function getLocale()
  68.     {
  69.         return $this->requestHelper->getCurrentRequest()->getLocale();
  70.     }
  71.     /**
  72.      * @return Request
  73.      */
  74.     protected function getRequest()
  75.     {
  76.         return $this->requestHelper->getCurrentRequest();
  77.     }
  78.     /**
  79.      * @param PhpEngine $engine
  80.      * @param array $arguments
  81.      *
  82.      * @return string
  83.      */
  84.     protected function url(PhpEngine $engine, array $arguments)
  85.     {
  86.         /** @var RouterHelper $helper */
  87.         $helper $engine->get('router');
  88.         return call_user_func_array([$helper'url'], $arguments);
  89.     }
  90.     /**
  91.      * @param PhpEngine $engine
  92.      * @param array $arguments
  93.      *
  94.      * @return string
  95.      */
  96.     protected function path(PhpEngine $engine, array $arguments)
  97.     {
  98.         /** @var RouterHelper $helper */
  99.         $helper $engine->get('router');
  100.         return call_user_func_array([$helper'path'], $arguments);
  101.     }
  102.     /**
  103.      * @param PhpEngine $engine
  104.      * @param array $arguments
  105.      *
  106.      * @return string
  107.      */
  108.     protected function t(PhpEngine $engine, array $arguments)
  109.     {
  110.         /** @var Translate $helper */
  111.         $helper $engine->get('translate');
  112.         return $helper(...$arguments);
  113.     }
  114. }