ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DeprecationCollector.php
Go to the documentation of this file.
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
18{
19 private $twig;
21
23 {
24 $this->twig = $twig;
25 }
26
35 public function collectDir($dir, $ext = '.twig')
36 {
37 $iterator = new RegexIterator(
38 new RecursiveIteratorIterator(
39 new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY
40 ), '{'.preg_quote($ext).'$}'
41 );
42
43 return $this->collect(new Twig_Util_TemplateDirIterator($iterator));
44 }
45
53 public function collect(Traversable $iterator)
54 {
55 $this->deprecations = array();
56
57 set_error_handler(array($this, 'errorHandler'));
58
59 foreach ($iterator as $name => $contents) {
60 try {
61 $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name)));
62 } catch (Twig_Error_Syntax $e) {
63 // ignore templates containing syntax errors
64 }
65 }
66
67 restore_error_handler();
68
70 $this->deprecations = array();
71
72 return $deprecations;
73 }
74
78 public function errorHandler($type, $msg)
79 {
80 if (E_USER_DEPRECATED === $type) {
81 $this->deprecations[] = $msg;
82 }
83 }
84}
85
86class_alias('Twig_Util_DeprecationCollector', 'Twig\Util\DeprecationCollector', false);
An exception for terminatinating execution or to throw for unit testing.
Stores the Twig configuration.
Definition: Environment.php:18
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Holds information about a non-compiled Twig template.
Definition: Source.php:20
collectDir($dir, $ext='.twig')
Returns deprecations for templates contained in a directory.
collect(Traversable $iterator)
Returns deprecations for passed templates.
__construct(Twig_Environment $twig)
$type