/**
* @param string $template
* @return array
* @throws \Werkint\Bundle\TemplatingBundle\Exception\TemplateNotFoundException
*/
public function parse($template)
{
$modules = [$template];
$worked = [];
while ($name = array_shift($modules)) {
if (isset($worked[$name])) {
continue;
}
try {
$source = $this->templating->getLoader()->getSource($name);
} catch (\Twig_Error_Loader $exception) {
throw new TemplateNotFoundException($template);
}
// Инклуды
preg_match_all('!%\\s*(include|extends)\\s*(.+?)\\s+!', $source, $m);
$m = array_map(function ($name) {
return substr($name, 1, strlen($name) - 2);
}, array_filter($m[2], function ($name) {
return preg_match('!^[\'"].+?[\'"]$!', $name);
}));
$modules = array_merge($modules, $m);
$worked[$name] = $source;
}
return $worked;
}