PHP code example of azaharizaman / nexus-connector
1. Go to this page and download the library: Download azaharizaman/nexus-connector 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/ */
azaharizaman / nexus-connector example snippets
use Nexus\Connector\Contracts\EmailServiceConnectorInterface;
class NotificationService
{
public function __construct(
private readonly EmailServiceConnectorInterface $emailConnector
) {}
public function sendWelcomeEmail(string $recipient): void
{
$this->emailConnector->sendTransactionalEmail(
recipient: $recipient,
subject: 'Welcome to Nexus',
body: 'Thank you for joining us!'
);
}
}
use Nexus\Connector\Services\ConnectorManager;
use Nexus\Connector\ValueObjects\{Endpoint, HttpMethod, RateLimitConfig, IdempotencyKey};
class PaymentService
{
public function __construct(
private readonly ConnectorManager $connector
) {}
public function processPayment(float $amount, string $currency, array $paymentData): array
{
// Create endpoint with rate limiting and custom timeout
$endpoint = Endpoint::create('https://api.stripe.com/v1/charges', HttpMethod::POST)
->withRateLimit(RateLimitConfig::perSecond(100))
->withTimeout(45);
// Generate idempotency key to prevent duplicate charges
$idempotencyKey = IdempotencyKey::generate('payment');
// Execute with automatic retry, circuit breaker, and OAuth refresh
return $this->connector->execute(
serviceName: 'stripe',
endpoint: $endpoint,
payload: [
'amount' => (int)($amount * 100),
'currency' => $currency,
'source' => $paymentData['token'],
],
idempotencyKey: $idempotencyKey
);
}
}