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

Cdn77 Bundle Laravel Package

dekalee/cdn77-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require dekalee/cdn77-bundle
    

    Register the bundle in config/app.php (Laravel 5.5+) under providers:

    Dekalee\Cdn77Bundle\DekaleeCdn77Bundle::class,
    
  2. Configuration Add to .env:

    DEKALEE_CDN77_LOGIN=your_login
    DEKALEE_CDN77_PASSWORD=your_password
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Dekalee\Cdn77Bundle\DekaleeCdn77Bundle" --tag="config"
    

    Update config/cdn77.php (if published).

  3. First Use Case Inject the Cdn77Client into a service/controller:

    use Dekalee\Cdn77Bundle\Client\Cdn77Client;
    
    public function __construct(private Cdn77Client $cdn77) {}
    
    // Purge a URL
    $this->cdn77->purge(['url' => 'https://example.com/image.jpg']);
    

Implementation Patterns

Core Workflows

  1. Purging Assets

    • Single URL:
      $this->cdn77->purge(['url' => 'https://example.com/image.jpg']);
      
    • Bulk Purge:
      $urls = ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'];
      $this->cdn77->purge($urls);
      
    • Purge All:
      $this->cdn77->purgeAll();
      
  2. Uploading Files

    • Use the underlying Cdn77 library (not directly exposed by the bundle) via the client:
      $this->cdn77->getClient()->uploadFile($filePath, $cdnPath);
      
  3. Resource Management

    • List resources:
      $resources = $this->cdn77->listResources();
      
    • Delete a resource:
      $this->cdn77->deleteResource(['url' => 'https://example.com/image.jpg']);
      
  4. Event-Driven Purging

    • Hook into Laravel events (e.g., illuminate.filesystem.updated) to auto-purge:
      Event::listen('illuminate.filesystem.updated', function ($event) {
          $this->cdn77->purge(['url' => $event->path]);
      });
      

Integration Tips

  • Service Container Binding Bind the client to a custom interface for better testability:

    $this->app->bind(
        Dekalee\Cdn77Bundle\Contracts\Cdn77Interface::class,
        Dekalee\Cdn77Bundle\Client\Cdn77Client::class
    );
    
  • Queue Purging Offload purging to a queue job to avoid blocking requests:

    class PurgeCdnJob implements ShouldQueue {
        public function handle(Cdn77Client $cdn77) {
            $cdn77->purge(['url' => $this->url]);
        }
    }
    
  • Middleware for Dynamic URLs Create middleware to purge CDN on route changes:

    public function handle($request, Closure $next) {
        $response = $next($request);
        $this->cdn77->purge(['url' => $request->url()]);
        return $response;
    }
    

Gotchas and Tips

Pitfalls

  1. Authentication Failures

    • Ensure .env credentials match CDN77 account.
    • Debug with:
      try {
          $this->cdn77->purge(['url' => 'test']);
      } catch (\Exception $e) {
          Log::error('CDN77 Error: ' . $e->getMessage());
      }
      
  2. Rate Limiting

    • CDN77 may throttle requests. Implement exponential backoff:
      use Symfony\Component\Process\Exception\ProcessTimedOutException;
      
      try {
          $this->cdn77->purge($urls);
      } catch (ProcessTimedOutException $e) {
          sleep(2); // Retry after delay
          $this->cdn77->purge($urls);
      }
      
  3. URL Formatting

    • Ensure URLs are absolute (include http:// or https://). Relative paths will fail.
  4. Bundle Compatibility

    • Test with Laravel 5.5+ (Symfony 3.4+). Older versions may require adjustments.

Debugging

  • Enable API Logging Add to config/cdn77.php:

    debug: true,
    

    Logs will appear in storage/logs/laravel.log.

  • Check API Responses Inspect raw responses via:

    $response = $this->cdn77->getClient()->purge(['url' => 'test']);
    Log::debug('CDN77 Response:', [$response->getBody()]);
    

Extension Points

  1. Custom API Endpoints Override URLs in config:

    dekalee_cdn77:
        purge: https://custom-api.example.com/purge
    
  2. Extend Client Create a decorator for additional logic:

    class ExtendedCdn77Client implements Cdn77Interface {
        private $cdn77;
    
        public function __construct(Cdn77Client $cdn77) {
            $this->cdn77 = $cdn77;
        }
    
        public function purge(array $urls) {
            // Add analytics or pre-processing
            $this->cdn77->purge($urls);
        }
    }
    
  3. Add Custom Commands Extend the bundle with Artisan commands:

    Artisan::command('cdn:purge-all', function () {
        $this->cdn77->purgeAll();
    });
    

Performance Tips

  • Batch Purges Group URLs into chunks of 100 (CDN77’s recommended limit):

    array_chunk($urls, 100, function ($chunk) {
        $this->cdn77->purge($chunk);
    });
    
  • Cache Purge Events Cache purge operations to avoid redundant calls:

    if (!Cache::has("cdn_purge_{$url}")) {
        $this->cdn77->purge(['url' => $url]);
        Cache::put("cdn_purge_{$url}", true, now()->addHours(1));
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky