1. Go to this page and download the library: Download andrebhas/laravel-brick 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/ */
andrebhas / laravel-brick example snippets
namespace Bricks\Hotel\Bridge;
use AndreBhas\Brick\Brick\Bridge\Contracts\Bridgeable;
class HotelBridge implements Bridgeable
{
public static function getBridgeName(): string
{
return 'Hotel';
}
public static function getExposedMethods(): array
{
return ['getById', 'checkAvailability'];
}
public function getById(int $id): array
{
// Fetch hotel data...
return ['id' => $id, 'name' => 'Grand Hotel'];
}
public function checkAvailability(int $hotelId, string $date): bool
{
return true;
}
}
use AndreBhas\Brick\Brick\Bridge\InternalGateway;
$gateway = app(InternalGateway::class);
// Goes through middleware pipeline (logging, circuit breaker, etc.)
$hotel = $gateway->call('Hotel', 'getById', 42);
// Dispatch to queue, get a job ID
$jobId = $gateway->callAsync('Hotel', 'getById', 42);
// Later, poll for the result
$result = $gateway->getAsyncResult($jobId);
// ['status' => 'success', 'result' => [...], 'completed_at' => '...']
// or
// ['status' => 'pending', 'queued_at' => '...']
// or
// ['status' => 'failed', 'error' => '...']
use AndreBhas\Brick\Brick\Testing\BridgeFake;
use AndreBhas\Brick\Brick\Bridge\InternalGateway;
$fake = new BridgeFake(
container: app(),
cache: app('cache')->store(),
queue: app('queue'),
);
// Register a fake response
$fake->shouldReceive('Hotel', 'getById', fn ($id) => ['id' => $id, 'name' => 'Test Hotel']);
// Swap in the container
app()->instance(InternalGateway::class, $fake);
// ... run your code ...
// Assert calls
$fake->assertCalled('Hotel', 'getById', 1);
$fake->assertNotCalled('Hotel', 'delete');
$fake->assertNothingCalled(); // if no calls expected
use AndreBhas\Brick\Brick\Testing\CircuitBreakerFake;
use AndreBhas\Brick\Brick\Bridge\CircuitBreaker;
$fake = new CircuitBreakerFake();
$fake->forceOpen('Hotel'); // simulate open circuit
$fake->forceHalfOpen('Payment');
$fake->forceClose('Auth');
app()->instance(CircuitBreaker::class, $fake);
bash
php artisan brick:enable Booking
# Error: Cannot enable [Booking]. Missing dependencies: Hotel (inactive).
# Use --force to override.
php artisan brick:enable Hotel
php artisan brick:enable Booking # Now works
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.