]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use single resource locator instance
authorJulius Härtl <jus@bitgrid.net>
Thu, 17 Nov 2022 07:32:16 +0000 (08:32 +0100)
committerJulius Härtl <jus@bitgrid.net>
Wed, 7 Dec 2022 21:32:05 +0000 (22:32 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/private/Template/CSSResourceLocator.php
lib/private/Template/JSResourceLocator.php
lib/private/Template/ResourceLocator.php
lib/private/TemplateLayout.php

index 2cbf12ce65dd09b12ea5ecc77d7cf67a29b63278..beb5178476b9978d7f1159bc816d95180f76c4d6 100644 (file)
@@ -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);
        }
 
        /**
index 9e76655aba21b5f8956a28fffb2eeb7f4983e520..00cfde1f9f5e57a98f7d6b6da58fea4e662a285c 100644 (file)
@@ -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;
        }
index 5a50cc6fd1bf9a50a64da964876853025f45ffdd..dec74ed1ab83f9253823e24b18ece17dd88f8815 100755 (executable)
@@ -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();
        }
 
        /**
index e043f79745ac0e677b275bae95e3484b9102b398..aa1ee203f319705e46b55bb1473c4446a0dbef1c 100644 (file)
@@ -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();
        }
 
        /**