2828namespace OC \Template ;
2929
3030use OCP \App \AppPathNotFoundException ;
31+ use OCP \App \IAppManager ;
3132use Psr \Log \LoggerInterface ;
32- use \OCP \App \IAppManager ;
3333
3434class JSResourceLocator extends ResourceLocator {
35- /** @var JSCombiner */
36- protected $ jsCombiner ;
37-
38- /** @var IAppManager */
39- protected $ appManager ;
35+ protected JSCombiner $ jsCombiner ;
36+ protected IAppManager $ appManager ;
4037
4138 public function __construct (LoggerInterface $ logger , JSCombiner $ JSCombiner , IAppManager $ appManager ) {
4239 parent ::__construct ($ logger );
@@ -86,41 +83,36 @@ public function doFind($script) {
8683 }
8784
8885 $ script = substr ($ script , strpos ($ script , '/ ' ) + 1 );
89- $ app_path = false ;
90- $ app_url = false ;
86+ $ app_url = null ;
9187
9288 try {
93- $ app_path = $ this ->appManager ->getAppPath ($ app );
94- // Account for the possibility of having symlinks in app path. Only
95- // do this if $app_path is set, because an empty argument to realpath
96- // gets turned into cwd.
97- $ app_path = realpath ($ app_path );
89+ $ app_url = $ this ->appManager ->getAppWebPath ($ app );
9890 } catch (AppPathNotFoundException ) {
9991 // pass
10092 }
10193
10294 try {
103- $ app_url = $ this ->appManager ->getAppWebPath ($ app );
104- } catch (AppPathNotFoundException ) {
105- // pass
106- }
95+ $ app_path = $ this ->appManager ->getAppPath ($ app );
10796
108- // missing translations files fill be ignored
109- if (strpos ($ script , 'l10n/ ' ) === 0 ) {
110- $ this ->appendScriptIfExist ($ app_path , $ script , $ app_url );
111- return ;
112- }
97+ // Account for the possibility of having symlinks in app path. Only
98+ // do this if $app_path is set, because an empty argument to realpath
99+ // gets turned into cwd.
100+ $ app_path = realpath ($ app_path );
113101
114- if ($ app_path === false && $ app_url === false ) {
102+ // missing translations files will be ignored
103+ if (strpos ($ script , 'l10n/ ' ) === 0 ) {
104+ $ this ->appendScriptIfExist ($ app_path , $ script , $ app_url );
105+ return ;
106+ }
107+
108+ if (!$ this ->cacheAndAppendCombineJsonIfExist ($ app_path , $ script .'.json ' , $ app )) {
109+ $ this ->appendScriptIfExist ($ app_path , $ script , $ app_url );
110+ }
111+ } catch (AppPathNotFoundException ) {
115112 $ this ->logger ->error ('Could not find resource {resource} to load ' , [
116113 'resource ' => $ app . '/ ' . $ script . '.js ' ,
117114 'app ' => 'jsresourceloader ' ,
118115 ]);
119- return ;
120- }
121-
122- if (!$ this ->cacheAndAppendCombineJsonIfExist ($ app_path , $ script .'.json ' , $ app )) {
123- $ this ->append ($ app_path , $ script . '.js ' , $ app_url );
124116 }
125117 }
126118
@@ -134,7 +126,7 @@ public function doFindTheme($script) {
134126 * Try to find ES6 script file (`.mjs`) with fallback to plain javascript (`.js`)
135127 * @see appendIfExist()
136128 */
137- protected function appendScriptIfExist ($ root , $ file , $ webRoot = null ) {
129+ protected function appendScriptIfExist (string $ root , string $ file , string $ webRoot = null ) {
138130 if (!$ this ->appendIfExist ($ root , $ file . '.mjs ' , $ webRoot )) {
139131 return $ this ->appendIfExist ($ root , $ file . '.js ' , $ webRoot );
140132 }
0 commit comments