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