Weave 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

Php Sdk Laravel Package

getkeymanager/php-sdk

PHP SDK for integrating with GetKeyManager: manage API keys and access securely from your Laravel or PHP apps. Simple client setup, request helpers, and authentication support to streamline key creation, retrieval, rotation, and usage.

View on GitHub
Deep Wiki
Context7
## Technical Evaluation
### **Architecture Fit**
- **Monolithic vs. Microservices**:
  - **Monolithic**: Unchanged; direct Composer integration remains viable. Middleware/service layer integration still optimal.
  - **Microservices**: New **async validation webhooks** (3.3.0) enable event-driven architectures. Requires Laravel queue/listener setup (e.g., `Illuminate\Queue\Listeners`) to process webhook payloads.
  - **Event-Driven**: Now **partially supported** via webhooks (e.g., license expiration events). Requires Laravel’s queue system for async handling.

- **State Management**:
  - **New**: Local license storage API (`LicenseManager::storeLocally()`) for offline scenarios. Reduces risk of offline failures.
  - **Caching**: Redis integration remains recommended; new `cacheTTL` config option in SDK (default: 3600s).

### **Integration Feasibility**
- **PHP/Laravel Compatibility**:
  - **Pros**:
    - New **Laravel facade** (`GetKeyManager\Facades\License`) reduces boilerplate.
    - Webhook listeners now natively supported via `LicenseWebhookHandler` trait.
  - **Cons**:
    - **Breaking**: `LicenseManager::validate()` signature changed (now returns `LicenseResponse` object instead of bool).
    - **Workaround**: Update calls to:
      ```php
      $response = app(LicenseManager::class)->validate();
      if (!$response->isValid()) { ... }
      ```
  - **Dependency Conflicts**:
    - New dependency: `symfony/event-dispatcher` (for webhooks). Check for conflicts with Laravel’s event system.

- **Dependency Conflicts**:
  - Low risk for core functionality. **New**: `symfony/event-dispatcher` may conflict with Laravel’s `illuminate/events` if not namespaced properly.
  - **Mitigation**: Use `composer why-not symfony/event-dispatcher` and alias in `composer.json` if needed.

### **Technical Risk**
| **Risk Area**               | **Severity** | **Mitigation**                                                                 |
|-----------------------------|-------------|---------------------------------------------------------------------------------|
| **Webhook Reliability**     | High        | Implement Laravel’s `failed_jobs` table monitoring and retry logic.            |
| **Breaking Changes**        | High        | Update all `validate()` calls; test with `phpunit` and `pest`.                  |
| **Event-Dispatcher Conflict**| Medium      | Isolate SDK events in a custom namespace or use Laravel’s event system.        |
| **Local Storage Security**  | Medium      | Encrypt locally stored licenses (e.g., `storage/encrypted/licenses`).           |
| **Rate Limits**             | High        | New `retryAfter` field in `LicenseResponse`; implement exponential backoff.    |

### **Key Questions**
1. **Webhook Integration Depth**:
   - Does the app need to react to **all** webhook events (e.g., `license.activated`, `license.expired`) or only specific ones?
   - *Impact*: May require custom event handlers or Laravel’s `HandleJobsMiddleware`.

2. **Local Storage Encryption**:
   - How sensitive are license keys? Does the app need **end-to-end encryption** for locally stored licenses?
   - *Impact*: SDK provides `storeLocally()` but not encryption; may need `openssl` integration.

3. **Webhook Authentication**:
   - How will Laravel verify webhook payloads (e.g., HMAC signatures)?
   - *Impact*: SDK requires `webhookSecret` config; ensure `.env` is secure.

4. **Queue Backpressure**:
   - Under high load, could webhook processing overwhelm Laravel’s queue?
   - *Impact*: Monitor `failed_jobs` table; consider batching or dedicated queue workers.

5. **Multi-Region Deployments**:
   - Will webhooks be processed globally, or is regional failover needed?
   - *Impact*: SDK webhooks are HTTP-based; may need CDN or regional queue workers.

---

