Skip to content

Commit 48c0c7d

Browse files
committed
feat: Add Cms\License::delete() & ::root()
1 parent 1b5a14e commit 48c0c7d

File tree

2 files changed

+82
-130
lines changed

2 files changed

+82
-130
lines changed

src/Cms/License.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class License
3131

3232
protected const SALT = 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX';
3333

34+
protected App $kirby;
35+
3436
// cache
3537
protected LicenseStatus $status;
3638
protected LicenseType $type;
@@ -51,6 +53,8 @@ public function __construct(
5153
if ($email !== null) {
5254
$this->email = $this->normalizeEmail($email);
5355
}
56+
57+
$this->kirby = App::instance();
5458
}
5559

5660
/**
@@ -101,6 +105,15 @@ public function date(
101105
return $this->date !== null ? Str::date(strtotime($this->date), $format, $handler) : null;
102106
}
103107

108+
/**
109+
* Deletes the license file if it exists
110+
* @since 5.0.0
111+
*/
112+
public function delete(): bool
113+
{
114+
return F::remove($this->root());
115+
}
116+
104117
/**
105118
* Returns the activation domain if available
106119
*/
@@ -180,7 +193,7 @@ public function isLegacy(): bool
180193
}
181194

182195
// get release date of current major version
183-
$major = Str::before(App::instance()->version(), '.');
196+
$major = Str::before($this->kirby->version(), '.');
184197
$release = strtotime(static::HISTORY[$major] ?? '');
185198

186199
// if there's no matching version in the history
@@ -220,7 +233,7 @@ public function isOnCorrectDomain(): bool
220233
}
221234

222235
// compare domains
223-
if ($this->normalizeDomain(App::instance()->system()->indexUrl()) !== $this->normalizeDomain($this->domain)) {
236+
if ($this->normalizeDomain($this->kirby->system()->indexUrl()) !== $this->normalizeDomain($this->domain)) {
224237
return false;
225238
}
226239

@@ -237,7 +250,7 @@ public function isSigned(): bool
237250
}
238251

239252
// get the public key
240-
$pubKey = F::read(App::instance()->root('kirby') . '/kirby.pub');
253+
$pubKey = F::read($this->kirby->root('kirby') . '/kirby.pub');
241254

242255
// verify the license signature
243256
$data = json_encode($this->signatureData());
@@ -329,7 +342,7 @@ public static function polyfill(array $license): array
329342
public static function read(): static
330343
{
331344
try {
332-
$license = Json::read(App::instance()->root('license'));
345+
$license = Json::read(static::root());
333346
} catch (Throwable) {
334347
return new static();
335348
}
@@ -410,6 +423,15 @@ public function request(string $path, array $data): array
410423
// @codeCoverageIgnoreEnd
411424
}
412425

426+
/**
427+
* Returns the root path to the license file
428+
* @since 5.0.0
429+
*/
430+
public static function root(): string
431+
{
432+
return App::instance()->root('license');
433+
}
434+
413435
/**
414436
* Saves the license in the config folder
415437
*/
@@ -421,11 +443,11 @@ public function save(): bool
421443
);
422444
}
423445

424-
// where to store the license file
425-
$file = App::instance()->root('license');
426-
427446
// save the license information
428-
return Json::write($file, $this->content());
447+
return Json::write(
448+
file: $this->root(),
449+
data: $this->content()
450+
);
429451
}
430452

431453
/**

0 commit comments

Comments
 (0)