PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.3
Elementor Website Builder – more than just a page builder v3.28.3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / vendor_prefixed / twig / src / Util / DeprecationCollector.php

DeprecationCollector.php in Elementor Website Builder – more than just a page builder 3.28.3, at vendor_prefixed/twig/src/Util/DeprecationCollector.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 namespace ElementorDeps\Twig\Util;
12
13 use ElementorDeps\Twig\Environment;
14 use ElementorDeps\Twig\Error\SyntaxError;
15 use ElementorDeps\Twig\Source;
16 /**
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 final class DeprecationCollector
20 {
21 private $twig;
22 public function __construct(Environment $twig)
23 {
24 $this->twig = $twig;
25 }
26 /**
27 * Returns deprecations for templates contained in a directory.
28 *
29 * @param string $dir A directory where templates are stored
30 * @param string $ext Limit the loaded templates by extension
31 *
32 * @return array An array of deprecations
33 */
34 public function collectDir(string $dir, string $ext = '.twig') : array
35 {
36 $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY), '{' . \preg_quote($ext) . '$}');
37 return $this->collect(new TemplateDirIterator($iterator));
38 }
39 /**
40 * Returns deprecations for passed templates.
41 *
42 * @param \Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template)
43 *
44 * @return array An array of deprecations
45 */
46 public function collect(\Traversable $iterator) : array
47 {
48 $deprecations = [];
49 \set_error_handler(function ($type, $msg) use(&$deprecations) {
50 if (\E_USER_DEPRECATED === $type) {
51 $deprecations[] = $msg;
52 }
53 return \false;
54 });
55 foreach ($iterator as $name => $contents) {
56 try {
57 $this->twig->parse($this->twig->tokenize(new Source($contents, $name)));
58 } catch (SyntaxError $e) {
59 // ignore templates containing syntax errors
60 }
61 }
62 \restore_error_handler();
63 return $deprecations;
64 }
65 }
66