Skip to content

Commit e193e90

Browse files
fix: usage without Composer
1 parent bc679ae commit e193e90

File tree

10 files changed

+180
-49
lines changed

10 files changed

+180
-49
lines changed

composer.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
return array(
99
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10+
'JohannSchopplich\\Licensing\\Http\\HttpClientInterface' => $vendorDir . '/johannschopplich/kirby-tools-licensing/src/Http/HttpClientInterface.php',
11+
'JohannSchopplich\\Licensing\\Http\\KirbyHttpClient' => $vendorDir . '/johannschopplich/kirby-tools-licensing/src/Http/KirbyHttpClient.php',
1012
'JohannSchopplich\\Licensing\\Licenses' => $vendorDir . '/johannschopplich/kirby-tools-licensing/src/Licenses.php',
1113
'JohannSchopplich\\Licensing\\PluginLicense' => $vendorDir . '/johannschopplich/kirby-tools-licensing/src/PluginLicense.php',
1214
'Kirby\\ComposerInstaller\\CmsInstaller' => $vendorDir . '/getkirby/composer-installer/src/ComposerInstaller/CmsInstaller.php',

vendor/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ComposerStaticInit3e118550e09fa4bd12cae71292360377
3030

3131
public static $classMap = array (
3232
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
33+
'JohannSchopplich\\Licensing\\Http\\HttpClientInterface' => __DIR__ . '/..' . '/johannschopplich/kirby-tools-licensing/src/Http/HttpClientInterface.php',
34+
'JohannSchopplich\\Licensing\\Http\\KirbyHttpClient' => __DIR__ . '/..' . '/johannschopplich/kirby-tools-licensing/src/Http/KirbyHttpClient.php',
3335
'JohannSchopplich\\Licensing\\Licenses' => __DIR__ . '/..' . '/johannschopplich/kirby-tools-licensing/src/Licenses.php',
3436
'JohannSchopplich\\Licensing\\PluginLicense' => __DIR__ . '/..' . '/johannschopplich/kirby-tools-licensing/src/PluginLicense.php',
3537
'Kirby\\ComposerInstaller\\CmsInstaller' => __DIR__ . '/..' . '/getkirby/composer-installer/src/ComposerInstaller/CmsInstaller.php',

vendor/composer/installed.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@
5252
},
5353
{
5454
"name": "johannschopplich/kirby-tools-licensing",
55-
"version": "0.7.2",
56-
"version_normalized": "0.7.2.0",
55+
"version": "0.7.4",
56+
"version_normalized": "0.7.4.0",
5757
"source": {
5858
"type": "git",
5959
"url": "https://github.com/kirby-tools/licensing-backend.git",
60-
"reference": "186b5a066d16bd78075b3f4a413567835de3f940"
60+
"reference": "eb9f866b5ad9df01f20ded1e752b4046ca938666"
6161
},
6262
"dist": {
6363
"type": "zip",
64-
"url": "https://api.github.com/repos/kirby-tools/licensing-backend/zipball/186b5a066d16bd78075b3f4a413567835de3f940",
65-
"reference": "186b5a066d16bd78075b3f4a413567835de3f940",
64+
"url": "https://api.github.com/repos/kirby-tools/licensing-backend/zipball/eb9f866b5ad9df01f20ded1e752b4046ca938666",
65+
"reference": "eb9f866b5ad9df01f20ded1e752b4046ca938666",
6666
"shasum": ""
6767
},
6868
"require-dev": {
69-
"getkirby/cms": "^5"
69+
"getkirby/cms": "^5",
70+
"phpunit/phpunit": "^12"
7071
},
71-
"time": "2025-06-24T15:04:04+00:00",
72+
"time": "2025-07-11T12:37:14+00:00",
7273
"type": "library",
7374
"extra": {
7475
"kirby-cms-path": false
@@ -94,7 +95,7 @@
9495
"homepage": "https://github.com/kirby-tools/licensing-backend#readme",
9596
"support": {
9697
"issues": "https://github.com/kirby-tools/licensing-backend/issues",
97-
"source": "https://github.com/kirby-tools/licensing-backend/tree/v0.7.2"
98+
"source": "https://github.com/kirby-tools/licensing-backend/tree/v0.7.4"
9899
},
99100
"install-path": "../johannschopplich/kirby-tools-licensing"
100101
}

vendor/composer/installed.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
'dev_requirement' => false,
3030
),
3131
'johannschopplich/kirby-tools-licensing' => array(
32-
'pretty_version' => '0.7.2',
33-
'version' => '0.7.2.0',
34-
'reference' => '186b5a066d16bd78075b3f4a413567835de3f940',
32+
'pretty_version' => '0.7.4',
33+
'version' => '0.7.4.0',
34+
'reference' => 'eb9f866b5ad9df01f20ded1e752b4046ca938666',
3535
'type' => 'library',
3636
'install_path' => __DIR__ . '/../johannschopplich/kirby-tools-licensing',
3737
'aliases' => array(),

vendor/johannschopplich/kirby-tools-licensing/composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "johannschopplich/kirby-tools-licensing",
33
"description": "License system backend for Kirby Tools plugins",
44
"type": "library",
5-
"version": "0.7.2",
5+
"version": "0.7.4",
66
"license": "AGPL-3.0-or-later",
77
"homepage": "https://github.com/kirby-tools/licensing-backend#readme",
88
"authors": [
@@ -13,10 +13,12 @@
1313
}
1414
],
1515
"require-dev": {
16-
"getkirby/cms": "^5"
16+
"getkirby/cms": "^5",
17+
"phpunit/phpunit": "^12"
1718
},
1819
"scripts": {
19-
"csfix": "@php tools/phpcs/vendor/bin/php-cs-fixer fix"
20+
"csfix": "@php tools/phpcs/vendor/bin/php-cs-fixer fix",
21+
"test": "phpunit"
2022
},
2123
"autoload": {
2224
"psr-4": {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace JohannSchopplich\Licensing\Http;
6+
7+
interface HttpClientInterface
8+
{
9+
/**
10+
* @throws \Exception when the curl request failed
11+
*/
12+
public function request(string $url, array $options = []): array;
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace JohannSchopplich\Licensing\Http;
6+
7+
use Kirby\Cms\App;
8+
use Kirby\Exception\LogicException;
9+
use Kirby\Http\Remote;
10+
use Kirby\Toolkit\A;
11+
12+
/**
13+
* HTTP client implementation using Kirby's `Remote` class.
14+
*/
15+
class KirbyHttpClient implements HttpClientInterface
16+
{
17+
public function request(string $url, array $options = []): array
18+
{
19+
$response = new Remote($url, A::merge([
20+
'headers' => [
21+
'X-App-Url' => App::instance()->url()
22+
]
23+
], $options));
24+
25+
if ($response->code() < 200 || $response->code() >= 300) {
26+
$message = $response->json()['message'] ?? 'Request failed';
27+
throw new LogicException($message, (string)$response->code());
28+
}
29+
30+
return $response->json();
31+
}
32+
}

vendor/johannschopplich/kirby-tools-licensing/src/Licenses.php

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace JohannSchopplich\Licensing;
66

77
use Composer\Semver\Semver;
8+
use JohannSchopplich\Licensing\Http\HttpClientInterface;
9+
use JohannSchopplich\Licensing\Http\KirbyHttpClient;
810
use Kirby\Cms\App;
911
use Kirby\Data\Json;
1012
use Kirby\Exception\LogicException;
1113
use Kirby\Filesystem\F;
12-
use Kirby\Http\Remote;
13-
use Kirby\Toolkit\A;
14+
use Kirby\Http\Request;
1415
use Throwable;
1516

1617
/**
@@ -30,16 +31,19 @@
3031
*/
3132
class Licenses
3233
{
33-
private const LICENSE_FILE = '.kirby-tools-licenses';
34-
private const LICENSE_PATTERN = '!^KT(\d+)-\w+-\w+$!';
35-
private const API_URL = 'https://repo.kirby.tools/api';
36-
private string $licenseFile;
34+
protected const LICENSE_PATTERN = '!^KT(\d+)-\w+-\w+$!';
35+
protected const API_URL = 'https://repo.kirby.tools/api';
36+
protected string $licenseFile;
37+
38+
public const LICENSE_FILE = '.kirby-tools-licenses';
3739

3840
public function __construct(
39-
private array $licenses,
40-
private string $packageName,
41+
protected array $licenses,
42+
protected string $packageName,
43+
protected HttpClientInterface|null $httpClient = null
4144
) {
4245
$this->licenseFile = dirname(App::instance()->root('license')) . '/' . static::LICENSE_FILE;
46+
$this->httpClient = $httpClient ?? new KirbyHttpClient();
4347
}
4448

4549
public static function read(string $packageName, array $options = []): static
@@ -50,7 +54,11 @@ public static function read(string $packageName, array $options = []): static
5054
$licenses = [];
5155
}
5256

53-
$instance = new static($licenses, $packageName);
57+
$instance = new static(
58+
licenses: $licenses,
59+
packageName: $packageName,
60+
httpClient: $options['httpClient'] ?? null
61+
);
5462
$instance->migration();
5563
$instance->refresh();
5664

@@ -118,8 +126,10 @@ public function getLicenseCompatibility(): string|null
118126

119127
public function getPluginVersion(): string|null
120128
{
121-
$kirbyPackageName = str_replace('/kirby-', '/', $this->packageName);
122-
return App::instance()->plugin($kirbyPackageName)?->version();
129+
// Map package name to Kirby plugin name by removing the vendor prefix
130+
$kirbyPluginName = str_replace('/kirby-', '/', $this->packageName);
131+
132+
return App::instance()->plugin($kirbyPluginName)?->version();
123133
}
124134

125135
public function isActivated(): bool
@@ -208,9 +218,9 @@ public function activate(string $email, string|int $orderId): void
208218
$this->update($this->packageName, $response);
209219
}
210220

211-
public function activateFromRequest(): array
221+
public function activateFromRequest(Request|null $request = null): array
212222
{
213-
$request = App::instance()->request();
223+
$request = $request ?? App::instance()->request();
214224
$email = $request->get('email');
215225
$orderId = $request->get('orderId');
216226

@@ -239,7 +249,7 @@ public function update(string $packageName, array $data): void
239249
Json::write($this->licenseFile, $this->licenses);
240250
}
241251

242-
private function migration(): void
252+
protected function migration(): void
243253
{
244254
// Migration 1: Move license file to license directory
245255
$oldLicenseFile = App::instance()->root('config') . '/' . static::LICENSE_FILE;
@@ -255,7 +265,7 @@ private function migration(): void
255265
}
256266
}
257267

258-
private function refresh(): void
268+
protected function refresh(): void
259269
{
260270
$currentVersion = $this->licenses[$this->packageName]['pluginVersion'] ?? null;
261271

@@ -269,19 +279,8 @@ private function refresh(): void
269279
}
270280
}
271281

272-
private function request(string $path, array $options = []): array
282+
protected function request(string $path, array $options = []): array
273283
{
274-
$response = new Remote(static::API_URL . '/' . $path, A::merge([
275-
'headers' => [
276-
'X-App-Url' => App::instance()->url()
277-
]
278-
], $options));
279-
280-
if ($response->code() < 200 || $response->code() >= 300) {
281-
$message = $response->json()['message'] ?? 'Request failed';
282-
throw new LogicException($message, (string)$response->code());
283-
}
284-
285-
return $response->json();
284+
return $this->httpClient->request(static::API_URL . '/' . $path, $options);
286285
}
287286
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace JohannSchopplich\Licensing;
6+
7+
use Kirby\Plugin\License as KirbyLicense;
8+
use Kirby\Plugin\LicenseStatus as KirbyLicenseStatus;
9+
use Kirby\Plugin\Plugin;
10+
11+
/**
12+
* Integrates the custom license system for Kirby Tools plugins with Kirby's plugin license system.
13+
*
14+
* @link https://kirby.tools
15+
* @copyright Johann Schopplich
16+
* @license AGPL-3.0
17+
*/
18+
class PluginLicense extends KirbyLicense
19+
{
20+
public const LICENSE_NAME = 'Kirby Tools License';
21+
public const LICENSE_URL = 'https://kirby.tools/license';
22+
23+
public function __construct(
24+
Plugin $plugin,
25+
protected string $packageName
26+
) {
27+
$licenses = Licenses::read($packageName);
28+
$status = $this->mapToKirbyStatus($licenses->getStatus());
29+
30+
parent::__construct(
31+
plugin: $plugin,
32+
name: static::LICENSE_NAME,
33+
link: static::LICENSE_URL,
34+
status: $status
35+
);
36+
}
37+
38+
protected function mapToKirbyStatus(string $customStatus): KirbyLicenseStatus
39+
{
40+
return match ($customStatus) {
41+
'active' => new KirbyLicenseStatus(
42+
value: 'active',
43+
label: 'Licensed',
44+
icon: 'check',
45+
theme: 'positive'
46+
),
47+
'inactive' => new KirbyLicenseStatus(
48+
value: 'missing',
49+
label: 'Please buy a license',
50+
icon: 'key',
51+
theme: 'love'
52+
),
53+
'invalid' => new KirbyLicenseStatus(
54+
value: 'invalid',
55+
label: 'Invalid license',
56+
icon: 'alert',
57+
theme: 'negative'
58+
),
59+
'incompatible' => new KirbyLicenseStatus(
60+
value: 'incompatible',
61+
label: 'Incompatible license',
62+
icon: 'alert',
63+
theme: 'negative'
64+
),
65+
'upgradeable' => new KirbyLicenseStatus(
66+
value: 'upgradeable',
67+
label: 'License upgrade available',
68+
icon: 'refresh',
69+
theme: 'notice'
70+
),
71+
default => new KirbyLicenseStatus(
72+
value: 'unknown',
73+
label: 'Unknown license status',
74+
icon: 'question',
75+
theme: 'passive'
76+
)
77+
};
78+
}
79+
}

0 commit comments

Comments
 (0)