public function renderJs()
{
$jsFileList = $this->getJsFileList();
if ($jsFileList->count() == 0) {
return '';
}
$generate = true;
$bundlePath = $this->getJsBundlePath();
if (!$this->getForce() && file_exists($bundlePath)) {
$cacheTime = filemtime($bundlePath);
if (false !== $cacheTime && $cacheTime >= $jsFileList->getMaxMTime()) {
$generate = false;
}
}
$bundleUrl = $this->getJsBundleUrl();
if ($generate) {
$data = '';
$filter = $this->getJsFilter();
foreach ($jsFileList as $file => $fileInfo) {
$data .= '/* --------- ' . $file . ' --------- */' . PHP_EOL;
$contents = @file_get_contents($fileInfo->getPathname());
if (!$contents) {
$data .= '/* FILE READ ERROR! */' . PHP_EOL;
} else {
if (null !== $filter) {
$contents = $filter->filterFile($contents, $file, $fileInfo, $bundleUrl, $bundlePath);
}
$data .= $contents . PHP_EOL;
}
}
if (null !== $filter) {
$data = $filter->filter($data);
}
$cacheTime = $this->writeBundleFile($bundlePath, $data);
}
$template = $this->getJsTemplate();
if (is_callable($template)) {
return call_user_func($template, $bundleUrl, $cacheTime);
}
return sprintf($template, $bundleUrl, $cacheTime);
}