From 7bc42031ae5dcc6604bd545e7af986d12177b07c Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 14 Nov 2023 23:16:32 +0300 Subject: [PATCH] Adding convenience codegen(..) function --- src/codegen.inc.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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',