/** * Close tag {/block} * @param Tokenizer $tokens * @param Scope $scope * @return string */ public static function tagBlockClose($tokens, Scope $scope) { $tpl = $scope->tpl; if (isset($tpl->_extends)) { // is child if ($scope["name"]) { // is scalar name if ($tpl->_compatible) { // is compatible mode $scope->replaceContent('<?php /* 1) Block ' . $tpl . ': ' . $scope["cname"] . ' */' . PHP_EOL . ' if(empty($tpl->b[' . $scope["cname"] . '])) { ' . '$tpl->b[' . $scope["cname"] . '] = function($tpl) { ?>' . PHP_EOL . $scope->getContent() . "<?php };" . "} ?>" . PHP_EOL); } elseif (!isset($tpl->blocks[$scope["name"]])) { // is block not registered $tpl->blocks[$scope["name"]] = $scope->getContent(); $scope->replaceContent('<?php /* 2) Block ' . $tpl . ': ' . $scope["cname"] . ' ' . $tpl->_compatible . ' */' . PHP_EOL . ' $tpl->b[' . $scope["cname"] . '] = function($tpl) { ?>' . PHP_EOL . $scope->getContent() . "<?php }; ?>" . PHP_EOL); } } else { // dynamic name $tpl->_compatible = true; // enable compatible mode $scope->replaceContent('<?php /* 3) Block ' . $tpl . ': ' . $scope["cname"] . ' */' . PHP_EOL . ' if(empty($tpl->b[' . $scope["cname"] . '])) { ' . '$tpl->b[' . $scope["cname"] . '] = function($tpl) { ?>' . PHP_EOL . $scope->getContent() . "<?php };" . "} ?>" . PHP_EOL); } } else { // is parent if (isset($tpl->blocks[$scope["name"]])) { // has block if ($tpl->_compatible) { // compatible mode enabled $scope->replaceContent('<?php /* 4) Block ' . $tpl . ': ' . $scope["cname"] . ' */' . PHP_EOL . ' if(isset($tpl->b[' . $scope["cname"] . '])) { echo $tpl->b[' . $scope["cname"] . ']->__invoke($tpl); } else {?>' . PHP_EOL . $tpl->blocks[$scope["name"]] . '<?php } ?>' . PHP_EOL); } else { $scope->replaceContent($tpl->blocks[$scope["name"]]); } // } elseif(isset($tpl->_extended) || !empty($tpl->_compatible)) { } elseif (isset($tpl->_extended) && $tpl->_compatible || empty($tpl->_extended)) { $scope->replaceContent('<?php /* 5) Block ' . $tpl . ': ' . $scope["cname"] . ' */' . PHP_EOL . ' if(isset($tpl->b[' . $scope["cname"] . '])) { echo $tpl->b[' . $scope["cname"] . ']->__invoke($tpl); } else {?>' . PHP_EOL . $scope->getContent() . '<?php } ?>' . PHP_EOL); } } return ''; }