| 1 |
<?php |
| 2 |
namespace BerqWP; |
| 3 |
use BerqWP\Cache; |
| 4 |
use BerqWP\CriticalCSS; |
| 5 |
use BerqWP\CDN; |
| 6 |
// use BerqWP\GuzzleHttp\Client; |
| 7 |
use GuzzleHttp\Client; |
| 8 |
|
| 9 |
|
| 10 |
class BerqWP |
| 11 |
{ |
| 12 |
protected $client = null; |
| 13 |
protected $license_key = null; |
| 14 |
protected $cache_directory = null; |
| 15 |
protected $storage_dir = null; |
| 16 |
static $endpoint = 'https://boost.berqwp.com/optimize/'; |
| 17 |
|
| 18 |
function __construct($license_key, $cache_directory, $storage_dir) { |
| 19 |
$this->license_key = $license_key; |
| 20 |
$this->cache_directory = $cache_directory; |
| 21 |
$this->storage_dir = $storage_dir; |
| 22 |
|
| 23 |
$this->client = new Client([ |
| 24 |
'base_uri' => self::$endpoint, |
| 25 |
'http_errors' => false, |
| 26 |
'verify' => false, |
| 27 |
'timeout' => 30, |
| 28 |
'headers' => [ |
| 29 |
'User-Agent' => 'BerqWP/1.0 (https://berqwp.com)' |
| 30 |
] |
| 31 |
]); |
| 32 |
} |
| 33 |
|
| 34 |
function request_cache($post_data, $timeout = 30) { |
| 35 |
$cache = new Cache($this->client, $this->cache_directory, $this->storage_dir); |
| 36 |
return $cache->request_cache($post_data, $timeout); |
| 37 |
} |
| 38 |
|
| 39 |
function request_multi_cache($post_data_arr) { |
| 40 |
$cache = new Cache($this->client, $this->cache_directory, $this->storage_dir); |
| 41 |
return $cache->request_multi_cache($post_data_arr); |
| 42 |
} |
| 43 |
|
| 44 |
function purge_critilclcss($domain) { |
| 45 |
$critical = new CriticalCSS($this->client, $this->license_key); |
| 46 |
return $critical->purge_all($domain); |
| 47 |
} |
| 48 |
|
| 49 |
function purge_criticlecss_url($page_url) { |
| 50 |
$critical = new CriticalCSS($this->client, $this->license_key); |
| 51 |
return $critical->purge_url($page_url); |
| 52 |
} |
| 53 |
|
| 54 |
function purge_cdn($domain) { |
| 55 |
$cdn = new CDN($this->client, $this->license_key); |
| 56 |
return $cdn->purge_all($domain); |
| 57 |
} |
| 58 |
|
| 59 |
function cdn_stale_assets($domain) { |
| 60 |
$cdn = new CDN($this->client, $this->license_key); |
| 61 |
return $cdn->stale_assets($domain); |
| 62 |
} |
| 63 |
|
| 64 |
function request_cache_warmup($post_data, $async = false) { |
| 65 |
$cache = new Cache($this->client, $this->cache_directory, $this->storage_dir); |
| 66 |
return $cache->request_cache_warmup($post_data, $async); |
| 67 |
} |
| 68 |
|
| 69 |
function queue_count($site_id) { |
| 70 |
$cache = new Cache($this->client, $this->cache_directory, $this->storage_dir); |
| 71 |
return $cache->queue_count($site_id); |
| 72 |
} |
| 73 |
|
| 74 |
function clear_cache_queue($site_url, $site_id) { |
| 75 |
$cache = new Cache($this->client, $this->cache_directory, $this->storage_dir); |
| 76 |
return $cache->clear_queue($site_url, $site_id, $this->license_key); |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|