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

Sulu Bunny Cdn Bundle Laravel Package

alengo/sulu-bunny-cdn-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the bundle via Composer:

    composer require alengo/sulu-bunny-cdn-bundle
    

    Enable it in config/bundles.php:

    Alengo\SuluBunnyCdnBundle\SuluBunnyCdnBundle::class => ['all' => true],
    
  2. Configuration Publish the default config:

    php bin/console sulu-bunny-cdn:install
    

    Update config/packages/sulu_bunny_cdn.yaml with your BunnyCDN credentials:

    alengo_sulu_bunny_cdn:
        api_key: '%env(BUNNY_API_KEY)%'
        storage_zone: 'your-storage-zone'
    
  3. First Use Case Trigger a cache purge after content updates:

    use Alengo\SuluBunnyCdnBundle\Service\BunnyCdnPurger;
    
    class YourContentController {
        public function updateContent(BunnyCdnPurger $purger) {
            // Update content in Sulu/Symfony
            $purger->purgeByTag('content-updated'); // Purges all cached assets tagged with 'content-updated'
        }
    }
    

Implementation Patterns

Tag-Based Invalidation Workflow

  1. Tagging Assets Use the BunnyCdnTagger service to attach tags to responses:

    $response = $this->getContentResponse();
    $response = $tagger->addTag($response, 'content-updated');
    return $response;
    
  2. Purging Strategies

    • Wildcard Purge (for broad invalidation):
      $purger->purgeWildcard('*.jpg'); // Purges all JPG files
      
    • Tag-Based Purge (for granular control):
      $purger->purgeByTag('homepage-assets'); // Purges all assets tagged with 'homepage-assets'
      
  3. Integration with FOSHttpCache The bundle hooks into FOSHttpCache’s CacheWarmer. Extend the default warmer:

    # config/packages/fos_http_cache.yaml
    fos_http_cache:
        warmer:
            Alengo\SuluBunnyCdnBundle\CacheWarmer\BunnyCdnCacheWarmer: ~
    
  4. Sulu CMS Integration Override Sulu’s ContentCacheWarmer to include BunnyCDN purges:

    use Alengo\SuluBunnyCdnBundle\Service\BunnyCdnPurger;
    
    class CustomContentCacheWarmer extends \Sulu\Bundle\CoreBundle\CacheWarmer\ContentCacheWarmer {
        public function __construct(BunnyCdnPurger $purger) {
            $this->purger = $purger;
        }
    
        public function warmUp($cacheDir) {
            parent::warmUp($cacheDir);
            $this->purger->purgeByTag('sulu-content'); // Purge after Sulu content updates
        }
    }
    

Gotchas and Tips

Common Pitfalls

  1. API Key Permissions Ensure your BunnyCDN API key has purge permissions for the storage zone. Test with:

    php bin/console debug:container alengo_sulu_bunny_cdn.bunny_cdn_client
    

    Then call:

    $client->purge('test-tag');
    

    to verify connectivity.

  2. Tagging Overhead Avoid excessive tagging (e.g., per-request tags). Use semantic tags like:

    • homepage-assets
    • product-page-{id}
    • global-header
  3. Wildcard Purges Are Expensive Wildcard purges (*.png) trigger full scans of the storage zone. Prefer tag-based purges where possible.

  4. FOSHttpCache Conflicts If using both sulu_http_cache and fos_http_cache, ensure the BunnyCdnCacheWarmer is only registered once to avoid duplicate purges.

Debugging Tips

  • Log Purge Requests Enable debug logging in config/packages/sulu_bunny_cdn.yaml:

    alengo_sulu_bunny_cdn:
        debug: true
    

    Check logs for failed purges (e.g., invalid tags or API errors).

  • Verify Tags in BunnyCDN Dashboard Navigate to your BunnyCDN storage zone → Cache → Tags to confirm tags are applied.

  • Test Locally with Mock Client Override the client in tests:

    $container->set('alengo_sulu_bunny_cdn.bunny_cdn_client', $mockClient);
    

Extension Points

  1. Custom Purge Logic Extend BunnyCdnPurger to add conditional purges:

    class CustomPurger extends BunnyCdnPurger {
        public function purgeIfNeeded(string $tag, bool $condition) {
            if ($condition) {
                $this->purgeByTag($tag);
            }
        }
    }
    
  2. Dynamic Tag Generation Generate tags based on Sulu content:

    $tag = 'product-'.$product->getId();
    $tagger->addTag($response, $tag);
    
  3. Webhook-Based Purges Use BunnyCDN’s webhook system to trigger purges externally (e.g., from a CI/CD pipeline):

    # config/packages/sulu_bunny_cdn.yaml
    alengo_sulu_bunny_cdn:
        webhook_secret: '%env(BUNNY_WEBHOOK_SECRET)%'
    

    Then implement a controller to handle webhook payloads.

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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels