1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed'); |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* DomainBase Class |
13
|
|
|
* A container for all domain data related to the plugin |
14
|
|
|
* |
15
|
|
|
* @package EventEspresso\core\domain |
16
|
|
|
* @author Darren Ethier |
17
|
|
|
* @since 4.9.38 |
18
|
|
|
*/ |
19
|
|
|
abstract class DomainBase implements DomainInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Equivalent to `__FILE__` for main plugin file. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $plugin_file; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* String indicating version for plugin |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $version; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string $plugin_basename |
38
|
|
|
*/ |
39
|
|
|
private $plugin_basename; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string $plugin_path |
43
|
|
|
*/ |
44
|
|
|
private $plugin_path; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string $plugin_url |
48
|
|
|
*/ |
49
|
|
|
private $plugin_url; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Initializes internal properties. |
55
|
|
|
* |
56
|
|
|
* @param string $plugin_file |
57
|
|
|
* @param string $version |
58
|
|
|
* @throws InvalidArgumentException |
59
|
|
|
*/ |
60
|
|
|
public function __construct($plugin_file, $version) |
61
|
|
|
{ |
62
|
|
|
$this->setPluginFile($plugin_file); |
63
|
|
|
$this->setVersion($version); |
64
|
|
|
$this->plugin_basename = plugin_basename($plugin_file); |
65
|
|
|
$this->plugin_path = plugin_dir_path($plugin_file); |
66
|
|
|
$this->plugin_url = plugin_dir_url($plugin_file); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $plugin_file |
72
|
|
|
* @throws InvalidArgumentException |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
private function setPluginFile($plugin_file) |
75
|
|
|
{ |
76
|
|
|
if(empty($plugin_file) || ! is_string($plugin_file)){ |
77
|
|
|
throw new InvalidArgumentException( |
78
|
|
|
esc_html__( |
79
|
|
|
'You need to supply a path to the addon plugin file in order to generate a Domain class', |
80
|
|
|
'event_espresso' |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
if(! is_readable($plugin_file)){ |
85
|
|
|
throw new InvalidArgumentException( |
86
|
|
|
esc_html__( |
87
|
|
|
'You need to supply a valid path to the addon plugin file in order to generate a Domain class', |
88
|
|
|
'event_espresso' |
89
|
|
|
) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
$this->plugin_file = $plugin_file; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $version |
98
|
|
|
* @throws InvalidArgumentException |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
private function setVersion($version) |
101
|
|
|
{ |
102
|
|
|
if (empty($version) || ! is_string($version)) { |
103
|
|
|
throw new InvalidArgumentException( |
104
|
|
|
esc_html__( |
105
|
|
|
'You need to supply a version string in order to generate a Domain class', |
106
|
|
|
'event_espresso' |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
if (strpos($version, '.') === false) { |
111
|
|
|
throw new InvalidArgumentException( |
112
|
|
|
esc_html__( |
113
|
|
|
'You need to supply a valid version string in order to generate a Domain class', |
114
|
|
|
'event_espresso' |
115
|
|
|
) |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
$this->version = $version; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
* @throws DomainException |
125
|
|
|
*/ |
126
|
|
|
public function pluginFile() |
127
|
|
|
{ |
128
|
|
|
return $this->plugin_file; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
* @throws DomainException |
136
|
|
|
*/ |
137
|
|
|
public function pluginBasename() |
138
|
|
|
{ |
139
|
|
|
return $this->plugin_basename; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return string |
146
|
|
|
*/ |
147
|
|
|
public function pluginPath() |
148
|
|
|
{ |
149
|
|
|
return $this->plugin_path; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
* @throws DomainException |
157
|
|
|
*/ |
158
|
|
|
public function pluginUrl() |
159
|
|
|
{ |
160
|
|
|
return $this->plugin_url; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return string |
167
|
|
|
* @throws DomainException |
168
|
|
|
*/ |
169
|
|
|
public function version() |
170
|
|
|
{ |
171
|
|
|
return $this->version; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
} |
176
|
|
|
|