@@ -14,5 +14,5 @@ |
||
14 | 14 | */ |
15 | 15 | class BatchRequestException extends \Exception |
16 | 16 | { |
17 | - // so far the same as exception |
|
17 | + // so far the same as exception |
|
18 | 18 | } |
@@ -4,63 +4,63 @@ |
||
4 | 4 | |
5 | 5 | interface HasSchemaInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * Returns whatever is set as the nicename for the object. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public function getSchemaDescription(); |
|
7 | + /** |
|
8 | + * Returns whatever is set as the nicename for the object. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public function getSchemaDescription(); |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Returns whatever is set as the $_schema_type property for the object. |
|
17 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
18 | - * |
|
19 | - * @return string|array |
|
20 | - */ |
|
21 | - public function getSchemaType(); |
|
15 | + /** |
|
16 | + * Returns whatever is set as the $_schema_type property for the object. |
|
17 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
18 | + * |
|
19 | + * @return string|array |
|
20 | + */ |
|
21 | + public function getSchemaType(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
26 | - * this method and return the properties for the schema. |
|
27 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
28 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
29 | - * |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function getSchemaProperties(); |
|
24 | + /** |
|
25 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
26 | + * this method and return the properties for the schema. |
|
27 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
28 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
29 | + * |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function getSchemaProperties(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * If a child class has enum values, they should override this method and provide a simple array |
|
36 | - * of the enum values. |
|
37 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
38 | - * are set on the instantiated object that could be filtered after construct. |
|
39 | - * |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getSchemaEnum(); |
|
34 | + /** |
|
35 | + * If a child class has enum values, they should override this method and provide a simple array |
|
36 | + * of the enum values. |
|
37 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
38 | + * are set on the instantiated object that could be filtered after construct. |
|
39 | + * |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getSchemaEnum(); |
|
43 | 43 | |
44 | - /** |
|
45 | - * This returns the value of the $_schema_format property on the object. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getSchemaFormat(); |
|
44 | + /** |
|
45 | + * This returns the value of the $_schema_format property on the object. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getSchemaFormat(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * This returns the value of the $_schema_readonly property on the object. |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function getSchemaReadonly(); |
|
51 | + /** |
|
52 | + * This returns the value of the $_schema_readonly property on the object. |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function getSchemaReadonly(); |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * This returns elements used to represent this field in the json schema. |
|
61 | - * |
|
62 | - * @link http://json-schema.org/ |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function getSchema(); |
|
59 | + /** |
|
60 | + * This returns elements used to represent this field in the json schema. |
|
61 | + * |
|
62 | + * @link http://json-schema.org/ |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function getSchema(); |
|
66 | 66 | } |
@@ -12,9 +12,9 @@ |
||
12 | 12 | */ |
13 | 13 | interface CaffeinatedInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Used to indicate when functionality is caffeinated or not. |
|
17 | - * @return bool |
|
18 | - */ |
|
19 | - public function isCaffeinated(); |
|
15 | + /** |
|
16 | + * Used to indicate when functionality is caffeinated or not. |
|
17 | + * @return bool |
|
18 | + */ |
|
19 | + public function isCaffeinated(); |
|
20 | 20 | } |
@@ -5,8 +5,8 @@ |
||
5 | 5 | interface SessionIdentifierInterface |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @return string |
|
10 | - */ |
|
11 | - public function id(); |
|
8 | + /** |
|
9 | + * @return string |
|
10 | + */ |
|
11 | + public function id(); |
|
12 | 12 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public function validate($email_address) |
24 | 24 | { |
25 | 25 | parent::validate($email_address); |
26 | - if (! is_email($email_address)) { |
|
26 | + if ( ! is_email($email_address)) { |
|
27 | 27 | throw new EmailValidationException( |
28 | 28 | esc_html__('The email address provided is not valid.', 'event_espresso') |
29 | 29 | ); |
@@ -14,19 +14,19 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPress extends Basic |
16 | 16 | { |
17 | - /** |
|
18 | - * @param string $email_address |
|
19 | - * @return boolean |
|
20 | - * @throws EmailValidationException |
|
21 | - */ |
|
22 | - public function validate($email_address) |
|
23 | - { |
|
24 | - parent::validate($email_address); |
|
25 | - if (! is_email($email_address)) { |
|
26 | - throw new EmailValidationException( |
|
27 | - esc_html__('The email address provided is not valid.', 'event_espresso') |
|
28 | - ); |
|
29 | - } |
|
30 | - return true; |
|
31 | - } |
|
17 | + /** |
|
18 | + * @param string $email_address |
|
19 | + * @return boolean |
|
20 | + * @throws EmailValidationException |
|
21 | + */ |
|
22 | + public function validate($email_address) |
|
23 | + { |
|
24 | + parent::validate($email_address); |
|
25 | + if (! is_email($email_address)) { |
|
26 | + throw new EmailValidationException( |
|
27 | + esc_html__('The email address provided is not valid.', 'event_espresso') |
|
28 | + ); |
|
29 | + } |
|
30 | + return true; |
|
31 | + } |
|
32 | 32 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $quantity = 1 |
31 | 31 | ) { |
32 | 32 | $total_line_item = $transaction->total_line_item(); |
33 | - if (! $total_line_item instanceof \EE_Line_Item) { |
|
33 | + if ( ! $total_line_item instanceof \EE_Line_Item) { |
|
34 | 34 | throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
35 | 35 | } |
36 | 36 | // create new line item for ticket |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $ticket, |
40 | 40 | $quantity |
41 | 41 | ); |
42 | - if (! $ticket_line_item instanceof \EE_Line_Item) { |
|
42 | + if ( ! $ticket_line_item instanceof \EE_Line_Item) { |
|
43 | 43 | throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
44 | 44 | } |
45 | 45 | $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
@@ -15,41 +15,41 @@ |
||
15 | 15 | */ |
16 | 16 | class CreateTicketLineItemService extends DomainService |
17 | 17 | { |
18 | - /** |
|
19 | - * @param \EE_Transaction $transaction |
|
20 | - * @param \EE_Ticket $ticket |
|
21 | - * @param int $quantity |
|
22 | - * @return \EE_Line_Item |
|
23 | - * @throws \EE_Error |
|
24 | - * @throws UnexpectedEntityException |
|
25 | - */ |
|
26 | - public function create( |
|
27 | - \EE_Transaction $transaction, |
|
28 | - \EE_Ticket $ticket, |
|
29 | - $quantity = 1 |
|
30 | - ) { |
|
31 | - $total_line_item = $transaction->total_line_item(); |
|
32 | - if (! $total_line_item instanceof \EE_Line_Item) { |
|
33 | - throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
34 | - } |
|
35 | - // create new line item for ticket |
|
36 | - $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
37 | - $total_line_item, |
|
38 | - $ticket, |
|
39 | - $quantity |
|
40 | - ); |
|
41 | - if (! $ticket_line_item instanceof \EE_Line_Item) { |
|
42 | - throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
43 | - } |
|
44 | - $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
45 | - // apply any applicable promotions that were initially used during registration to new line items |
|
46 | - do_action( |
|
47 | - 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
48 | - $total_line_item, |
|
49 | - $ticket, |
|
50 | - $transaction, |
|
51 | - $quantity |
|
52 | - ); |
|
53 | - return $ticket_line_item; |
|
54 | - } |
|
18 | + /** |
|
19 | + * @param \EE_Transaction $transaction |
|
20 | + * @param \EE_Ticket $ticket |
|
21 | + * @param int $quantity |
|
22 | + * @return \EE_Line_Item |
|
23 | + * @throws \EE_Error |
|
24 | + * @throws UnexpectedEntityException |
|
25 | + */ |
|
26 | + public function create( |
|
27 | + \EE_Transaction $transaction, |
|
28 | + \EE_Ticket $ticket, |
|
29 | + $quantity = 1 |
|
30 | + ) { |
|
31 | + $total_line_item = $transaction->total_line_item(); |
|
32 | + if (! $total_line_item instanceof \EE_Line_Item) { |
|
33 | + throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
34 | + } |
|
35 | + // create new line item for ticket |
|
36 | + $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
37 | + $total_line_item, |
|
38 | + $ticket, |
|
39 | + $quantity |
|
40 | + ); |
|
41 | + if (! $ticket_line_item instanceof \EE_Line_Item) { |
|
42 | + throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
43 | + } |
|
44 | + $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
45 | + // apply any applicable promotions that were initially used during registration to new line items |
|
46 | + do_action( |
|
47 | + 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
48 | + $total_line_item, |
|
49 | + $ticket, |
|
50 | + $transaction, |
|
51 | + $quantity |
|
52 | + ); |
|
53 | + return $ticket_line_item; |
|
54 | + } |
|
55 | 55 | } |
@@ -4,31 +4,31 @@ |
||
4 | 4 | interface SetHooksInterface |
5 | 5 | { |
6 | 6 | |
7 | - /** |
|
8 | - * a place to add action and filter hooks for regular frontend requests |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function setHooks(); |
|
7 | + /** |
|
8 | + * a place to add action and filter hooks for regular frontend requests |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function setHooks(); |
|
13 | 13 | |
14 | - /** |
|
15 | - * a place to add action and filter hooks for regular WP admin requests |
|
16 | - * |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function setAdminHooks(); |
|
14 | + /** |
|
15 | + * a place to add action and filter hooks for regular WP admin requests |
|
16 | + * |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function setAdminHooks(); |
|
20 | 20 | |
21 | - /** |
|
22 | - * a place to add action and filter hooks for AJAX requests |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function setAjaxHooks(); |
|
21 | + /** |
|
22 | + * a place to add action and filter hooks for AJAX requests |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function setAjaxHooks(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * a place to add action and filter hooks for REST API requests |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function setApiHooks(); |
|
28 | + /** |
|
29 | + * a place to add action and filter hooks for REST API requests |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function setApiHooks(); |
|
34 | 34 | } |
@@ -14,34 +14,34 @@ |
||
14 | 14 | */ |
15 | 15 | interface CapabilitiesActionRestrictionInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Return whether the item can be edited for the given context. |
|
19 | - * @param Context $context |
|
20 | - * @return bool |
|
21 | - */ |
|
22 | - public function canEdit(Context $context); |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Return whether the item can be read for the given context. |
|
27 | - * @param Context $context |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public function canRead(Context $context); |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Return whether the item can be deleted for the given context. |
|
35 | - * @param Context $context |
|
36 | - * @return bool |
|
37 | - */ |
|
38 | - public function canDelete(Context $context); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Return whether the item can be created for the given context |
|
43 | - * @param Context $context |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function canCreate(Context $context); |
|
17 | + /** |
|
18 | + * Return whether the item can be edited for the given context. |
|
19 | + * @param Context $context |
|
20 | + * @return bool |
|
21 | + */ |
|
22 | + public function canEdit(Context $context); |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Return whether the item can be read for the given context. |
|
27 | + * @param Context $context |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public function canRead(Context $context); |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Return whether the item can be deleted for the given context. |
|
35 | + * @param Context $context |
|
36 | + * @return bool |
|
37 | + */ |
|
38 | + public function canDelete(Context $context); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Return whether the item can be created for the given context |
|
43 | + * @param Context $context |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function canCreate(Context $context); |
|
47 | 47 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | } |
104 | 104 | // add defaults for missing pieces |
105 | - $version_parts += array(0,0,0,'p',0); |
|
105 | + $version_parts += array(0, 0, 0, 'p', 0); |
|
106 | 106 | // reassign to individual variables |
107 | 107 | list($major, $minor, $patch, $release, $build) = $version_parts; |
108 | 108 | return new Version( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function setMajor($major) |
132 | 132 | { |
133 | - if (! is_int($major)) { |
|
133 | + if ( ! is_int($major)) { |
|
134 | 134 | throw new InvalidDataTypeException( |
135 | 135 | '$major', |
136 | 136 | $major, |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function setMinor($minor) |
158 | 158 | { |
159 | - if (! is_int($minor)) { |
|
159 | + if ( ! is_int($minor)) { |
|
160 | 160 | throw new InvalidDataTypeException( |
161 | 161 | '$minor', |
162 | 162 | $minor, |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function setPatch($patch) |
184 | 184 | { |
185 | - if (! is_int($patch)) { |
|
185 | + if ( ! is_int($patch)) { |
|
186 | 186 | throw new InvalidDataTypeException( |
187 | 187 | '$patch', |
188 | 188 | $patch, |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | Version::RELEASE_TYPE_DECAF, |
215 | 215 | Version::RELEASE_TYPE_PROD, |
216 | 216 | ); |
217 | - if (! in_array($release, $valid_release_types, true)) { |
|
217 | + if ( ! in_array($release, $valid_release_types, true)) { |
|
218 | 218 | throw new InvalidArgumentException( |
219 | 219 | sprintf( |
220 | 220 | esc_html__( |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | private function setBuild($build) |
247 | 247 | { |
248 | - if (! is_int($build)) { |
|
248 | + if ( ! is_int($build)) { |
|
249 | 249 | throw new InvalidDataTypeException( |
250 | 250 | '$build', |
251 | 251 | $build, |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | { |
304 | 304 | $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
305 | 305 | if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
306 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
306 | + $version_string .= '.'.str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
307 | 307 | } |
308 | 308 | return $version_string; |
309 | 309 | } |
@@ -15,295 +15,295 @@ |
||
15 | 15 | */ |
16 | 16 | class Version |
17 | 17 | { |
18 | - const RELEASE_TYPE_RC = 'rc'; |
|
19 | - |
|
20 | - const RELEASE_TYPE_BETA = 'beta'; |
|
21 | - |
|
22 | - const RELEASE_TYPE_DECAF = 'decaf'; |
|
23 | - |
|
24 | - const RELEASE_TYPE_PROD = 'p'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var int $major |
|
28 | - */ |
|
29 | - private $major; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var int $minor |
|
33 | - */ |
|
34 | - private $minor; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var int $patch |
|
38 | - */ |
|
39 | - private $patch; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string $release |
|
43 | - */ |
|
44 | - private $release; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var int $build |
|
48 | - */ |
|
49 | - private $build; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Version constructor. |
|
54 | - * |
|
55 | - * @param int $major |
|
56 | - * @param int $minor |
|
57 | - * @param int $patch |
|
58 | - * @param string $release |
|
59 | - * @param int $build |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - * @throws InvalidArgumentException |
|
62 | - */ |
|
63 | - public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
64 | - { |
|
65 | - $this->setMajor($major); |
|
66 | - $this->setMinor($minor); |
|
67 | - $this->setPatch($patch); |
|
68 | - $this->setRelease($release); |
|
69 | - $this->setBuild($build); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $version_string |
|
75 | - * @return Version |
|
76 | - * @throws InvalidArgumentException |
|
77 | - */ |
|
78 | - public static function fromString($version_string) |
|
79 | - { |
|
80 | - // compare incoming version string against the lowest possible valid version |
|
81 | - if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
82 | - throw new InvalidArgumentException( |
|
83 | - sprintf( |
|
84 | - esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
85 | - $version_string |
|
86 | - ) |
|
87 | - ); |
|
88 | - } |
|
89 | - // break apart incoming version string |
|
90 | - $version_parts = explode('.', $version_string); |
|
91 | - // verify that version string at least contains {major}.{minor}.{patch} |
|
92 | - if (count($version_parts) < 3) { |
|
93 | - throw new InvalidArgumentException( |
|
94 | - sprintf( |
|
95 | - esc_html__( |
|
96 | - 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - $version_string |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - // add defaults for missing pieces |
|
104 | - $version_parts += array(0,0,0,'p',0); |
|
105 | - // reassign to individual variables |
|
106 | - list($major, $minor, $patch, $release, $build) = $version_parts; |
|
107 | - return new Version( |
|
108 | - (int) $major, |
|
109 | - (int) $minor, |
|
110 | - (int) $patch, |
|
111 | - $release, |
|
112 | - (int) $build |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function major() |
|
121 | - { |
|
122 | - return $this->major; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param int|string $major |
|
128 | - * @throws InvalidDataTypeException |
|
129 | - */ |
|
130 | - private function setMajor($major) |
|
131 | - { |
|
132 | - if (! is_int($major)) { |
|
133 | - throw new InvalidDataTypeException( |
|
134 | - '$major', |
|
135 | - $major, |
|
136 | - 'integer' |
|
137 | - ); |
|
138 | - } |
|
139 | - $this->major = absint($major); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return int |
|
145 | - */ |
|
146 | - public function minor() |
|
147 | - { |
|
148 | - return $this->minor; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param int|string $minor |
|
154 | - * @throws InvalidDataTypeException |
|
155 | - */ |
|
156 | - private function setMinor($minor) |
|
157 | - { |
|
158 | - if (! is_int($minor)) { |
|
159 | - throw new InvalidDataTypeException( |
|
160 | - '$minor', |
|
161 | - $minor, |
|
162 | - 'integer' |
|
163 | - ); |
|
164 | - } |
|
165 | - $this->minor = absint($minor); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return int |
|
171 | - */ |
|
172 | - public function patch() |
|
173 | - { |
|
174 | - return $this->patch; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param int|string $patch |
|
180 | - * @throws InvalidDataTypeException |
|
181 | - */ |
|
182 | - private function setPatch($patch) |
|
183 | - { |
|
184 | - if (! is_int($patch)) { |
|
185 | - throw new InvalidDataTypeException( |
|
186 | - '$patch', |
|
187 | - $patch, |
|
188 | - 'integer' |
|
189 | - ); |
|
190 | - } |
|
191 | - $this->patch = absint($patch); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function release() |
|
199 | - { |
|
200 | - return $this->release; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param string $release |
|
206 | - * @throws InvalidArgumentException |
|
207 | - */ |
|
208 | - private function setRelease($release) |
|
209 | - { |
|
210 | - $valid_release_types = array( |
|
211 | - Version::RELEASE_TYPE_RC, |
|
212 | - Version::RELEASE_TYPE_BETA, |
|
213 | - Version::RELEASE_TYPE_DECAF, |
|
214 | - Version::RELEASE_TYPE_PROD, |
|
215 | - ); |
|
216 | - if (! in_array($release, $valid_release_types, true)) { |
|
217 | - throw new InvalidArgumentException( |
|
218 | - sprintf( |
|
219 | - esc_html__( |
|
220 | - '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
221 | - 'event_espresso' |
|
222 | - ), |
|
223 | - $release, |
|
224 | - implode(', ', $valid_release_types) |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - $this->release = $release; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @return int |
|
234 | - */ |
|
235 | - public function build() |
|
236 | - { |
|
237 | - return $this->build; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param int|string $build |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - */ |
|
245 | - private function setBuild($build) |
|
246 | - { |
|
247 | - if (! is_int($build)) { |
|
248 | - throw new InvalidDataTypeException( |
|
249 | - '$build', |
|
250 | - $build, |
|
251 | - 'integer' |
|
252 | - ); |
|
253 | - } |
|
254 | - $this->build = absint($build); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @param Version $other_version |
|
260 | - * @return int |
|
261 | - */ |
|
262 | - public function compare(Version $other_version) |
|
263 | - { |
|
264 | - return version_compare((string) $this, (string) $other_version); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param Version $other_version |
|
270 | - * @return bool |
|
271 | - */ |
|
272 | - public function equals(Version $other_version) |
|
273 | - { |
|
274 | - return version_compare((string) $this, (string) $other_version, '=='); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * @param Version $other_version |
|
280 | - * @return bool |
|
281 | - */ |
|
282 | - public function newerThan(Version $other_version) |
|
283 | - { |
|
284 | - return version_compare((string) $this, (string) $other_version, '>'); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @param Version $other_version |
|
290 | - * @return bool |
|
291 | - */ |
|
292 | - public function olderThan(Version $other_version) |
|
293 | - { |
|
294 | - return version_compare((string) $this, (string) $other_version, '<'); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function __toString() |
|
302 | - { |
|
303 | - $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
304 | - if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
305 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
306 | - } |
|
307 | - return $version_string; |
|
308 | - } |
|
18 | + const RELEASE_TYPE_RC = 'rc'; |
|
19 | + |
|
20 | + const RELEASE_TYPE_BETA = 'beta'; |
|
21 | + |
|
22 | + const RELEASE_TYPE_DECAF = 'decaf'; |
|
23 | + |
|
24 | + const RELEASE_TYPE_PROD = 'p'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var int $major |
|
28 | + */ |
|
29 | + private $major; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var int $minor |
|
33 | + */ |
|
34 | + private $minor; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var int $patch |
|
38 | + */ |
|
39 | + private $patch; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string $release |
|
43 | + */ |
|
44 | + private $release; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var int $build |
|
48 | + */ |
|
49 | + private $build; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Version constructor. |
|
54 | + * |
|
55 | + * @param int $major |
|
56 | + * @param int $minor |
|
57 | + * @param int $patch |
|
58 | + * @param string $release |
|
59 | + * @param int $build |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + * @throws InvalidArgumentException |
|
62 | + */ |
|
63 | + public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
64 | + { |
|
65 | + $this->setMajor($major); |
|
66 | + $this->setMinor($minor); |
|
67 | + $this->setPatch($patch); |
|
68 | + $this->setRelease($release); |
|
69 | + $this->setBuild($build); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $version_string |
|
75 | + * @return Version |
|
76 | + * @throws InvalidArgumentException |
|
77 | + */ |
|
78 | + public static function fromString($version_string) |
|
79 | + { |
|
80 | + // compare incoming version string against the lowest possible valid version |
|
81 | + if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
82 | + throw new InvalidArgumentException( |
|
83 | + sprintf( |
|
84 | + esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
85 | + $version_string |
|
86 | + ) |
|
87 | + ); |
|
88 | + } |
|
89 | + // break apart incoming version string |
|
90 | + $version_parts = explode('.', $version_string); |
|
91 | + // verify that version string at least contains {major}.{minor}.{patch} |
|
92 | + if (count($version_parts) < 3) { |
|
93 | + throw new InvalidArgumentException( |
|
94 | + sprintf( |
|
95 | + esc_html__( |
|
96 | + 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + $version_string |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + // add defaults for missing pieces |
|
104 | + $version_parts += array(0,0,0,'p',0); |
|
105 | + // reassign to individual variables |
|
106 | + list($major, $minor, $patch, $release, $build) = $version_parts; |
|
107 | + return new Version( |
|
108 | + (int) $major, |
|
109 | + (int) $minor, |
|
110 | + (int) $patch, |
|
111 | + $release, |
|
112 | + (int) $build |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function major() |
|
121 | + { |
|
122 | + return $this->major; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param int|string $major |
|
128 | + * @throws InvalidDataTypeException |
|
129 | + */ |
|
130 | + private function setMajor($major) |
|
131 | + { |
|
132 | + if (! is_int($major)) { |
|
133 | + throw new InvalidDataTypeException( |
|
134 | + '$major', |
|
135 | + $major, |
|
136 | + 'integer' |
|
137 | + ); |
|
138 | + } |
|
139 | + $this->major = absint($major); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return int |
|
145 | + */ |
|
146 | + public function minor() |
|
147 | + { |
|
148 | + return $this->minor; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param int|string $minor |
|
154 | + * @throws InvalidDataTypeException |
|
155 | + */ |
|
156 | + private function setMinor($minor) |
|
157 | + { |
|
158 | + if (! is_int($minor)) { |
|
159 | + throw new InvalidDataTypeException( |
|
160 | + '$minor', |
|
161 | + $minor, |
|
162 | + 'integer' |
|
163 | + ); |
|
164 | + } |
|
165 | + $this->minor = absint($minor); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return int |
|
171 | + */ |
|
172 | + public function patch() |
|
173 | + { |
|
174 | + return $this->patch; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param int|string $patch |
|
180 | + * @throws InvalidDataTypeException |
|
181 | + */ |
|
182 | + private function setPatch($patch) |
|
183 | + { |
|
184 | + if (! is_int($patch)) { |
|
185 | + throw new InvalidDataTypeException( |
|
186 | + '$patch', |
|
187 | + $patch, |
|
188 | + 'integer' |
|
189 | + ); |
|
190 | + } |
|
191 | + $this->patch = absint($patch); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function release() |
|
199 | + { |
|
200 | + return $this->release; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param string $release |
|
206 | + * @throws InvalidArgumentException |
|
207 | + */ |
|
208 | + private function setRelease($release) |
|
209 | + { |
|
210 | + $valid_release_types = array( |
|
211 | + Version::RELEASE_TYPE_RC, |
|
212 | + Version::RELEASE_TYPE_BETA, |
|
213 | + Version::RELEASE_TYPE_DECAF, |
|
214 | + Version::RELEASE_TYPE_PROD, |
|
215 | + ); |
|
216 | + if (! in_array($release, $valid_release_types, true)) { |
|
217 | + throw new InvalidArgumentException( |
|
218 | + sprintf( |
|
219 | + esc_html__( |
|
220 | + '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
221 | + 'event_espresso' |
|
222 | + ), |
|
223 | + $release, |
|
224 | + implode(', ', $valid_release_types) |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + $this->release = $release; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @return int |
|
234 | + */ |
|
235 | + public function build() |
|
236 | + { |
|
237 | + return $this->build; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param int|string $build |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + */ |
|
245 | + private function setBuild($build) |
|
246 | + { |
|
247 | + if (! is_int($build)) { |
|
248 | + throw new InvalidDataTypeException( |
|
249 | + '$build', |
|
250 | + $build, |
|
251 | + 'integer' |
|
252 | + ); |
|
253 | + } |
|
254 | + $this->build = absint($build); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @param Version $other_version |
|
260 | + * @return int |
|
261 | + */ |
|
262 | + public function compare(Version $other_version) |
|
263 | + { |
|
264 | + return version_compare((string) $this, (string) $other_version); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param Version $other_version |
|
270 | + * @return bool |
|
271 | + */ |
|
272 | + public function equals(Version $other_version) |
|
273 | + { |
|
274 | + return version_compare((string) $this, (string) $other_version, '=='); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * @param Version $other_version |
|
280 | + * @return bool |
|
281 | + */ |
|
282 | + public function newerThan(Version $other_version) |
|
283 | + { |
|
284 | + return version_compare((string) $this, (string) $other_version, '>'); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @param Version $other_version |
|
290 | + * @return bool |
|
291 | + */ |
|
292 | + public function olderThan(Version $other_version) |
|
293 | + { |
|
294 | + return version_compare((string) $this, (string) $other_version, '<'); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function __toString() |
|
302 | + { |
|
303 | + $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
304 | + if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
305 | + $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
306 | + } |
|
307 | + return $version_string; |
|
308 | + } |
|
309 | 309 | } |