1. Go to this page and download the library: Download morcen/passage 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/ */
morcen / passage example snippets
use Morcen\Passage\Facades\Passage;
Passage::get('github/{path?}', GithubPassageController::class);
Passage::post('stripe/{path?}', StripePassageController::class);
Passage::any('payments/{path?}', PaymentsPassageController::class);
use Morcen\Passage\PassageHandler;
class GithubPassageController extends PassageHandler
{
public function getOptions(): array
{
return [
'base_uri' => 'https://api.github.com/',
];
}
}
public function getRequest(Request $request): Request
{
$request->headers->set('Authorization', 'Bearer '.config('services.github.token'));
return $request;
}
use Morcen\Passage\Contracts\AcceptsClientHeaders;
use Morcen\Passage\PassageHandler;
class RelayHandler extends PassageHandler implements AcceptsClientHeaders
{
public function allowedClientHeaders(): array
{
return ['authorization'];
}
public function getOptions(): array
{
return ['base_uri' => 'https://api.partner.com/'];
}
}
use Morcen\Passage\Exceptions\PassageRequestAbortedException;
public function getRequest(Request $request): Request
{
if (! $this->isAllowed($request)) {
throw new PassageRequestAbortedException('Access denied.', 403);
}
return $request;
}
use Morcen\Passage\Contracts\ValidatesInboundRequest;
use Morcen\Passage\PassageHandler;
class CreateOrderHandler extends PassageHandler implements ValidatesInboundRequest
{
public function rules(): array
{
return [
'product_id' => ['
use Morcen\Passage\PassageHandler;
class GithubHandler extends PassageHandler
{
public function getRequest(Request $request): Request
{
return $this->withBearerToken($request, config('services.github.token'));
}
public function getOptions(): array
{
return ['base_uri' => 'https://api.github.com/'];
}
}
public function getRequest(Request $request): Request
{
// Inject as a header (default: X-API-Key)
return $this->withApiKey($request, config('services.stripe.key'));
// Or inject as a query parameter
return $this->withApiKeyQuery($request, config('services.stripe.key'), 'api_key');
// Or use a custom header name
return $this->withApiKey($request, config('services.stripe.key'), 'X-Stripe-Key');
}
public function getRequest(Request $request): Request
{
return $this->withHmacSignature($request, config('services.partner.secret'));
}
use Morcen\Passage\PassageHandler;
class PaymentsHandler extends PassageHandler
{
public function getOptions(): array
{
return array_merge(
['base_uri' => 'https://payments.example.com/'],
$this->withRetry(3, 200),
);
}
}
$this->withRetry(
times: 3,
sleepMs: 200,
when: function (\Exception $e, \Illuminate\Http\Client\Response $response) {
// Only retry on connection errors, not on 4xx responses
return $e instanceof \Illuminate\Http\Client\ConnectionException;
}
)
public function getOptions(): array
{
return [
'base_uri' => 'https://api.example.com/',
'passage_cache_ttl' => 60,
];
}
'cache' => [
'store' => 'redis',
],
public function getOptions(): array
{
return [
'base_uri' => 'https://files.example.com/',
'passage_streaming' => true,
];
}
use Morcen\Passage\Listeners\PassageEventSubscriber;
protected $subscribe = [
PassageEventSubscriber::class,
];