forked from crowdfavorite-mirrors/wp-w3-total-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cdn_CloudFrontFsd_Engine.php
executable file
·54 lines (38 loc) · 1.33 KB
/
Cdn_CloudFrontFsd_Engine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace W3TC;
class Cdn_CloudFrontFsd_Engine {
private $access_key;
private $secret_key;
private $distribution_id;
function __construct( $config = array() ) {
$this->access_key = $config['access_key'];
$this->secret_key = $config['secret_key'];
$this->distribution_id = $config['distribution_id'];
}
function flush_urls( $urls ) {
if ( empty( $this->access_key ) || empty( $this->secret_key ) ||
empty( $this->distribution_id ) )
throw new \Exception( __( 'Access key not specified.', 'w3-total-cache' ) );
$api = new Cdn_CloudFrontFsd_Api( $this->access_key, $this->secret_key );
$uris = array();
foreach ( $urls as $url ) {
$parsed = parse_url( $url );
$relative_url =
( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) .
( isset( $parsed['query'] ) ? '?' . $parsed['query'] : '' );
$uris[] = $relative_url;
}
$api->invalidation_create( $this->distribution_id, $uris );
}
/**
* Flushes CDN completely
*/
function flush_all() {
if ( empty( $this->access_key ) || empty( $this->secret_key ) ||
empty( $this->distribution_id ) )
throw new \Exception( __( 'Access key not specified.', 'w3-total-cache' ) );
$api = new Cdn_CloudFrontFsd_Api( $this->access_key, $this->secret_key );
$uris = array( '/*' );
$api->invalidation_create( $this->distribution_id, $uris );
}
}