vendor/twig/twig/src/Resources/core.php line 85

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. use Twig\Environment;
  11. use Twig\Extension\CoreExtension;
  12. use Twig\Extension\SandboxExtension;
  13. use Twig\Source;
  14. use Twig\Template;
  15. /**
  16.  * @internal
  17.  *
  18.  * @deprecated since Twig 3.9
  19.  */
  20. function twig_cycle($values, $position)
  21. {
  22.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  23.     return CoreExtension::cycle($values, $position);
  24. }
  25. /**
  26.  * @internal
  27.  *
  28.  * @deprecated since Twig 3.9
  29.  */
  30. function twig_random(Environment $env, $values = null, $max = null)
  31. {
  32.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  33.     return CoreExtension::random($env->getCharset(), $values, $max);
  34. }
  35. /**
  36.  * @internal
  37.  *
  38.  * @deprecated since Twig 3.9
  39.  */
  40. function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null)
  41. {
  42.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  43.     return $env->getExtension(CoreExtension::class)->formatDate($date, $format, $timezone);
  44. }
  45. /**
  46.  * @internal
  47.  *
  48.  * @deprecated since Twig 3.9
  49.  */
  50. function twig_date_modify_filter(Environment $env, $date, $modifier)
  51. {
  52.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  53.     return $env->getExtension(CoreExtension::class)->modifyDate($date, $modifier);
  54. }
  55. /**
  56.  * @internal
  57.  *
  58.  * @deprecated since Twig 3.9
  59.  */
  60. function twig_sprintf($format, ...$values)
  61. {
  62.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  63.     return CoreExtension::sprintf($format, ...$values);
  64. }
  65. /**
  66.  * @internal
  67.  *
  68.  * @deprecated since Twig 3.9
  69.  */
  70. function twig_date_converter(Environment $env, $date = null, $timezone = null)
  71. {
  72.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  73.     return $env->getExtension(CoreExtension::class)->convertDate($date, $timezone);
  74. }
  75. /**
  76.  * @internal
  77.  *
  78.  * @deprecated since Twig 3.9
  79.  */
  80. function twig_replace_filter($str, $from)
  81. {
  82.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  83.     return CoreExtension::replace($str, $from);
  84. }
  85. /**
  86.  * @internal
  87.  *
  88.  * @deprecated since Twig 3.9
  89.  */
  90. function twig_round($value, $precision = 0, $method = 'common')
  91. {
  92.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  93.     return CoreExtension::round($value, $precision, $method);
  94. }
  95. /**
  96.  * @internal
  97.  *
  98.  * @deprecated since Twig 3.9
  99.  */
  100. function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
  101. {
  102.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  103.     return $env->getExtension(CoreExtension::class)->formatNumber($number, $decimal, $decimalPoint, $thousandSep);
  104. }
  105. /**
  106.  * @internal
  107.  *
  108.  * @deprecated since Twig 3.9
  109.  */
  110. function twig_urlencode_filter($url)
  111. {
  112.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  113.     return CoreExtension::urlencode($url);
  114. }
  115. /**
  116.  * @internal
  117.  *
  118.  * @deprecated since Twig 3.9
  119.  */
  120. function twig_array_merge(...$arrays)
  121. {
  122.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  123.     return CoreExtension::merge(...$arrays);
  124. }
  125. /**
  126.  * @internal
  127.  *
  128.  * @deprecated since Twig 3.9
  129.  */
  130. function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false)
  131. {
  132.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  133.     return CoreExtension::slice($env->getCharset(), $item, $start, $length, $preserveKeys);
  134. }
  135. /**
  136.  * @internal
  137.  *
  138.  * @deprecated since Twig 3.9
  139.  */
  140. function twig_first(Environment $env, $item)
  141. {
  142.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  143.     return CoreExtension::first($env->getCharset(), $item);
  144. }
  145. /**
  146.  * @internal
  147.  *
  148.  * @deprecated since Twig 3.9
  149.  */
  150. function twig_last(Environment $env, $item)
  151. {
  152.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  153.     return CoreExtension::last($env->getCharset(), $item);
  154. }
  155. /**
  156.  * @internal
  157.  *
  158.  * @deprecated since Twig 3.9
  159.  */
  160. function twig_join_filter($value, $glue = '', $and = null)
  161. {
  162.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  163.     return CoreExtension::join($value, $glue, $and);
  164. }
  165. /**
  166.  * @internal
  167.  *
  168.  * @deprecated since Twig 3.9
  169.  */
  170. function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
  171. {
  172.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  173.     return CoreExtension::split($env->getCharset(), $value, $delimiter, $limit);
  174. }
  175. /**
  176.  * @internal
  177.  *
  178.  * @deprecated since Twig 3.9
  179.  */
  180. function twig_get_array_keys_filter($array)
  181. {
  182.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  183.     return CoreExtension::keys($array);
  184. }
  185. /**
  186.  * @internal
  187.  *
  188.  * @deprecated since Twig 3.9
  189.  */
  190. function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
  191. {
  192.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  193.     return CoreExtension::reverse($env->getCharset(), $item, $preserveKeys);
  194. }
  195. /**
  196.  * @internal
  197.  *
  198.  * @deprecated since Twig 3.9
  199.  */
  200. function twig_sort_filter(Environment $env, $array, $arrow = null)
  201. {
  202.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  203.     return CoreExtension::sort($env, twig_resolve_is_sandboxed($env), $array, $arrow);
  204. }
  205. /**
  206.  * @internal
  207.  *
  208.  * @deprecated since Twig 3.9
  209.  */
  210. function twig_matches(string $regexp, ?string $str)
  211. {
  212.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  213.     return CoreExtension::matches($regexp, $str);
  214. }
  215. /**
  216.  * @internal
  217.  *
  218.  * @deprecated since Twig 3.9
  219.  */
  220. function twig_trim_filter($string, $characterMask = null, $side = 'both')
  221. {
  222.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  223.     return CoreExtension::trim($string, $characterMask, $side);
  224. }
  225. /**
  226.  * @internal
  227.  *
  228.  * @deprecated since Twig 3.9
  229.  */
  230. function twig_nl2br($string)
  231. {
  232.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  233.     return CoreExtension::nl2br($string);
  234. }
  235. /**
  236.  * @internal
  237.  *
  238.  * @deprecated since Twig 3.9
  239.  */
  240. function twig_spaceless($content)
  241. {
  242.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  243.     return CoreExtension::spaceless($content);
  244. }
  245. /**
  246.  * @internal
  247.  *
  248.  * @deprecated since Twig 3.9
  249.  */
  250. function twig_convert_encoding($string, $to, $from)
  251. {
  252.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  253.     return CoreExtension::convertEncoding($string, $to, $from);
  254. }
  255. /**
  256.  * @internal
  257.  *
  258.  * @deprecated since Twig 3.9
  259.  */
  260. function twig_length_filter(Environment $env, $thing)
  261. {
  262.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  263.     return CoreExtension::length($env->getCharset(), $thing);
  264. }
  265. /**
  266.  * @internal
  267.  *
  268.  * @deprecated since Twig 3.9
  269.  */
  270. function twig_upper_filter(Environment $env, $string)
  271. {
  272.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  273.     return CoreExtension::upper($env->getCharset(), $string);
  274. }
  275. /**
  276.  * @internal
  277.  *
  278.  * @deprecated since Twig 3.9
  279.  */
  280. function twig_lower_filter(Environment $env, $string)
  281. {
  282.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  283.     return CoreExtension::lower($env->getCharset(), $string);
  284. }
  285. /**
  286.  * @internal
  287.  *
  288.  * @deprecated since Twig 3.9
  289.  */
  290. function twig_striptags($string, $allowable_tags = null)
  291. {
  292.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  293.     return CoreExtension::striptags($string, $allowable_tags);
  294. }
  295. /**
  296.  * @internal
  297.  *
  298.  * @deprecated since Twig 3.9
  299.  */
  300. function twig_title_string_filter(Environment $env, $string)
  301. {
  302.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  303.     return CoreExtension::titleCase($env->getCharset(), $string);
  304. }
  305. /**
  306.  * @internal
  307.  *
  308.  * @deprecated since Twig 3.9
  309.  */
  310. function twig_capitalize_string_filter(Environment $env, $string)
  311. {
  312.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  313.     return CoreExtension::capitalize($env->getCharset(), $string);
  314. }
  315. /**
  316.  * @internal
  317.  *
  318.  * @deprecated since Twig 3.9
  319.  */
  320. function twig_test_empty($value)
  321. {
  322.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  323.     return CoreExtension::testEmpty($value);
  324. }
  325. /**
  326.  * @internal
  327.  *
  328.  * @deprecated since Twig 3.9
  329.  */
  330. function twig_test_iterable($value)
  331. {
  332.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  333.     return is_iterable($value);
  334. }
  335. /**
  336.  * @internal
  337.  *
  338.  * @deprecated since Twig 3.9
  339.  */
  340. function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
  341. {
  342.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  343.     return CoreExtension::include($env, $context, $template, $variables, $withContext, $ignoreMissing, $sandboxed);
  344. }
  345. /**
  346.  * @internal
  347.  *
  348.  * @deprecated since Twig 3.9
  349.  */
  350. function twig_source(Environment $env, $name, $ignoreMissing = false)
  351. {
  352.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  353.     return CoreExtension::source($env, $name, $ignoreMissing);
  354. }
  355. /**
  356.  * @internal
  357.  *
  358.  * @deprecated since Twig 3.9
  359.  */
  360. function twig_constant($constant, $object = null)
  361. {
  362.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  363.     return CoreExtension::constant($constant, $object);
  364. }
  365. /**
  366.  * @internal
  367.  *
  368.  * @deprecated since Twig 3.9
  369.  */
  370. function twig_constant_is_defined($constant, $object = null)
  371. {
  372.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  373.     return CoreExtension::constant($constant, $object, true);
  374. }
  375. /**
  376.  * @internal
  377.  *
  378.  * @deprecated since Twig 3.9
  379.  */
  380. function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
  381. {
  382.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  383.     return CoreExtension::batch($items, $size, $fill, $preserveKeys);
  384. }
  385. /**
  386.  * @internal
  387.  *
  388.  * @deprecated since Twig 3.9
  389.  */
  390. function twig_array_column(Environment $env, $array, $name, $index = null): array
  391. {
  392.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  393.     return CoreExtension::column($env, twig_resolve_is_sandboxed($env), $array, $name, $index);
  394. }
  395. /**
  396.  * @internal
  397.  *
  398.  * @deprecated since Twig 3.9
  399.  */
  400. function twig_array_filter(Environment $env, $array, $arrow)
  401. {
  402.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  403.     return CoreExtension::filter($env, twig_resolve_is_sandboxed($env), $array, $arrow);
  404. }
  405. /**
  406.  * @internal
  407.  *
  408.  * @deprecated since Twig 3.9
  409.  */
  410. function twig_array_map(Environment $env, $array, $arrow)
  411. {
  412.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  413.     return CoreExtension::map($env, twig_resolve_is_sandboxed($env), $array, $arrow);
  414. }
  415. /**
  416.  * @internal
  417.  *
  418.  * @deprecated since Twig 3.9
  419.  */
  420. function twig_array_reduce(Environment $env, $array, $arrow, $initial = null)
  421. {
  422.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  423.     return CoreExtension::reduce($env, twig_resolve_is_sandboxed($env), $array, $arrow, $initial);
  424. }
  425. /**
  426.  * @internal
  427.  *
  428.  * @deprecated since Twig 3.9
  429.  */
  430. function twig_array_some(Environment $env, $array, $arrow)
  431. {
  432.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  433.     return CoreExtension::arraySome($env, $array, $arrow, twig_resolve_is_sandboxed($env));
  434. }
  435. /**
  436.  * @internal
  437.  *
  438.  * @deprecated since Twig 3.9
  439.  */
  440. function twig_array_every(Environment $env, $array, $arrow)
  441. {
  442.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  443.     return CoreExtension::arrayEvery($env, $array, $arrow, twig_resolve_is_sandboxed($env));
  444. }
  445. /**
  446.  * @internal
  447.  *
  448.  * @deprecated since Twig 3.9
  449.  */
  450. function twig_check_arrow_in_sandbox(Environment $env, $arrow, $thing, $type): void
  451. {
  452.     trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
  453.     CoreExtension::checkArrow(twig_resolve_is_sandboxed($env), $arrow, $thing, $type);
  454. }
  455. /**
  456.  * Recovers the calling Template's Source by walking the PHP backtrace.
  457.  *
  458.  * @internal
  459.  */
  460. function twig_resolve_caller_source(): ?Source
  461. {
  462.     foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $trace) {
  463.         if (isset($trace['object']) && $trace['object'] instanceof Template) {
  464.             return $trace['object']->getSourceContext();
  465.         }
  466.     }
  467.     return null;
  468. }
  469. /**
  470.  * @internal
  471.  */
  472. function twig_resolve_is_sandboxed(Environment $env): bool
  473. {
  474.     if (!$env->hasExtension(SandboxExtension::class)) {
  475.         return false;
  476.     }
  477.     return $env->getExtension(SandboxExtension::class)->isSandboxed(twig_resolve_caller_source());
  478. }