Ejemplo n.º 1
0
 /**
  * Setup scripts.
  *
  * @param ReportRouting $reportRouting
  */
 protected function setScripts(ReportRouting $reportRouting)
 {
     $report = $reportRouting->getReport();
     $scripts = $report->getScripts();
     $content = $report->getResponse();
     $doc = new \DOMDocument();
     $doc->loadHTML($content);
     $heads = $doc->getElementsByTagName('head');
     if ($heads->length == 0) {
         /* If no head is created, add it at the top of HTML */
         $head = $doc->createElement('head');
         $html = $doc->getElementsByTagName('html');
         $html->item(0)->insertBefore($head, $html->item(0)->firstChild);
     } else {
         $head = $heads->item(0);
     }
     foreach ($scripts as $script) {
         $url = $reportRouting->getUrl($script);
         $element = $doc->createElement('script');
         $element->setAttribute('type', 'text/javascript');
         $element->setAttribute('src', $url);
         $head->appendChild($element);
     }
     $report->setResponse($doc->saveHTML());
 }