diff --git a/composer.json b/composer.json index 0ef26b5..268964a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^8.2", "laravel/framework": "^10.44.0 || ^11.0", - "flagsmith/flagsmith-php-client": "^4.2.0" + "flagsmith/flagsmith-php-client": "^4.3.1" }, "extra": { "laravel": { @@ -32,10 +32,10 @@ "require-dev": { "guzzlehttp/psr7": "^2.6.2", "guzzlehttp/guzzle": "^7.8.1", - "orchestra/testbench": "^8.22.0", - "phpunit/phpunit": "^10.5.13", - "vimeo/psalm": "^5.23.1", - "squizlabs/php_codesniffer": "^3.9.0" + "orchestra/testbench": "^8.23.0", + "phpunit/phpunit": "^10.5.25", + "vimeo/psalm": "^5.25.0", + "squizlabs/php_codesniffer": "^3.10.1" }, "config": { "allow-plugins": { diff --git a/src/Concerns/HasFlags.php b/src/Concerns/HasFlags.php index dfadad6..166c70a 100644 --- a/src/Concerns/HasFlags.php +++ b/src/Concerns/HasFlags.php @@ -2,11 +2,13 @@ namespace Clearlyip\LaravelFlagsmith\Concerns; +use BackedEnum; use Flagsmith\Flagsmith; use Flagsmith\Models\Identity; use Flagsmith\Models\IdentityTrait; use Flagsmith\Utils\Collections\FlagModelsList; use Illuminate\Support\Facades\App; +use UnitEnum; trait HasFlags { @@ -112,7 +114,13 @@ public function getFlagTraits(): array return array_reduce( config('flagsmith.identity.traits', []), function ($carry, $attribute) { - $carry[$attribute] = $this->getRawOriginal($attribute); + $value = $this->{$attribute}; + if ($value instanceof BackedEnum) { + $value = $value->value; + } elseif ($value instanceof UnitEnum) { + $value = $value->name; + } + $carry[$attribute] = $value; return $carry; }, [], diff --git a/src/Listeners/UserLogin.php b/src/Listeners/UserLogin.php index 94f6975..f155487 100644 --- a/src/Listeners/UserLogin.php +++ b/src/Listeners/UserLogin.php @@ -4,6 +4,7 @@ use Clearlyip\LaravelFlagsmith\Contracts\UserFlags; use Clearlyip\LaravelFlagsmith\Jobs\SyncUser; +use Flagsmith\Utils\IdentitiesGenerator; use Illuminate\Auth\Events\Login; class UserLogin @@ -42,8 +43,13 @@ public function handle(Login $event) return; } + $key = IdentitiesGenerator::generateIdentitiesCacheKey( + $user->getFlagIdentityId(), + (object) $user->getFlagTraits(), + ); + //Doesn't exist so get it now - if (!$cache->has('Identity.' . $user->getFlagIdentityId())) { + if (!$cache->has($key)) { SyncUser::dispatchSync($user); } else { SyncUser::dispatch($user)->onQueue($queue);