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