From: Tim Düsterhus Date: Wed, 27 Sep 2023 13:09:06 +0000 (+0200) Subject: Store the license data in serialized form X-Git-Tag: 6.0.0_RC_2~3^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8796b7de71e5fd5e904617de1d61a772767dff33;p=GitHub%2FWoltLab%2FWCF.git Store the license data in serialized form This avoids expensive remapping on every request. --- diff --git a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php index bd669d3cd1..82c9d77b64 100644 --- a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php +++ b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php @@ -22,14 +22,12 @@ use wcf\system\package\license\exception\ParsingFailed; final class LicenseApi { private readonly LicenseData $data; - private readonly string $json; private const LICENSE_FILE = \WCF_DIR . 'license.php'; - private function __construct(string $json) + private function __construct(LicenseData $data) { - $this->json = $json; - $this->data = $this->parseLicenseData($this->json); + $this->data = $data; } public function getData(): LicenseData @@ -45,17 +43,15 @@ final class LicenseApi <<<'EOT' json, + \var_export(\serialize($this->data), true), ) ); } - private function parseLicenseData(string $json): LicenseData + private static function parseLicenseData(string $json): LicenseData { try { return (new MapperBuilder()) @@ -95,7 +91,7 @@ final class LicenseApi $response = HttpFactory::makeClientWithTimeout(5)->send($request); - return new LicenseApi($response->getBody()); + return new LicenseApi(self::parseLicenseData($response->getBody())); } public static function readFromFile(): ?LicenseApi @@ -104,13 +100,7 @@ final class LicenseApi return null; } - $content = require(self::LICENSE_FILE); - - try { - return new LicenseApi($content); - } catch (ParsingFailed) { - return null; - } + return new LicenseApi(require(self::LICENSE_FILE)); } public static function removeLicenseFile(): void