3434use OC \AppFramework \DependencyInjection \DIContainer ;
3535use OC \AppFramework \Http \Dispatcher ;
3636use OC \AppFramework \Http \Request ;
37- use OCP \App \IAppManager ;
38- use OCP \Profiler \IProfiler ;
3937use OC \Profiler \RoutingDataCollector ;
40- use OCP \AppFramework \QueryException ;
4138use OCP \AppFramework \Http ;
4239use OCP \AppFramework \Http \ICallbackResponse ;
4340use OCP \AppFramework \Http \IOutput ;
41+ use OCP \AppFramework \QueryException ;
4442use OCP \Diagnostics \IEventLogger ;
4543use OCP \HintException ;
4644use OCP \IRequest ;
45+ use OCP \Profiler \IProfiler ;
4746
4847/**
4948 * Entry point for every request in your app. You can consider this as your
@@ -69,7 +68,7 @@ public static function buildAppNamespace(string $appId, string $topNamespace = '
6968 return $ topNamespace . self ::$ nameSpaceCache [$ appId ];
7069 }
7170
72- $ appInfo = \ OCP \Server:: get (IAppManager::class)-> getAppInfo ($ appId );
71+ $ appInfo = self :: getAppInfo ($ appId );
7372 if (isset ($ appInfo ['namespace ' ])) {
7473 self ::$ nameSpaceCache [$ appId ] = trim ($ appInfo ['namespace ' ]);
7574 } else {
@@ -91,11 +90,42 @@ public static function buildAppNamespace(string $appId, string $topNamespace = '
9190 return $ topNamespace . self ::$ nameSpaceCache [$ appId ];
9291 }
9392
93+ public static function getAppInfo (string $ appId , bool $ path = false , $ lang = null ) {
94+ if ($ path ) {
95+ $ file = $ appId ;
96+ } else {
97+ try {
98+ if ($ appPath = \OC_App::findAppInDirectories ($ appId , true )) {
99+ $ appPath = $ appPath ['path ' ] . '/ ' . $ appId ;
100+ }
101+ } catch (\OCP \App \AppPathNotFoundException $ e ) {
102+ return null ;
103+ }
104+ $ file = $ appPath . '/appinfo/info.xml ' ;
105+ }
106+
107+ $ parser = new \OC \App \InfoParser ();
108+ $ data = $ parser ->parse ($ file );
109+
110+ if (is_array ($ data )) {
111+ $ data = \OC_App::parseAppInfo ($ data , $ lang );
112+ }
113+
114+ return $ data ;
115+ }
116+
94117 public static function getAppIdForClass (string $ className , string $ topNamespace = 'OCA \\' ): ?string {
95118 if (!str_starts_with ($ className , $ topNamespace )) {
96119 return null ;
97120 }
98121
122+ if (str_starts_with ($ className , $ topNamespace )) {
123+ $ classNoTopNamespace = substr ($ className , strlen ($ topNamespace ));
124+ $ appNameParts = explode ('\\' , $ classNoTopNamespace , 2 );
125+ $ appName = reset ($ appNameParts );
126+ return strtolower ($ appName );
127+ }
128+
99129 foreach (self ::$ nameSpaceCache as $ appId => $ namespace ) {
100130 if (str_starts_with ($ className , $ topNamespace . $ namespace . '\\' )) {
101131 return $ appId ;
@@ -105,6 +135,16 @@ public static function getAppIdForClass(string $className, string $topNamespace
105135 return null ;
106136 }
107137
138+ public static function registerAppClass (string $ className ): void {
139+ $ classParts = explode ('\\' , $ className , 2 );
140+ $ topNamespace = reset ($ classParts ) . '\\' ;
141+ $ appId = self ::getAppIdForClass ($ className , $ topNamespace );
142+
143+ if ($ appPath = \OC_App::findAppInDirectories ($ appId , true )) {
144+ $ appPath = $ appPath ['path ' ] . '/ ' . $ appId ;
145+ \OC_App::registerAutoloading ($ appId , $ appPath );
146+ }
147+ }
108148
109149 /**
110150 * Shortcut for calling a controller method and printing the result
0 commit comments