PHP code example of kefyusuf / laravel-bloom-gate

1. Go to this page and download the library: Download kefyusuf/laravel-bloom-gate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kefyusuf / laravel-bloom-gate example snippets




namespace App\Bloom;

use Kefyusuf\BloomGate\Contracts\{AuthoritativeSet, FilterDefinition, ValueNormalizer};
use Kefyusuf\BloomGate\Core\{AuthoritativeSetIdentity, ConsistencyContract, NormalizationIdentity, NormalizedValue};

final class CountryCodeFilter implements FilterDefinition
{
    public function normalizer(): ValueNormalizer
    {
        return new class implements ValueNormalizer {
            public function identity(): NormalizationIdentity
            {
                return NormalizationIdentity::fromString('country-code-uppercase@1');
            }

            public function normalize(string|int $value): NormalizedValue
            {
                return NormalizedValue::fromBytes(strtoupper(trim((string) $value)));
            }
        };
    }

    public function authoritativeSet(): AuthoritativeSet
    {
        return new class implements AuthoritativeSet {
            public function identity(): AuthoritativeSetIdentity
            {
                return AuthoritativeSetIdentity::fromString('demo-country-codes@1');
            }

            public function values(): iterable
            {
                yield from ['TR', 'DE', 'US'];
            }

            public function exists(NormalizedValue $value): bool
            {
                return in_array($value->bytes(), ['TR', 'DE', 'US'], true);
            }
        };
    }

    public function consistency(): ConsistencyContract
    {
        return ConsistencyContract::ImmutableV1;
    }
}

'demo.country_codes' => [
    'enabled' => true,
    'definition' => App\Bloom\CountryCodeFilter::class,
    'capacity' => 100,
    'false_positive_rate' => 0.01,
],

use Kefyusuf\BloomGate\Laravel\Facades\BloomGate;

BloomGate::exists('demo.country_codes', 'tr'); // true
BloomGate::exists('demo.country_codes', 'ZZ'); // false

'query' => [
    'descriptor_cache' => [
        'driver' => 'apcu',
        'namespace' => 'my-application-production-primary',
        'ttl' => 60,
    ],
],

interface FilterDefinition
{
    public function normalizer(): ValueNormalizer;

    public function authoritativeSet(): AuthoritativeSet;

    public function consistency(): ConsistencyContract;
}

BloomGate::exists('users.email', $email);
BloomGate::existsResult('users.email', $email);

BloomGate::add('users.email', $email);
BloomGate::addMany('users.email', $emails);

new BloomUnique('users.email');
new BloomExists('users.email');
sh
php artisan bloom:doctor
php artisan bloom:build demo.country_codes
php artisan bloom:verify demo.country_codes
php artisan bloom:activate demo.country_codes
php artisan bloom:status demo.country_codes
text
php artisan bloom:build <filter>
php artisan bloom:verify <filter>
php artisan bloom:activate <filter> [--quiescent]
php artisan bloom:discard <filter>
php artisan bloom:status [filter]
php artisan bloom:doctor