Merge pull request #1239 from nextcloud/cache_info_parsing
Cache parsing of info.xml
This commit is contained in:
commit
93624c3028
|
@ -42,6 +42,8 @@ use OCP\AppFramework\Http\ICallbackResponse;
|
||||||
*/
|
*/
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
private static $nameSpaceCache = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns an app id into a namespace by either reading the appinfo.xml's
|
* Turns an app id into a namespace by either reading the appinfo.xml's
|
||||||
|
@ -52,6 +54,11 @@ class App {
|
||||||
* @return string the starting namespace for the app
|
* @return string the starting namespace for the app
|
||||||
*/
|
*/
|
||||||
public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
|
public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
|
||||||
|
// Hit the cache!
|
||||||
|
if (isset(self::$nameSpaceCache[$appId])) {
|
||||||
|
return $topNamespace . self::$nameSpaceCache[$appId];
|
||||||
|
}
|
||||||
|
|
||||||
// first try to parse the app's appinfo/info.xml <namespace> tag
|
// first try to parse the app's appinfo/info.xml <namespace> tag
|
||||||
$appPath = OC_App::getAppPath($appId);
|
$appPath = OC_App::getAppPath($appId);
|
||||||
if ($appPath !== false) {
|
if ($appPath !== false) {
|
||||||
|
@ -63,14 +70,16 @@ class App {
|
||||||
if ($xml) {
|
if ($xml) {
|
||||||
$result = $xml->xpath('/info/namespace');
|
$result = $xml->xpath('/info/namespace');
|
||||||
if ($result && count($result) > 0) {
|
if ($result && count($result) > 0) {
|
||||||
|
self::$nameSpaceCache[$appId] = trim((string) $result[0]);
|
||||||
// take first namespace result
|
// take first namespace result
|
||||||
return $topNamespace . trim((string) $result[0]);
|
return $topNamespace . self::$nameSpaceCache[$appId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the tag is not found, fall back to uppercasing the first letter
|
// if the tag is not found, fall back to uppercasing the first letter
|
||||||
return $topNamespace . ucfirst($appId);
|
self::$nameSpaceCache[$appId] = ucfirst($appId);
|
||||||
|
return $topNamespace . self::$nameSpaceCache[$appId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue