PHP code example of jlchassaing / cdn-purger

1. Go to this page and download the library: Download jlchassaing/cdn-purger 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/ */

    

jlchassaing / cdn-purger example snippets


return [
    // ...
    CdnPurge\CdnPurgeBundle::class => ['all' => true],
];

use CdnPurge\Service\PurgeManager;

class MyController
{
    public function __construct(private PurgeManager $purgeManager) {}

    public function clearCache(): void
    {
        // Purger des URLs spécifiques
        $this->purgeManager->purge([
            'https://example.com/page-1',
            'https://example.com/page-2',
        ]);

        // Purger tout le cache
        $this->purgeManager->purgeAll();

        // Cibler un connecteur précis
        $this->purgeManager->purge(['https://example.com/'], 'cloudflare');
    }
}

use CdnPurge\Connector\ConnectorInterface;
use CdnPurge\Exception\PurgeException;

class AkamaiConnector implements ConnectorInterface
{
    public function getName(): string
    {
        return 'akamai';
    }

    public function purge(array $urls): void
    {
        // ... appel API Akamai
    }

    public function purgeAll(): void
    {
        // ... appel API Akamai
    }
}