Twig_Util_DeprecationCollector

The WooCommerce Multilingual Twig Util DeprecationCollector class.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/Util/DeprecationCollector.php  
  1. class Twig_Util_DeprecationCollector 
  2. private $twig; 
  3. private $deprecations; 
  4.  
  5. public function __construct(Twig_Environment $twig) 
  6. $this->twig = $twig; 
  7.  
  8. /** 
  9. * Returns deprecations for templates contained in a directory. 
  10. * @param string $dir A directory where templates are stored 
  11. * @param string $ext Limit the loaded templates by extension 
  12. * @return array An array of deprecations 
  13. */ 
  14. public function collectDir($dir, $ext = '.twig') 
  15. $iterator = new RegexIterator( 
  16. new RecursiveIteratorIterator( 
  17. new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY 
  18. ), '{'.preg_quote($ext).'$}' 
  19. ); 
  20.  
  21. return $this->collect(new Twig_Util_TemplateDirIterator($iterator)); 
  22.  
  23. /** 
  24. * Returns deprecations for passed templates. 
  25. * @param Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) 
  26. * @return array An array of deprecations 
  27. */ 
  28. public function collect(Traversable $iterator) 
  29. $this->deprecations = array(); 
  30.  
  31. set_error_handler(array($this, 'errorHandler')); 
  32.  
  33. foreach ($iterator as $name => $contents) { 
  34. try { 
  35. $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name))); 
  36. } catch (Twig_Error_Syntax $e) { 
  37. // ignore templates containing syntax errors 
  38.  
  39. restore_error_handler(); 
  40.  
  41. $deprecations = $this->deprecations; 
  42. $this->deprecations = array(); 
  43.  
  44. return $deprecations; 
  45.  
  46. /** 
  47. * @internal 
  48. */ 
  49. public function errorHandler($type, $msg) 
  50. if (E_USER_DEPRECATED === $type) { 
  51. $this->deprecations[] = $msg;