diff --git a/src/bind.inc.php b/src/bind.inc.php index 43b9301..51af1c1 100644 --- a/src/bind.inc.php +++ b/src/bind.inc.php @@ -2,6 +2,8 @@ namespace bhl_bind; use Exception; +$GLOBALS['BHL_BIND_WARNS'] = array(); + function supported_tokens() { return [ @@ -48,7 +50,11 @@ function codegen( $twig->addGlobal('plugins', $options['plugins']); - return $twig->render('codegen_autobind.twig', $options); + $str = $twig->render('codegen_autobind.twig', $options); + + print_warnings(); + + return $str; } function get_twig(array $inc_path = []) @@ -320,13 +326,19 @@ function add_twig_support(\Twig\Environment $twig) function Warn($msg) { - //NOTE: we can't just echo the value because it will - // be rendered into resulting code - register_shutdown_function(function() use($msg) { - echo "BHL BIND WARN: $msg\n"; - }); + global $BHL_BIND_WARNS; + $BHL_BIND_WARNS[] = $msg; } +function print_warnings() +{ + global $BHL_BIND_WARNS; + + foreach($BHL_BIND_WARNS as $msg) + echo "BHL BIND WARN: $msg\n"; +} + + function paginate($total, $step) { //pages are returned as an array where each element is in interval [N, Y)