From 19a0a9a4e7e9e511f5f3d99c697e57e7bb0260e6 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Mon, 29 Jan 2018 13:09:32 +0100 Subject: Move getAppInfo and getAppVersion to IAppManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/App/AppManager.php | 50 +++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'lib/private/App') diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index f2b396b29d0..0e921ba1b7f 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -80,6 +80,12 @@ class AppManager implements IAppManager { /** @var string[] */ private $alwaysEnabled; + /** @var array */ + private $appInfos = []; + + /** @var array */ + private $appVersions = []; + /** * @param IUserSession $userSession * @param AppConfig $appConfig @@ -341,17 +347,45 @@ class AppManager implements IAppManager { * * @param string $appId app id * + * @param bool $path + * @param null $lang * @return array app info - * - * @internal */ - public function getAppInfo($appId) { - $appInfo = \OC_App::getAppInfo($appId); - if (!isset($appInfo['version'])) { - // read version from separate file - $appInfo['version'] = \OC_App::getAppVersion($appId); + public function getAppInfo(string $appId, bool $path = false, $lang = null) { + if ($path) { + $file = $appId; + } else { + if ($lang === null && isset($this->appInfos[$appId])) { + return $this->appInfos[$appId]; + } + try { + $appPath = $this->getAppPath($appId); + } catch (AppPathNotFoundException $e) { + return null; + } + $file = $appPath . '/appinfo/info.xml'; + } + + $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); + $data = $parser->parse($file); + + if (is_array($data)) { + $data = \OC_App::parseAppInfo($data, $lang); + } + + if ($lang === null) { + $this->appInfos[$appId] = $data; + } + + return $data; + } + + public function getAppVersion(string $appId, bool $useCache = true) { + if(!$useCache || !isset($this->appVersions[$appId])) { + $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); + $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; } - return $appInfo; + return $this->appVersions[$appId]; } /** -- cgit v1.2.3