Skip to content

Commit bc80685

Browse files
committed
update: twig extension
1 parent 61c8ba4 commit bc80685

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Tests/SymfonyRollbarBundle/Twig/RollbarExtensionTest.php

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public function testRollbarJs($env, $isDisabled)
4141
$this->assertNotEmpty($list);
4242

4343
$function = $list[0];
44-
$this->assertInstanceOf(\Twig_Function::class, $function);
44+
$this->assertInstanceOf(\Twig_SimpleFunction::class, $function);
4545

4646
$output = $rollbarTwig->rollbarJs();
4747
$this->assertContains('_rollbarConfig', $output);
4848
$this->assertContains('SOME_ROLLBAR_ACCESS_TOKEN_654321', $output);
49+
$this->assertContains('_rollbarConfig.rollbarJsUrl', $output);
4950
}
5051
}
5152

@@ -57,7 +58,7 @@ public function generatorRollbarEnv()
5758
return [
5859
// env, is-empty-functions
5960
['test', false],
60-
// ['test_drb', true],
61+
['test_drb', true],
6162
];
6263
}
6364
}

Twig/RollbarExtension.php

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SymfonyRollbarBundle\Twig;
44

5+
use Rollbar\RollbarJsHelper;
56
use Symfony\Component\DependencyInjection\ContainerInterface;
67
use SymfonyRollbarBundle\DependencyInjection\SymfonyRollbarExtension;
78

@@ -43,7 +44,7 @@ public function getFunctions()
4344
}
4445

4546
return [
46-
new \Twig_Function('rollbarJs', [$this, 'rollbarJs']),
47+
new \Twig_SimpleFunction('rollbarJs', [$this, 'rollbarJs']),
4748
];
4849
}
4950

@@ -52,13 +53,12 @@ public function getFunctions()
5253
*/
5354
public function rollbarJs()
5455
{
55-
$js = ''; // /vendor/rollbar/rollbar/data/rollbar.snippet.js
56-
$script = "<script>var _rollbarConfig = {{config}};\n{{rollbar-snippet}}</script>";
57-
$config = $this->config['rollbar_js'];
56+
$helper = new RollbarJsHelper($this->config['rollbar_js']);
5857

58+
$script = "<script>var _rollbarConfig = {{config}};\n{{rollbar-snippet}}</script>";
5959
$script = strtr($script, [
60-
'{{config}}' => json_encode($config),
61-
'{{rollbar-snippet}}' => $js,
60+
'{{config}}' => $helper->configJsTag(),
61+
'{{rollbar-snippet}}' => $helper->jsSnippet(),
6262
]);
6363

6464
return $script;

0 commit comments

Comments
 (0)