*/
namespace OC\Template;
+use OC\SystemConfig;
use OCP\ICache;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
/** @var ICache */
protected $depsCache;
+ /** @var SystemConfig */
+ protected $config;
+
/**
* JSCombiner constructor.
*
*/
public function __construct(IAppData $appData,
IURLGenerator $urlGenerator,
- ICache $depsCache) {
+ ICache $depsCache,
+ SystemConfig $config) {
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->depsCache = $depsCache;
+ $this->config = $config;
}
/**
* @return bool
*/
public function process($root, $file, $app) {
+ if ($this->config->getValue('debug')) {
+ return false;
+ }
+
$path = explode('/', $root . '/' . $file);
$fileName = array_pop($path);
return substr($this->urlGenerator->linkToRoute('core.Js.getJs', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1);
}
+
+ /**
+ * @param string $root
+ * @param string $file
+ * @return string[]
+ */
+ public function getContent($root, $file) {
+ $data = json_decode(file_get_contents($root . '/' . $file));
+
+ $path = explode('/', $file);
+ array_pop($path);
+ $path = implode('/', $path);
+
+ $result = [];
+ foreach ($data as $f) {
+ $result[] = $path . '/' . $f;
+ }
+
+ return $result;
+ }
}
if ($this->jsCombiner->process($root, $file, $app)) {
$this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
return true;
+ } else {
+ // Add all the files from the json
+ $files = $this->jsCombiner->getContent($root, $file);
+ $app_url = \OC_App::getAppWebPath($app);
+
+ foreach ($files as $jsFile) {
+ $this->append($root, $jsFile, $app_url);
+ }
}
}
new JSCombiner(
\OC::$server->getAppDataDir('js'),
\OC::$server->getURLGenerator(),
- \OC::$server->getMemCacheFactory()->create('JS')
+ \OC::$server->getMemCacheFactory()->create('JS'),
+ \OC::$server->getSystemConfig()
)
);
$locator->find($scripts);