{/hascontent}
</header>
-{if $licenseData[license][type] === 'developer'}
+{if $licenseData->license[type] === 'developer'}
<p class="warning">{lang}wcf.acp.license.developerLicense{/lang}</p>
{/if}
</thead>
<tbody>
{content}
- {foreach from=$licenseData[woltlab] key=package item=majorVersion}
+ {foreach from=$availablePackages[woltlab] key=package item=majorVersion}
<tr class="licensed_packages__package" data-package="{$package}">
{if $installedPackages[$package]|isset}
<td class="columnText">
</thead>
<tbody>
{content}
- {foreach from=$licenseData[pluginstore] key=package item=majorVersion}
+ {foreach from=$availablePackages[pluginstore] key=package item=majorVersion}
<tr class="licensed_packages__package" data-package="{$package}">
{if $installedPackages[$package]|isset}
<td class="columnText">
if (isset($this->licenseApi)) {
$this->licenseApi->updateLicenseFile();
- if (isset($this->licenseApi->getData()['license']['authCode'])) {
- $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseApi->getData()['license']['authCode'];
+ if (isset($this->licenseApi->getData()->license['authCode'])) {
+ $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseApi->getData()->license['authCode'];
}
}
if (isset($this->licenseApi)) {
$this->licenseApi->updateLicenseFile();
- $authCode = $this->licenseApi->getData()['license']['authCode'] ?? '';
+ $authCode = $this->licenseApi->getData()->license['authCode'] ?? '';
} else {
LicenseApi::removeLicenseFile();
}
use wcf\page\AbstractPage;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\package\license\LicenseApi;
+use wcf\system\package\license\LicenseData;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
public $neededPermissions = ['admin.configuration.package.canInstallPackage'];
- private array $licenseData;
+ private LicenseData $licenseData;
+
+ private array $availablePackages = [];
private int $licenseNumber;
$licenseApi->updateLicenseFile();
$this->licenseData = $licenseApi->getData();
- if (isset($this->licenseData['license']['licenseID'])) {
- $this->licenseNumber = $this->licenseData['license']['licenseID'];
+ if (isset($this->licenseData->license['licenseID'])) {
+ $this->licenseNumber = $this->licenseData->license['licenseID'];
}
$identifiers = \array_merge(
- \array_keys($this->licenseData['woltlab']),
- \array_keys($this->licenseData['pluginstore'])
+ \array_keys($this->licenseData->woltlab),
+ \array_keys($this->licenseData->pluginstore)
);
$this->installedPackages = $this->getInstalledPackages($identifiers);
}
foreach (['woltlab', 'pluginstore'] as $type) {
- $this->licenseData[$type] = \array_filter(
- $this->licenseData[$type],
+ $this->availablePackages[$type] = \array_filter(
+ $this->licenseData->{$type},
function (string $package) {
if (isset($this->installedPackages[$package])) {
return true;
\ARRAY_FILTER_USE_KEY
);
- \uksort($this->licenseData[$type], function ($packageA, $packageB) {
+ \uksort($this->availablePackages[$type], function ($packageA, $packageB) {
$a = $this->installedPackages[$packageA] ?? $this->packageUpdates[$packageA];
$b = $this->installedPackages[$packageB] ?? $this->packageUpdates[$packageB];
});
}
- foreach ($this->licenseData['woltlab'] as $identifier => $accessibleVersion) {
+ foreach ($this->availablePackages['woltlab'] as $identifier => $accessibleVersion) {
if ($accessibleVersion === '*') {
continue;
}
WCF::getTPL()->assign([
'licenseData' => $this->licenseData,
+ 'availablePackages' => $this->availablePackages,
'licenseNumber' => $this->licenseNumber,
'installedPackages' => $this->installedPackages,
'installablePackages' => $this->installablePackages,
$licenseApi = LicenseApi::readFromFile();
if ($licenseApi !== null) {
$licenseData = $licenseApi->getData();
- $brandingFree = $licenseData['woltlab']['com.woltlab.brandingFree'] ?? '0.0';
- $expiresAt = $licenseData['expiryDates']['com.woltlab.brandingFree'] ?? \TIME_NOW;
+ $brandingFree = $licenseData->woltlab['com.woltlab.brandingFree'] ?? '0.0';
+ $expiresAt = $licenseData->license['expiryDates']['com.woltlab.brandingFree'] ?? \TIME_NOW;
if ($brandingFree !== '0.0' && $expiresAt >= \TIME_NOW) {
define('WOLTLAB_BRANDING', false);
}
return '';
}
- return $licenseApi->getData()['license']['ckeditorLicenseKey'] ?? '';
+ return $licenseApi->getData()->license['ckeditorLicenseKey'] ?? '';
}
}
*/
final class LicenseApi
{
- private readonly array $data;
+ private readonly LicenseData $data;
private readonly string $json;
private const LICENSE_FILE = \WCF_DIR . 'license.php';
$this->data = $this->parseLicenseData($this->json);
}
- public function getData(): array
+ public function getData(): LicenseData
{
return $this->data;
}
);
}
- private function parseLicenseData(string $json): array
+ private function parseLicenseData(string $json): LicenseData
{
try {
- /** @var array $result */
- $result = (new MapperBuilder())
+ return (new MapperBuilder())
->allowSuperfluousKeys()
->mapper()
->map(
- <<<'EOT'
- array {
- status: 200,
- license: array {
- authCode?: string,
- licenseID?: int,
- type: string,
- expiryDates?: array<string, int>,
- ckeditorLicenseKey?: string,
- },
- pluginstore: array<string, string>,
- woltlab: array<string, string>,
- }
- EOT,
+ LicenseData::class,
Source::json($json)
);
} catch (MappingError $e) {
throw new ParsingFailed($e);
}
-
- return $result;
}
public static function fetchFromRemote(array $authData = []): LicenseApi
--- /dev/null
+<?php
+
+namespace wcf\system\package\license;
+
+/**
+ * Provides structured access to the license data.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+final class LicenseData
+{
+ /**
+ * @param array{
+ * authCode?: string,
+ * licenseID?: int,
+ * type: string,
+ * expiryDates?: array<string, int>,
+ * ckeditorLicenseKey?: string,
+ * } $license
+ * @param array<string,string> $pluginstore
+ * @param array<string,string> $woltlab
+ */
+ public function __construct(
+ public readonly array $license,
+ public readonly array $pluginstore,
+ public readonly array $woltlab,
+ )
+ {
+ }
+}