Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Nexmo Bridge Laravel Package

vonage/nexmo-bridge

Composer autoloader bridge that aliases legacy Nexmo (\Nexmo) classes, traits, and interfaces to their Vonage namespace equivalents. Use it to migrate existing code to vonage/client or vonage/client-core without refactoring everything at once.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require vonage/nexmo-bridge
    

    Add to composer.json if using legacy Nexmo namespace:

    "extra": {
        "nexmo-bridge": {
            "apiKey": "YOUR_API_KEY",
            "apiSecret": "YOUR_API_SECRET"
        }
    }
    
  2. First Use Case: Legacy Code Migration Replace Nexmo\Client with Vonage\Client in existing code:

    // Before (Nexmo)
    $client = new Nexmo\Client\Credentials\Basic('key', 'secret');
    
    // After (Vonage + Bridge)
    $client = new Vonage\Client\Credentials\Basic(config('nexmo-bridge.apiKey'), config('nexmo-bridge.apiSecret'));
    
  3. Key Files to Review

    • vendor/vonage/nexmo-bridge/src/Vonage/Nexmo/Client.php (Core bridge class)
    • config/nexmo-bridge.php (Default config, if published)

Implementation Patterns

1. Namespace Aliasing

Use use statements to alias Vonage classes under Nexmo for seamless migration:

use Vonage\Client as NexmoClient;
use Vonage\Sms\Message as NexmoMessage;

2. Configuration Management

Publish the config for customization:

php artisan vendor:publish --provider="Vonage\NexmoBridge\NexmoBridgeServiceProvider"

Update .env:

VONAGE_API_KEY=your_key
VONAGE_API_SECRET=your_secret

3. Service Container Integration

Bind the Vonage client in AppServiceProvider:

public function register()
{
    $this->app->singleton('nexmo', function ($app) {
        return new Vonage\Client($app['config']['nexmo-bridge']);
    });
}

4. Legacy Method Wrappers

Leverage the bridge’s static method wrappers for common operations:

// Legacy-style call (internally uses Vonage SDK)
$response = Nexmo\Client::sendSms('from', 'to', 'Hello!');

5. Testing Workflow

Mock the Vonage client in tests:

$mock = Mockery::mock('alias:Vonage\Client');
$mock->shouldReceive('sms()->send')->once();
$this->app->instance('nexmo', $mock);

Gotchas and Tips

Pitfalls

  1. Namespace Collisions Avoid mixing Nexmo\ and Vonage\ namespaces in the same file. Use aliases or fully qualify names:

    // ❌ Ambiguous
    $client = new Nexmo\Client(...);
    
    // ✅ Explicit
    $client = new Vonage\Client(...);
    
  2. Deprecated Method Warnings The bridge logs deprecation warnings for Nexmo methods. Monitor logs for migration prompts:

    [NexmoBridge] Method Nexmo\Client::sendSms() is deprecated. Use Vonage\Sms\Sms::send().
    
  3. Configuration Overrides Bridge config takes precedence over .env if not published. Explicitly publish to avoid surprises:

    // config/nexmo-bridge.php
    'apiKey' => env('VONAGE_API_KEY', 'fallback_key'),
    

Debugging Tips

  1. Enable Verbose Logging Add to config/logging.php:

    'channels' => [
        'nexmo' => [
            'driver' => 'single',
            'path' => storage_path('logs/nexmo.log'),
            'level' => 'debug',
        ],
    ],
    

    Then log bridge events:

    \Vonage\NexmoBridge\Logger::debug('Custom event', ['data' => $data]);
    
  2. Check HTTP Requests Use Laravel’s tap to inspect Vonage requests:

    $client->sms()->send()->tap(function ($response) {
        \Log::debug('Response:', $response->getBody());
    });
    

Extension Points

  1. Custom Bridge Classes Extend Vonage\NexmoBridge\Client to add legacy-specific logic:

    class CustomNexmoClient extends \Vonage\NexmoBridge\Client {
        public function legacySend($params) {
            return $this->sms()->send($params['from'], $params['to'], $params['text']);
        }
    }
    
  2. Event Listeners Listen for bridge events (e.g., nexmo.bridge.method.called):

    public function handle(NexmoBridgeEvent $event) {
        \Log::info("Called {$event->method} with args: " . json_encode($event->args));
    }
    
  3. Fallback for Missing Methods Override handleMissingMethod in a custom client:

    public function __call($method, $args) {
        if (strpos($method, 'nexmo_') === 0) {
            return $this->fallbackToVonage(substr($method, 6), $args);
        }
        throw new \BadMethodCallException("Method {$method} not found.");
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4