Use single resource locator instance

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/35223/head
Julius Härtl 4 years ago
parent b2af916872
commit 3e5838198c
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
  1. 10
      lib/private/Template/CSSResourceLocator.php
  2. 4
      lib/private/Template/JSResourceLocator.php
  3. 17
      lib/private/Template/ResourceLocator.php
  4. 43
      lib/private/TemplateLayout.php

@ -34,14 +34,8 @@ namespace OC\Template;
use Psr\Log\LoggerInterface;
class CSSResourceLocator extends ResourceLocator {
/**
* @param string $theme
* @param array $core_map
* @param array $party_map
*/
public function __construct(LoggerInterface $logger, $theme, $core_map, $party_map) {
parent::__construct($logger, $theme, $core_map, $party_map);
public function __construct(LoggerInterface $logger) {
parent::__construct($logger);
}
/**

@ -34,8 +34,8 @@ class JSResourceLocator extends ResourceLocator {
/** @var JSCombiner */
protected $jsCombiner;
public function __construct(LoggerInterface $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) {
parent::__construct($logger, $theme, $core_map, $party_map);
public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner) {
parent::__construct($logger);
$this->jsCombiner = $JSCombiner;
}

@ -43,18 +43,15 @@ abstract class ResourceLocator {
protected LoggerInterface $logger;
/**
* @param string $theme
* @param array $core_map
* @param array $party_map
*/
public function __construct(LoggerInterface $logger, $theme, $core_map, $party_map) {
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
$this->theme = $theme;
$this->mapping = $core_map + $party_map;
$this->serverroot = key($core_map);
$this->thirdpartyroot = key($party_map);
$this->mapping = [
\OC::$SERVERROOT => \OC::$WEBROOT
];
$this->serverroot = \OC::$SERVERROOT;
$this->thirdpartyroot = \OC::$SERVERROOT;
$this->webroot = $this->mapping[$this->serverroot];
$this->theme = \OC_Util::getTheme();
}
/**

@ -44,8 +44,9 @@ namespace OC;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\Search\SearchQuery;
use OC\Template\JSCombiner;
use OC\Template\CSSResourceLocator;
use OC\Template\JSConfigHelper;
use OC\Template\JSResourceLocator;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Defaults;
use OCP\IConfig;
@ -54,11 +55,16 @@ use OCP\INavigationManager;
use OCP\IUserSession;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;
use Psr\Log\LoggerInterface;
class TemplateLayout extends \OC_Template {
private static $versionHash = '';
/** @var CSSResourceLocator|null */
public static $cssLocator = null;
/** @var JSResourceLocator|null */
public static $jsLocator = null;
/** @var IConfig */
private $config;
@ -332,17 +338,11 @@ class TemplateLayout extends \OC_Template {
* @return array
*/
public static function findStylesheetFiles($styles, $compileScss = true) {
// Read the selected theme from the config file
$theme = \OC_Util::getTheme();
$locator = new \OC\Template\CSSResourceLocator(
\OC::$server->get(LoggerInterface::class),
$theme,
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
);
$locator->find($styles);
return $locator->getResources();
if (!self::$cssLocator) {
self::$cssLocator = \OCP\Server::get(CSSResourceLocator::class);
}
self::$cssLocator->find($styles);
return self::$cssLocator->getResources();
}
/**
@ -366,18 +366,11 @@ class TemplateLayout extends \OC_Template {
* @return array
*/
public static function findJavascriptFiles($scripts) {
// Read the selected theme from the config file
$theme = \OC_Util::getTheme();
$locator = new \OC\Template\JSResourceLocator(
\OC::$server->get(LoggerInterface::class),
$theme,
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
\OC::$server->query(JSCombiner::class)
);
$locator->find($scripts);
return $locator->getResources();
if (!self::$jsLocator) {
self::$jsLocator = \OCP\Server::get(JSResourceLocator::class);
}
self::$jsLocator->find($scripts);
return self::$jsLocator->getResources();
}
/**

Loading…
Cancel
Save