Skip to content

Commit

Permalink
changed MessengerBots::$useUuids to private and implemented getter/se…
Browse files Browse the repository at this point in the history
…tter combo method.
  • Loading branch information
RTippin committed Jul 6, 2021
1 parent cc28e63 commit 34182be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
21 changes: 18 additions & 3 deletions src/MessengerBots.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ final class MessengerBots
];

/**
* This determines if we use UUID or BigInt on the bot model.
*
* @var bool
*/
public static bool $useUuid = false;
private static bool $useUuid = false;

/**
* @var Collection
Expand Down Expand Up @@ -68,6 +66,23 @@ public function __construct()
$this->handlerOverrides = [];
}

/**
* This determines if we use UUID or BigInt on the bot model and migrations.
*
* @param bool|null $shouldUseUuids
* @return bool
*/
public static function shouldUseUuids(?bool $shouldUseUuids = null): bool
{
if (is_null($shouldUseUuids)) {
return self::$useUuid;
}

self::$useUuid = $shouldUseUuids;

return self::$useUuid;
}

/**
* Get all bot handler classes.
*
Expand Down
2 changes: 1 addition & 1 deletion src/MessengerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function boot(): void
'bots' => Bot::class,
]);

MessengerBots::$useUuid = config('messenger.provider_uuids');
MessengerBots::shouldUseUuids(config('messenger.provider_uuids'));

Collection::macro('forProvider', function (MessengerProvider $provider, string $morph = 'owner'): Collection {
/** @var Collection $this */
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class Bot extends Model implements MessengerProvider
*/
public function __construct(array $attributes = [])
{
$this->setKeyType(Bots::$useUuid ? 'string' : 'int');
$this->setKeyType(Bots::shouldUseUuids() ? 'string' : 'int');

$this->setIncrementing(! Bots::$useUuid);
$this->setIncrementing(! Bots::shouldUseUuids());

parent::__construct($attributes);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public static function boot()
parent::boot();

static::creating(function (Model $model) {
if (Bots::$useUuid) {
if (Bots::shouldUseUuids()) {
$model->id = Str::orderedUuid()->toString();
}
});
Expand Down

0 comments on commit 34182be

Please sign in to comment.