/
LeftAndMainExtension.php
49 lines (43 loc) · 1.61 KB
/
LeftAndMainExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace SilverStripe\Raygun;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Environment;
use SilverStripe\View\Requirements;
/**
* Raygun crash reporting front-end integration for silverstripe/admin
*/
class LeftAndMainExtension extends Extension
{
use CustomAppKeyProvider;
/**
* It may seem weird we're using this extension point to register raygun, but
* that's important to register it before the other scripts start executing,
* otherwise we may miss some errors in the bundles
*/
public function accessedCMS()
{
$apiKey = $this->getCustomRaygunAppKey() ?? Environment::getEnv(RaygunClientFactory::RAYGUN_APP_KEY_NAME);
if (empty($apiKey)) {
Requirements::insertHeadTags('<!-- Raygun app key is undefined -->');
} else {
$htmlBlock = <<<HTML
<!-- Raygun -->
<script type="text/javascript">
!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){
(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],
f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){
h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({
e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/raygun.min.js","rg4js");
</script>
<!-- End Raygun -->
<!-- Raygun crash reporting -->
<script type="text/javascript">
rg4js('apiKey', '$apiKey');
rg4js('enableCrashReporting', true);
</script>
<!-- End Raygun crash reporting -->
HTML;
Requirements::insertHeadTags($htmlBlock, hash('crc32', $htmlBlock) . '-' . $apiKey);
}
}
}