Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport25] Dependency injection of JSResourceLocator #254

Open
wants to merge 2 commits into
base: stable25
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
namespace OC;

use bantu\IniGetWrapper\IniGetWrapper;
use OC\AppFramework\Utility\QueryNotFoundException;
use OC\Search\SearchQuery;
use OC\Template\JSCombiner;
use OC\Template\JSConfigHelper;
use OC\Template\JSResourceLocator;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Defaults;
use OCP\IConfig;
Expand All @@ -68,6 +70,9 @@ class TemplateLayout extends \OC_Template {
/** @var INavigationManager */
private $navigationManager;

/** @var JSResourceLocator|null */
public static $jsLocator = null;

/**
* @param string $renderAs
* @param string $appId application id
Expand Down Expand Up @@ -374,16 +379,24 @@ public function getAppNamefromPath($path) {
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)
try {
// we need the injected form coming with stable26
if (self::$jsLocator === null) {
self::$jsLocator = \OCP\Server::get(JSResourceLocator::class);
}
} catch (QueryNotFoundException $eInject) {
// but keep the old version just in case theming is not available
self::$jsLocator = new 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();
}

self::$jsLocator->find($scripts);
return self::$jsLocator->getResources();
}

/**
Expand Down