File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
+
2
3
namespace BeyondCode \QueryDetector \Outputs ;
4
+
3
5
use Illuminate \Support \Collection ;
4
6
use Symfony \Component \HttpFoundation \Response ;
5
7
@@ -10,18 +12,25 @@ public function output(Collection $detectedQueries, Response $response)
10
12
if ($ response ->isRedirection ()) {
11
13
return ;
12
14
}
15
+
13
16
$ content = $ response ->getContent ();
17
+
14
18
$ outputContent = $ this ->getOutputContent ($ detectedQueries );
19
+
15
20
$ pos = strripos ($ content , '</body> ' );
21
+
16
22
if (false !== $ pos ) {
17
23
$ content = substr ($ content , 0 , $ pos ) . $ outputContent . substr ($ content , $ pos );
18
24
} else {
19
25
$ content = $ content . $ outputContent ;
20
26
}
27
+
21
28
// Update the new content and reset the content length
22
29
$ response ->setContent ($ content );
30
+
23
31
$ response ->headers ->remove ('Content-Length ' );
24
32
}
33
+
25
34
protected function getOutputContent (Collection $ detectedQueries )
26
35
{
27
36
$ output = '<script type="text/javascript"> ' ;
@@ -33,6 +42,7 @@ protected function getOutputContent(Collection $detectedQueries)
33
42
}
34
43
$ output .= "') " ;
35
44
$ output .= '</script> ' ;
45
+
36
46
return $ output ;
37
47
}
38
48
}
You can’t perform that action at this time.
0 commit comments