PHP code example of evolvex / laravel-shadow-runtime

1. Go to this page and download the library: Download evolvex/laravel-shadow-runtime 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/ */

    

evolvex / laravel-shadow-runtime example snippets


use Evolvex\ShadowRuntime\Facades\Shadow;

$provider = Shadow::compare('sms-provider-selection-v2')
    ->version('2.3.0')
    ->subject($player->id)
    ->sample(10)
    ->tags([
        'site_id' => $site->id,
        'country' => $player->country,
    ])
    ->primary(fn () => $oldResolver->resolve($context))
    ->candidate(fn () => $newResolver->resolve($context))
    ->sandbox(function ($sandbox) {
        $sandbox
            ->allowDatabaseReads()
            ->captureDatabaseWrites()
            ->captureHttp()
            ->captureJobs()
            ->captureEvents()
            ->captureMail()
            ->captureNotifications();
    })
    ->budget(timeoutMs: 50, memoryMb: 32, maxQueries: 20, maxEffects: 25)
    ->run();

use Evolvex\ShadowRuntime\Contracts\ShadowOperation;

final class WithdrawalEligibilityV3 implements ShadowOperation
{
    public function primary(mixed $input): mixed
    {
        return app(LegacyWithdrawalEligibility::class)->decide($input);
    }

    public function candidate(mixed $input): mixed
    {
        return app(NewWithdrawalEligibility::class)->decide($input);
    }
}

$decision = Shadow::operation(WithdrawalEligibilityV3::class)
    ->input($snapshot)
    ->subject($snapshot->playerId)
    ->sample(25)
    ->run();

->compareUsing(Evolvex\ShadowRuntime\Comparison\StrictComparator::class)
->compareUsing(Evolvex\ShadowRuntime\Comparison\JsonComparator::class)
->compareUsing(new Evolvex\ShadowRuntime\Comparison\NumericToleranceComparator(0.001))

->normalizeUsing(fn ($decision) => [
    'allowed' => $decision->allowed,
    'reason' => $decision->reason,
])

->subject($player->id)
->sample(5)
bash
composer shadow:install
php artisan migrate
bash
php artisan shadow:doctor
bash
php artisan shadow:list
php artisan shadow:status sms-provider-selection-v2
php artisan shadow:report sms-provider-selection-v2
php artisan shadow:diffs sms-provider-selection-v2
php artisan shadow:pause sms-provider-selection-v2
php artisan shadow:resume sms-provider-selection-v2
php artisan shadow:purge
php artisan shadow:doctor
php artisan shadow:gate sms-provider-selection-v2 \
  --agreement=99.9 \
  --max-candidate-error-rate=0.1 \
  --max-avg-latency-regression=10