PHP code example of saloonphp / barstool

1. Go to this page and download the library: Download saloonphp/barstool 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/ */

    

saloonphp / barstool example snippets


// config/barstool.php
'only' => [
    'connectors' => [
        StripeConnector::class, // record everything sent through this connector...
    ],
    'requests' => [],
],

'ignore' => [
    'connectors' => [],
    'requests' => [
        StripeHealthCheckRequest::class, // ...except this noisy request
    ],
],

'keep_successful_responses' => false,

'excluded_request_headers' => [
    'Authorization',
    'X-Api-Key',            // redact this header on every request
    SensitiveRequest::class, // redact ALL headers for this request
    SensitiveConnector::class, // redact ALL headers for this connector
    // '*',                 // redact ALL headers on every request
],

'excluded_response_headers' => [
    'Set-Cookie',
    // '*',                    // redact every response header
    // SensitiveConnector::class, // redact all response headers for a connector
    // SensitiveRequest::class,   // or a single request
],

'excluded_response_body' => [
    SensitiveConnector::class, // exclude bodies for a whole connector
    SensitiveRequest::class,   // or a single request
    // '*',                    // or every response
],

'max_response_size' => 100,

'keep_for_days' => 30,

use Saloon\Barstool\Models\Barstool;

Schedule::command('model:prune', [
    '--model' => [Barstool::class],
])->daily();

'queue' => [
    'enabled' => env('BARSTOOL_QUEUE_ENABLED', false),
    'connection' => env('BARSTOOL_QUEUE_CONNECTION'),  // null uses default connection
    'queue' => env('BARSTOOL_QUEUE_NAME'),             // null uses default queue
],

use Saloon\Barstool\Barstool;

Barstool::context([
    'user_id' => auth()->id(),
    'tenant_id' => $tenant->id,
]);

// Or add a single key:
Barstool::addContext('job', 'user-sync');

$response = $connector->send($request);

$barstoolUuid = $response->getPendingRequest()->headers()->get('X-Barstool-UUID');

if ($response->failed()) {
    UserSyncLog::create([
        'user_id' => auth()->id(),
        'barstool_uuid' => $barstoolUuid,
    ]);
}
bash
php artisan vendor:publish --tag="barstool-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="barstool-config"
bash
> php artisan vendor:publish --tag="barstool-migrations"
> php artisan migrate
>