diff --git a/src/codegen.inc.php b/src/codegen.inc.php index ba19a31..66fab35 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -2,7 +2,23 @@ namespace metagen_cs; use Exception; -function get_twig(array $inc_path = []) +function codegen(?string $cache_dir, \mtgMetaInfo $meta, array $options = []) : string +{ + $twig = get_twig(); + + if(!empty($cache_dir)) + $twig->setCache($cache_dir); + + $twig->addGlobal('meta', $meta); + + $options['meta'] = $meta; + if(!isset($options['namespace'])) + $options['namespace'] = 'BitGames.Autogen'; + + return $twig->render('codegen_bundle.twig', $options); +} + +function get_twig(array $inc_path = []) : \Twig\Environment { array_unshift($inc_path, __DIR__ . "/../tpl/"); $loader = new \Twig\Loader\FilesystemLoader($inc_path); @@ -19,7 +35,7 @@ function get_twig(array $inc_path = []) return $twig; } -function supported_tokens() +function supported_tokens() : array { return [ 'POD',