listDistributions() public static méthode

Get a list of CloudFront distributions
public static listDistributions ( ) : array
Résultat array
function test_listDistributions()
{
    if (($dists = S3::listDistributions()) !== false) {
        if (sizeof($dists) == 0) {
            echo "listDistributions(): No distributions\n";
        }
        foreach ($dists as $dist) {
            var_dump($dist);
        }
    } else {
        echo "listDistributions(): Failed to get distribution list\n";
    }
}
Exemple #2
0
/**
 * Invalidates all cloudfront paths stored in `$pathsToInvalidate`. Needs to
 * invalidate everything in a single batch request otherwise cloudfront limits
 * are hit (3 active invalidation requests per distribution)
 *
 * Called on each wp_redirect since that's the only way to capture multiple
 * delete calls in a single request (i.e., through the bulk actions)
 *
 * @param integer $postId The original post ID
 */
function invalidateCloudfrontPosts($url)
{
    if (empty($pathsToInvalidate)) {
        return $url;
    }
    $s3Key = get_option('s3_access_key');
    $s3KeySecret = get_option('s3_access_secret');
    $S3 = new S3($s3Key, $s3KeySecret);
    // invalidate cloudfront cache (if applicable)
    $downloadDomain = get_option('s3_download');
    if (!empty($downloadDomain)) {
        $distributions = $S3->listDistributions();
        // get matching distribution id
        foreach ($distributions as $distributionId => $distributionDetails) {
            if ($distributionDetails['domain'] === $downloadDomain) {
                $S3->invalidateDistribution($distributionId, $this->pathsToInvalidate);
                break;
            }
        }
    }
    return $url;
}