Upgrade to 3.8.1
This commit is contained in:
@@ -17,5 +17,5 @@ namespace Kirby\Uuid;
|
||||
interface Identifiable
|
||||
{
|
||||
public function id();
|
||||
public function uuid(): Uuid;
|
||||
public function uuid(): Uuid|null;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,12 @@ class Uuid
|
||||
Identifiable|null $model = null,
|
||||
Collection|null $context = null
|
||||
) {
|
||||
// throw exception when globally disabled
|
||||
if (Uuids::enabled() === false) {
|
||||
throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.');
|
||||
}
|
||||
|
||||
|
||||
$this->context = $context;
|
||||
$this->model = $model;
|
||||
|
||||
@@ -143,7 +149,13 @@ class Uuid
|
||||
final public static function for(
|
||||
string|Identifiable $seed,
|
||||
Collection|null $context = null
|
||||
): static {
|
||||
): static|null {
|
||||
// if globally disabled, return null
|
||||
if (Uuids::enabled() === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// for UUID string
|
||||
if (is_string($seed) === true) {
|
||||
return match (Str::before($seed, '://')) {
|
||||
'page' => new PageUuid(uuid: $seed, context: $context),
|
||||
@@ -157,6 +169,7 @@ class Uuid
|
||||
};
|
||||
}
|
||||
|
||||
// for model object
|
||||
return match (true) {
|
||||
$seed instanceof Page
|
||||
=> new PageUuid(model: $seed, context: $context),
|
||||
@@ -229,6 +242,11 @@ class Uuid
|
||||
string $string,
|
||||
string|null $type = null
|
||||
): bool {
|
||||
// always return false when UUIDs have been disabled
|
||||
if (Uuids::enabled() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type ??= implode('|', Uri::$schemes);
|
||||
$pattern = sprintf('!^(%s)://(.*)!', $type);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Kirby\Uuid;
|
||||
use Closure;
|
||||
use Kirby\Cache\Cache;
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* Helper methods that deal with the entirety of UUIDs in the system
|
||||
@@ -79,6 +80,11 @@ class Uuids
|
||||
// }
|
||||
}
|
||||
|
||||
public static function enabled(): bool
|
||||
{
|
||||
return App::instance()->option('content.uuid') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates UUID for all identifiable models of type
|
||||
*
|
||||
@@ -86,6 +92,10 @@ class Uuids
|
||||
*/
|
||||
public static function generate(string $type = 'all'): void
|
||||
{
|
||||
if (static::enabled() === false) {
|
||||
throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.');
|
||||
}
|
||||
|
||||
static::each(
|
||||
fn (Identifiable $model) => Uuid::for($model)->id(),
|
||||
$type
|
||||
@@ -100,6 +110,10 @@ class Uuids
|
||||
*/
|
||||
public static function populate(string $type = 'all'): void
|
||||
{
|
||||
if (static::enabled() === false) {
|
||||
throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.');
|
||||
}
|
||||
|
||||
static::each(
|
||||
fn (Identifiable $model) => Uuid::for($model)->populate(),
|
||||
$type
|
||||
|
||||
Reference in New Issue
Block a user