## Integration Approach
### **Stack Fit**
- **PHP/Laravel Alignment**:
  - **Strengths**:
    - **Facade**: `GetKeyManager\Facades\License` reduces manual DI.
    - **Webhooks**: Native integration with Laravel’s queue system (e.g., `LicenseWebhookHandler`).
    - **Local Storage**: `LicenseManager::storeLocally()` aligns with Laravel’s `storage/` directory.
  - **Gaps**:
    - **Event System**: SDK’s `symfony/event-dispatcher` may conflict with Laravel’s. Use Laravel’s events instead:
      ```php
      event(new LicenseExpired($license));
      ```
    - **No Queue Worker**: Webhook processing requires manual queue setup (e.g., `php artisan queue:work`).

- **Alternative Stacks**:
  - **Symfony**: Better alignment with SDK’s event system.
  - **Non-PHP**: Requires proxy service for webhooks (e.g., AWS Lambda).

### **Migration Path**
1. **Phase 1: SDK Update (1 day)**
   - Update Composer: `composer require getkeymanager/php-sdk:^3.3.0`.
   - Update `validate()` calls to use `LicenseResponse` object.
   - Add facade to `config/app.php`:
     ```php
     'aliases' => [
         'License' => GetKeyManager\Facades\License::class,
     ],
     ```

2. **Phase 2: Webhook Setup (3–5 days)**
   - Configure webhook endpoint in `routes/web.php`:
     ```php
     Route::post('/license-webhook', [LicenseWebhookHandler::class, 'handle']);
     ```
   - Set up queue listener in `app/Providers/QueueServiceProvider.php`:
     ```php
     $this->app->booted(function () {
         $this->app->make('Illuminate\Contracts\Queue\Queue')
             ->listen('license-webhook', LicenseWebhookHandler::class);
     });
  • Configure .env:
    LICENSE_WEBHOOK_SECRET=your_secret_here
    QUEUE_CONNECTION=redis
    
  1. Phase 3: Offline Support (2–3 days)
    • Implement local storage in a service:
      // app/Services/LocalLicenseStorage.php
      public function store($licenseData)
      {
          File::put(storage_path('encrypted/licenses/current.json'), $this->encrypt($licenseData));
      }
      
    • Add middleware to sync licenses on reconnect:
      // app/Http/Middleware/SyncLicenseOnReconnect.php
      public function handle($request, Closure $next)
      {
          if (app(LicenseManager::class)->isOffline()) {
              app(LocalLicenseStorage::class)->syncWithCloud();
          }
          return $next($request);
      }
      

Compatibility

  • Laravel Versions:

    • Tested with Laravel 10/11. New: Requires PHP 8.1+ (due to symfony/event-dispatcher).
    • Check: Run php artisan package:discover to resolve facade conflicts.
  • PHP Extensions:

    • New: openssl required for local license encryption.
    • Verify: Add to php.ini or Dockerfile:
      extension=openssl
      
  • Database:

    • No changes, but consider adding a licenses table for audit logs:
      Schema::create('licenses', function (Blueprint $table) {
          $table->id();
          $table->text('payload');
          $table->timestamp('expires_at')->nullable();
          $table->timestamps();
      });
      

Sequencing

  1. Prerequisites:

  2. Critical Path:

    • Facade/Response Updates: Must be done first to avoid runtime errors.
    • Webhook Endpoint: Secure this route (e.g., IP whitelisting) before enabling in SDK.
  3. Non-Critical:

    • Local storage encryption (post-MVP).
    • Custom event dispatching (if not using SDK’s webhooks).

Operational Impact

Maintenance

  • Dependencies:

    • New: Monitor symfony/event-dispatcher for updates.
    • Automation: Add composer why-not to CI pipeline to catch conflicts early.
    • Deprecation: SDK now deprecates LicenseManager::check() in favor of validate().
  • Configuration Drift:

    • Centralize new settings in config/license.php:
      return [
          'webhook_secret' => env('LICENSE_WEBHOOK_SECRET'),
          'local_storage_path' => storage_path('encrypted/licenses'),
          'webhook_events' => ['license.activated', 'license.expired'],
      ];
      
  • Deprecation:

    • Risk: LicenseManager::check() removed in 3.3.0. Update all usages.
    • Tool: Use phpstan to detect deprecated method calls.

Support

  • Debugging:
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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc