vendor/shopware/core/Framework/Adapter/Twig/functions.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Adapter\Twig;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\FieldVisibility;
  5. use Twig\Environment;
  6. use Twig\Source;
  7. if (!\function_exists('Shopware\Core\Framework\Adapter\Twig\sw_get_attribute')) {
  8.     /**
  9.      * Returns the attribute value for a given array/object.
  10.      *
  11.      * @param mixed  $object            The object or array from where to get the item
  12.      * @param mixed  $item              The item to get from the array or object
  13.      * @param array  $arguments         An array of arguments to pass if the item is an object method
  14.      * @param string $type              The type of attribute (@see \Twig\Template constants)
  15.      * @param bool   $isDefinedTest     Whether this is only a defined check
  16.      * @param bool   $ignoreStrictCheck Whether to ignore the strict attribute check or not
  17.      * @param int    $lineno            The template line where the attribute was called
  18.      *
  19.      * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
  20.      *
  21.      * @internal
  22.      */
  23.     function sw_get_attribute(Environment $envSource $source$object$item, array $arguments = [], $type /* Template::ANY_CALL */ 'any'$isDefinedTest false$ignoreStrictCheck false$sandboxed falseint $lineno = -1)
  24.     {
  25.         try {
  26.             if ($object instanceof Entity) {
  27.                 FieldVisibility::$isInTwigRenderingContext true;
  28.                 $getter 'get' $item;
  29.                 return $object->$getter();
  30.             }
  31.             return twig_get_attribute($env$source$object$item$arguments$type$isDefinedTest$ignoreStrictCheck$sandboxed$lineno);
  32.         } catch (\Throwable $e) {
  33.             return twig_get_attribute($env$source$object$item$arguments$type$isDefinedTest$ignoreStrictCheck$sandboxed$lineno);
  34.         } finally {
  35.             FieldVisibility::$isInTwigRenderingContext false;
  36.         }
  37.     }
  38. }
  39. if (!\function_exists('Shopware\Core\Framework\Adapter\Twig\sw_escape_filter')) {
  40.     /**
  41.      * Escapes a string.
  42.      *
  43.      * @param mixed  $string     The value to be escaped
  44.      * @param string $strategy   The escaping strategy
  45.      * @param ?string $charset    The charset
  46.      * @param bool   $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
  47.      *
  48.      * @return string
  49.      */
  50.     function sw_escape_filter(Environment $env$stringstring $strategy 'html'$charset null$autoescape false)
  51.     {
  52.         if (\is_int($string)) {
  53.             $string = (string) $string;
  54.         }
  55.         static $strings = [];
  56.         $isString \is_string($string);
  57.         if ($isString && isset($strings[$string][$strategy])) {
  58.             return $strings[$string][$strategy];
  59.         }
  60.         $result twig_escape_filter($env$string$strategy$charset$autoescape);
  61.         if (!$isString) {
  62.             return $result;
  63.         }
  64.         $strings[$string][$strategy] = $result;
  65.         return $result;
  66.     }
  67. }