ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
20  private $deprecations;
21 
23  {
24  $this->twig = $twig;
25  }
26 
35  public function collectDir($dir, $ext = '.twig')
36  {
37  $iterator = new RegexIterator(
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 
86 class_alias('Twig_Util_DeprecationCollector', 'Twig\Util\DeprecationCollector', false);
$type
__construct(Twig_Environment $twig)
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
if($format !==null) $name
Definition: metadata.php:146
collectDir($dir, $ext='.twig')
Returns deprecations for templates contained in a directory.
Create styles array
The data for the language used.
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17
collect(Traversable $iterator)
Returns deprecations for passed templates.