-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJavascriptRenderer.php
51 lines (42 loc) · 1.36 KB
/
JavascriptRenderer.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
50
51
<?php
namespace MagentoHackathon\Toolbar;
use DebugBar\JavascriptRenderer as BaseJavascriptRenderer;
use MagentoHackathon\Toolbar\Helper\Data as Helper;
use Magento\Framework\UrlInterface;
class JavascriptRenderer extends BaseJavascriptRenderer
{
/** @var UrlInterface */
protected $url;
public function __construct(Toolbar $debugBar, UrlInterface $url)
{
$this->url = $url;
parent::__construct($debugBar);
}
/**
* Renders the html to include needed assets
*
* @return string
*/
public function renderHead()
{
$cssUrl = $this->url->getUrl('hackathon_toolbar/assets/css?v=' . $this->getAssetsHash('css'));
$jsUrl = $this->url->getUrl('hackathon_toolbar/assets/js?v=' . $this->getAssetsHash('js'));
$html = "<link rel='stylesheet' type='text/css' property='stylesheet' href='{$cssUrl}'>";
$html .= "<script type='text/javascript' src='{$jsUrl}'></script>";
return $html;
}
/**
* Get the hash of the included assets, based on filename and modified time.
*
* @param string $type 'js' or 'css'
* @return string
*/
protected function getAssetsHash($type)
{
$assets = [];
foreach ($this->getAssets($type) as $file) {
$assets[$file] = filemtime($file);
}
return md5(serialize($assets));
}
}