mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-28 19:17:37 +00:00
Simplify code
This commit is contained in:
+10
-1
@@ -235,12 +235,21 @@ abstract class Template
|
||||
*/
|
||||
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
|
||||
{
|
||||
$level = ob_get_level();
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
$this->displayBlock($name, $context, $blocks, $useBlocks);
|
||||
try {
|
||||
$this->displayBlock($name, $context, $blocks, $useBlocks);
|
||||
} catch (\Throwable $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
+1
-18
@@ -60,24 +60,7 @@ final class TemplateWrapper
|
||||
|
||||
public function renderBlock(string $name, array $context = []): string
|
||||
{
|
||||
$context = $this->env->mergeGlobals($context);
|
||||
$level = ob_get_level();
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
try {
|
||||
$this->template->displayBlock($name, $context);
|
||||
} catch (\Throwable $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
return $this->template->renderBlock($name, $this->env->mergeGlobals($context));
|
||||
}
|
||||
|
||||
public function displayBlock(string $name, array $context = [])
|
||||
|
||||
@@ -130,13 +130,7 @@ class TemplateTest extends TestCase
|
||||
|
||||
$twig = new Environment($this->createMock(LoaderInterface::class));
|
||||
$template = new TemplateForTest($twig, 'index.twig');
|
||||
try {
|
||||
$template->renderBlock('unknown', []);
|
||||
} catch (\Exception $e) {
|
||||
ob_end_clean();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
$template->renderBlock('unknown', []);
|
||||
}
|
||||
|
||||
public function testDisplayBlockWithUndefinedBlock()
|
||||
|
||||
Reference in New Issue
Block a user