-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
94 lines (82 loc) · 2.23 KB
/
controller.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Concrete\Package\CdnCachePurgeCloudflare;
use Concrete\Core\Backup\ContentImporter;
use Macareux\CloudflareCache\Cache\CloudflareCache;
use Core;
use Events;
use Package;
/**
* Class Controller
* @package Concrete\Package\CdnCachePurgeCloudfront
*/
class Controller extends Package
{
/**
* @var string Package handle.
*/
protected $pkgHandle = 'cdn_cache_purge_cloudflare';
/**
* @var string Required concrete5 version.
*/
protected $appVersionRequired = '8.0.0';
/**
* @var string Package version.
*/
protected $pkgVersion = '0.9.2';
/**
* @see https://documentation.concretecms.org/developers/packages/adding-custom-code-to-packages
*
* @var string[]
*/
protected $pkgAutoloaderRegistries = [
'src' => '\Macareux\CloudflareCache',
];
/**
* @var bool Remove \Src from package namespace.
*/
protected $pkgAutoloaderMapCoreExtensions = true;
/**
* Returns the translated package description.
*
* @return string
*/
public function getPackageDescription()
{
return t("Flushes Cloudflare cache when you click Clear Cache button.");
}
/**
* Returns the translated package name.
*
* @return string
*/
public function getPackageName()
{
return t("CDN Cache Purge for Cloudflare");
}
/**
* Startup process of the package.
*/
public function on_start()
{
$cloudflare = $cloudflare = new CloudflareCache();
Events::addListener('on_cache_flush', function () use ($cloudflare) {
$base_path = Core::getApplicationRelativePath() . '/';
$cloudflare->createPurgeRequest([
$base_path . '*',
]);
});
}
/**
* Install process of the package.
*/
public function install()
{
if (version_compare(PHP_VERSION, $this->phpVersionRequired, '<')) {
throw new Exception(t('This package requires PHP %s or greater.', $this->phpVersionRequired));
}
$pkg = parent::install();
$ci = new ContentImporter();
$ci->importContentFile($pkg->getPackagePath() . '/config/dashboard.xml');
return $pkg;
}
}