@@ -12,18 +12,18 @@ |
||
| 12 | 12 | interface CapCheckInterface |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @return string |
|
| 17 | - */ |
|
| 18 | - public function capability(); |
|
| 15 | + /** |
|
| 16 | + * @return string |
|
| 17 | + */ |
|
| 18 | + public function capability(); |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function context(); |
|
| 20 | + /** |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function context(); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return int|string |
|
| 27 | - */ |
|
| 28 | - public function ID(); |
|
| 25 | + /** |
|
| 26 | + * @return int|string |
|
| 27 | + */ |
|
| 28 | + public function ID(); |
|
| 29 | 29 | } |
@@ -15,66 +15,66 @@ |
||
| 15 | 15 | class CapCheck implements CapCheckInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var string|array $capability |
|
| 20 | - */ |
|
| 21 | - private $capability; |
|
| 18 | + /** |
|
| 19 | + * @var string|array $capability |
|
| 20 | + */ |
|
| 21 | + private $capability; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string $context |
|
| 25 | - */ |
|
| 26 | - private $context; |
|
| 23 | + /** |
|
| 24 | + * @var string $context |
|
| 25 | + */ |
|
| 26 | + private $context; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var int|string $ID |
|
| 30 | - */ |
|
| 31 | - private $ID; |
|
| 28 | + /** |
|
| 29 | + * @var int|string $ID |
|
| 30 | + */ |
|
| 31 | + private $ID; |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string|array $capability - the capability to be checked, like: 'ee_edit_registrations', |
|
| 36 | - * or an array of capability strings |
|
| 37 | - * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
| 38 | - * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
| 39 | - * @throws InvalidDataTypeException |
|
| 40 | - */ |
|
| 41 | - public function __construct($capability, $context, $ID = 0) |
|
| 42 | - { |
|
| 43 | - if (! (is_string($capability) || is_array($capability))) { |
|
| 44 | - throw new InvalidDataTypeException('$capability', $capability, 'string or array'); |
|
| 45 | - } |
|
| 46 | - if (! is_string($context)) { |
|
| 47 | - throw new InvalidDataTypeException('$context', $context, 'string'); |
|
| 48 | - } |
|
| 49 | - $this->capability = $capability; |
|
| 50 | - $this->context = strtolower(str_replace(' ', '_', $context)); |
|
| 51 | - $this->ID = $ID; |
|
| 52 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string|array $capability - the capability to be checked, like: 'ee_edit_registrations', |
|
| 36 | + * or an array of capability strings |
|
| 37 | + * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
| 38 | + * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
| 39 | + * @throws InvalidDataTypeException |
|
| 40 | + */ |
|
| 41 | + public function __construct($capability, $context, $ID = 0) |
|
| 42 | + { |
|
| 43 | + if (! (is_string($capability) || is_array($capability))) { |
|
| 44 | + throw new InvalidDataTypeException('$capability', $capability, 'string or array'); |
|
| 45 | + } |
|
| 46 | + if (! is_string($context)) { |
|
| 47 | + throw new InvalidDataTypeException('$context', $context, 'string'); |
|
| 48 | + } |
|
| 49 | + $this->capability = $capability; |
|
| 50 | + $this->context = strtolower(str_replace(' ', '_', $context)); |
|
| 51 | + $this->ID = $ID; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return string|array |
|
| 57 | - */ |
|
| 58 | - public function capability() |
|
| 59 | - { |
|
| 60 | - return $this->capability; |
|
| 61 | - } |
|
| 55 | + /** |
|
| 56 | + * @return string|array |
|
| 57 | + */ |
|
| 58 | + public function capability() |
|
| 59 | + { |
|
| 60 | + return $this->capability; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function context() |
|
| 68 | - { |
|
| 69 | - return $this->context; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function context() |
|
| 68 | + { |
|
| 69 | + return $this->context; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return int|string |
|
| 75 | - */ |
|
| 76 | - public function ID() |
|
| 77 | - { |
|
| 78 | - return $this->ID; |
|
| 79 | - } |
|
| 73 | + /** |
|
| 74 | + * @return int|string |
|
| 75 | + */ |
|
| 76 | + public function ID() |
|
| 77 | + { |
|
| 78 | + return $this->ID; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -40,10 +40,10 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | public function __construct($capability, $context, $ID = 0) |
| 42 | 42 | { |
| 43 | - if (! (is_string($capability) || is_array($capability))) { |
|
| 43 | + if ( ! (is_string($capability) || is_array($capability))) { |
|
| 44 | 44 | throw new InvalidDataTypeException('$capability', $capability, 'string or array'); |
| 45 | 45 | } |
| 46 | - if (! is_string($context)) { |
|
| 46 | + if ( ! is_string($context)) { |
|
| 47 | 47 | throw new InvalidDataTypeException('$context', $context, 'string'); |
| 48 | 48 | } |
| 49 | 49 | $this->capability = $capability; |
@@ -19,19 +19,19 @@ |
||
| 19 | 19 | class EmailAddressFactory implements FactoryInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param string $email_address |
|
| 24 | - * @return EmailAddress |
|
| 25 | - * @throws EmailValidationException |
|
| 26 | - * @throws InvalidDataTypeException |
|
| 27 | - * @throws InvalidInterfaceException |
|
| 28 | - * @throws InvalidArgumentException |
|
| 29 | - */ |
|
| 30 | - public static function create($email_address) |
|
| 31 | - { |
|
| 32 | - return LoaderFactory::getLoader()->getNew( |
|
| 33 | - 'EventEspresso\core\domain\values\EmailAddress', |
|
| 34 | - array($email_address) |
|
| 35 | - ); |
|
| 36 | - } |
|
| 22 | + /** |
|
| 23 | + * @param string $email_address |
|
| 24 | + * @return EmailAddress |
|
| 25 | + * @throws EmailValidationException |
|
| 26 | + * @throws InvalidDataTypeException |
|
| 27 | + * @throws InvalidInterfaceException |
|
| 28 | + * @throws InvalidArgumentException |
|
| 29 | + */ |
|
| 30 | + public static function create($email_address) |
|
| 31 | + { |
|
| 32 | + return LoaderFactory::getLoader()->getNew( |
|
| 33 | + 'EventEspresso\core\domain\values\EmailAddress', |
|
| 34 | + array($email_address) |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -16,41 +16,41 @@ |
||
| 16 | 16 | class CreateTicketLineItemService extends DomainService |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param \EE_Transaction $transaction |
|
| 21 | - * @param \EE_Ticket $ticket |
|
| 22 | - * @param int $quantity |
|
| 23 | - * @return \EE_Line_Item |
|
| 24 | - * @throws \EE_Error |
|
| 25 | - * @throws UnexpectedEntityException |
|
| 26 | - */ |
|
| 27 | - public function create( |
|
| 28 | - \EE_Transaction $transaction, |
|
| 29 | - \EE_Ticket $ticket, |
|
| 30 | - $quantity = 1 |
|
| 31 | - ) { |
|
| 32 | - $total_line_item = $transaction->total_line_item(); |
|
| 33 | - if (! $total_line_item instanceof \EE_Line_Item) { |
|
| 34 | - throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
| 35 | - } |
|
| 36 | - // create new line item for ticket |
|
| 37 | - $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
| 38 | - $total_line_item, |
|
| 39 | - $ticket, |
|
| 40 | - $quantity |
|
| 41 | - ); |
|
| 42 | - if (! $ticket_line_item instanceof \EE_Line_Item) { |
|
| 43 | - throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
| 44 | - } |
|
| 45 | - $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 46 | - // apply any applicable promotions that were initially used during registration to new line items |
|
| 47 | - do_action( |
|
| 48 | - 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
| 49 | - $total_line_item, |
|
| 50 | - $ticket, |
|
| 51 | - $transaction, |
|
| 52 | - $quantity |
|
| 53 | - ); |
|
| 54 | - return $ticket_line_item; |
|
| 55 | - } |
|
| 19 | + /** |
|
| 20 | + * @param \EE_Transaction $transaction |
|
| 21 | + * @param \EE_Ticket $ticket |
|
| 22 | + * @param int $quantity |
|
| 23 | + * @return \EE_Line_Item |
|
| 24 | + * @throws \EE_Error |
|
| 25 | + * @throws UnexpectedEntityException |
|
| 26 | + */ |
|
| 27 | + public function create( |
|
| 28 | + \EE_Transaction $transaction, |
|
| 29 | + \EE_Ticket $ticket, |
|
| 30 | + $quantity = 1 |
|
| 31 | + ) { |
|
| 32 | + $total_line_item = $transaction->total_line_item(); |
|
| 33 | + if (! $total_line_item instanceof \EE_Line_Item) { |
|
| 34 | + throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
| 35 | + } |
|
| 36 | + // create new line item for ticket |
|
| 37 | + $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
| 38 | + $total_line_item, |
|
| 39 | + $ticket, |
|
| 40 | + $quantity |
|
| 41 | + ); |
|
| 42 | + if (! $ticket_line_item instanceof \EE_Line_Item) { |
|
| 43 | + throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
| 44 | + } |
|
| 45 | + $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 46 | + // apply any applicable promotions that were initially used during registration to new line items |
|
| 47 | + do_action( |
|
| 48 | + 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
| 49 | + $total_line_item, |
|
| 50 | + $ticket, |
|
| 51 | + $transaction, |
|
| 52 | + $quantity |
|
| 53 | + ); |
|
| 54 | + return $ticket_line_item; |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -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()); |
@@ -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 | } |
@@ -16,13 +16,13 @@ |
||
| 16 | 16 | interface RequiresDependencyMapInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param EE_Dependency_Map $dependency_map |
|
| 21 | - */ |
|
| 22 | - public function setDependencyMap($dependency_map); |
|
| 19 | + /** |
|
| 20 | + * @param EE_Dependency_Map $dependency_map |
|
| 21 | + */ |
|
| 22 | + public function setDependencyMap($dependency_map); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return EE_Dependency_Map |
|
| 26 | - */ |
|
| 27 | - public function dependencyMap(); |
|
| 24 | + /** |
|
| 25 | + * @return EE_Dependency_Map |
|
| 26 | + */ |
|
| 27 | + public function dependencyMap(); |
|
| 28 | 28 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | interface RequiresDomainInterface |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param DomainInterface $domain |
|
| 18 | - */ |
|
| 19 | - public function setDomain(DomainInterface $domain); |
|
| 16 | + /** |
|
| 17 | + * @param DomainInterface $domain |
|
| 18 | + */ |
|
| 19 | + public function setDomain(DomainInterface $domain); |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return DomainInterface |
|
| 24 | - */ |
|
| 25 | - public function domain(); |
|
| 22 | + /** |
|
| 23 | + * @return DomainInterface |
|
| 24 | + */ |
|
| 25 | + public function domain(); |
|
| 26 | 26 | } |
@@ -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 | } |
@@ -16,295 +16,295 @@ |
||
| 16 | 16 | class Version |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - const RELEASE_TYPE_RC = 'rc'; |
|
| 20 | - |
|
| 21 | - const RELEASE_TYPE_BETA = 'beta'; |
|
| 22 | - |
|
| 23 | - const RELEASE_TYPE_DECAF = 'decaf'; |
|
| 24 | - |
|
| 25 | - const RELEASE_TYPE_PROD = 'p'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var int $major |
|
| 29 | - */ |
|
| 30 | - private $major; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var int $minor |
|
| 34 | - */ |
|
| 35 | - private $minor; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var int $patch |
|
| 39 | - */ |
|
| 40 | - private $patch; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var string $release |
|
| 44 | - */ |
|
| 45 | - private $release; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var int $build |
|
| 49 | - */ |
|
| 50 | - private $build; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Version constructor. |
|
| 55 | - * |
|
| 56 | - * @param int $major |
|
| 57 | - * @param int $minor |
|
| 58 | - * @param int $patch |
|
| 59 | - * @param string $release |
|
| 60 | - * @param int $build |
|
| 61 | - * @throws InvalidDataTypeException |
|
| 62 | - * @throws InvalidArgumentException |
|
| 63 | - */ |
|
| 64 | - public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
| 65 | - { |
|
| 66 | - $this->setMajor($major); |
|
| 67 | - $this->setMinor($minor); |
|
| 68 | - $this->setPatch($patch); |
|
| 69 | - $this->setRelease($release); |
|
| 70 | - $this->setBuild($build); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $version_string |
|
| 76 | - * @return Version |
|
| 77 | - * @throws InvalidArgumentException |
|
| 78 | - */ |
|
| 79 | - public static function fromString($version_string) |
|
| 80 | - { |
|
| 81 | - // compare incoming version string against the lowest possible valid version |
|
| 82 | - if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
| 83 | - throw new InvalidArgumentException( |
|
| 84 | - sprintf( |
|
| 85 | - esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
| 86 | - $version_string |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - // break apart incoming version string |
|
| 91 | - $version_parts = explode('.', $version_string); |
|
| 92 | - // verify that version string at least contains {major}.{minor}.{patch} |
|
| 93 | - if (count($version_parts) < 3) { |
|
| 94 | - throw new InvalidArgumentException( |
|
| 95 | - sprintf( |
|
| 96 | - esc_html__( |
|
| 97 | - 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
| 98 | - 'event_espresso' |
|
| 99 | - ), |
|
| 100 | - $version_string |
|
| 101 | - ) |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - // add defaults for missing pieces |
|
| 105 | - $version_parts += array(0,0,0,'p',0); |
|
| 106 | - // reassign to individual variables |
|
| 107 | - list($major, $minor, $patch, $release, $build) = $version_parts; |
|
| 108 | - return new Version( |
|
| 109 | - (int) $major, |
|
| 110 | - (int) $minor, |
|
| 111 | - (int) $patch, |
|
| 112 | - $release, |
|
| 113 | - (int) $build |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return int |
|
| 120 | - */ |
|
| 121 | - public function major() |
|
| 122 | - { |
|
| 123 | - return $this->major; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param int|string $major |
|
| 129 | - * @throws InvalidDataTypeException |
|
| 130 | - */ |
|
| 131 | - private function setMajor($major) |
|
| 132 | - { |
|
| 133 | - if (! is_int($major)) { |
|
| 134 | - throw new InvalidDataTypeException( |
|
| 135 | - '$major', |
|
| 136 | - $major, |
|
| 137 | - 'integer' |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - $this->major = absint($major); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return int |
|
| 146 | - */ |
|
| 147 | - public function minor() |
|
| 148 | - { |
|
| 149 | - return $this->minor; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param int|string $minor |
|
| 155 | - * @throws InvalidDataTypeException |
|
| 156 | - */ |
|
| 157 | - private function setMinor($minor) |
|
| 158 | - { |
|
| 159 | - if (! is_int($minor)) { |
|
| 160 | - throw new InvalidDataTypeException( |
|
| 161 | - '$minor', |
|
| 162 | - $minor, |
|
| 163 | - 'integer' |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - $this->minor = absint($minor); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return int |
|
| 172 | - */ |
|
| 173 | - public function patch() |
|
| 174 | - { |
|
| 175 | - return $this->patch; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param int|string $patch |
|
| 181 | - * @throws InvalidDataTypeException |
|
| 182 | - */ |
|
| 183 | - private function setPatch($patch) |
|
| 184 | - { |
|
| 185 | - if (! is_int($patch)) { |
|
| 186 | - throw new InvalidDataTypeException( |
|
| 187 | - '$patch', |
|
| 188 | - $patch, |
|
| 189 | - 'integer' |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - $this->patch = absint($patch); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function release() |
|
| 200 | - { |
|
| 201 | - return $this->release; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param string $release |
|
| 207 | - * @throws InvalidArgumentException |
|
| 208 | - */ |
|
| 209 | - private function setRelease($release) |
|
| 210 | - { |
|
| 211 | - $valid_release_types = array( |
|
| 212 | - Version::RELEASE_TYPE_RC, |
|
| 213 | - Version::RELEASE_TYPE_BETA, |
|
| 214 | - Version::RELEASE_TYPE_DECAF, |
|
| 215 | - Version::RELEASE_TYPE_PROD, |
|
| 216 | - ); |
|
| 217 | - if (! in_array($release, $valid_release_types, true)) { |
|
| 218 | - throw new InvalidArgumentException( |
|
| 219 | - sprintf( |
|
| 220 | - esc_html__( |
|
| 221 | - '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
| 222 | - 'event_espresso' |
|
| 223 | - ), |
|
| 224 | - $release, |
|
| 225 | - implode(', ', $valid_release_types) |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - $this->release = $release; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return int |
|
| 235 | - */ |
|
| 236 | - public function build() |
|
| 237 | - { |
|
| 238 | - return $this->build; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param int|string $build |
|
| 244 | - * @throws InvalidDataTypeException |
|
| 245 | - */ |
|
| 246 | - private function setBuild($build) |
|
| 247 | - { |
|
| 248 | - if (! is_int($build)) { |
|
| 249 | - throw new InvalidDataTypeException( |
|
| 250 | - '$build', |
|
| 251 | - $build, |
|
| 252 | - 'integer' |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - $this->build = absint($build); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @param Version $other_version |
|
| 261 | - * @return int |
|
| 262 | - */ |
|
| 263 | - public function compare(Version $other_version) |
|
| 264 | - { |
|
| 265 | - return version_compare((string) $this, (string) $other_version); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param Version $other_version |
|
| 271 | - * @return bool |
|
| 272 | - */ |
|
| 273 | - public function equals(Version $other_version) |
|
| 274 | - { |
|
| 275 | - return version_compare((string) $this, (string) $other_version, '=='); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param Version $other_version |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function newerThan(Version $other_version) |
|
| 284 | - { |
|
| 285 | - return version_compare((string) $this, (string) $other_version, '>'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param Version $other_version |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function olderThan(Version $other_version) |
|
| 294 | - { |
|
| 295 | - return version_compare((string) $this, (string) $other_version, '<'); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - public function __toString() |
|
| 303 | - { |
|
| 304 | - $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
| 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); |
|
| 307 | - } |
|
| 308 | - return $version_string; |
|
| 309 | - } |
|
| 19 | + const RELEASE_TYPE_RC = 'rc'; |
|
| 20 | + |
|
| 21 | + const RELEASE_TYPE_BETA = 'beta'; |
|
| 22 | + |
|
| 23 | + const RELEASE_TYPE_DECAF = 'decaf'; |
|
| 24 | + |
|
| 25 | + const RELEASE_TYPE_PROD = 'p'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var int $major |
|
| 29 | + */ |
|
| 30 | + private $major; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var int $minor |
|
| 34 | + */ |
|
| 35 | + private $minor; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var int $patch |
|
| 39 | + */ |
|
| 40 | + private $patch; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var string $release |
|
| 44 | + */ |
|
| 45 | + private $release; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var int $build |
|
| 49 | + */ |
|
| 50 | + private $build; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Version constructor. |
|
| 55 | + * |
|
| 56 | + * @param int $major |
|
| 57 | + * @param int $minor |
|
| 58 | + * @param int $patch |
|
| 59 | + * @param string $release |
|
| 60 | + * @param int $build |
|
| 61 | + * @throws InvalidDataTypeException |
|
| 62 | + * @throws InvalidArgumentException |
|
| 63 | + */ |
|
| 64 | + public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
| 65 | + { |
|
| 66 | + $this->setMajor($major); |
|
| 67 | + $this->setMinor($minor); |
|
| 68 | + $this->setPatch($patch); |
|
| 69 | + $this->setRelease($release); |
|
| 70 | + $this->setBuild($build); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $version_string |
|
| 76 | + * @return Version |
|
| 77 | + * @throws InvalidArgumentException |
|
| 78 | + */ |
|
| 79 | + public static function fromString($version_string) |
|
| 80 | + { |
|
| 81 | + // compare incoming version string against the lowest possible valid version |
|
| 82 | + if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
| 83 | + throw new InvalidArgumentException( |
|
| 84 | + sprintf( |
|
| 85 | + esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
| 86 | + $version_string |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + // break apart incoming version string |
|
| 91 | + $version_parts = explode('.', $version_string); |
|
| 92 | + // verify that version string at least contains {major}.{minor}.{patch} |
|
| 93 | + if (count($version_parts) < 3) { |
|
| 94 | + throw new InvalidArgumentException( |
|
| 95 | + sprintf( |
|
| 96 | + esc_html__( |
|
| 97 | + 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
| 98 | + 'event_espresso' |
|
| 99 | + ), |
|
| 100 | + $version_string |
|
| 101 | + ) |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + // add defaults for missing pieces |
|
| 105 | + $version_parts += array(0,0,0,'p',0); |
|
| 106 | + // reassign to individual variables |
|
| 107 | + list($major, $minor, $patch, $release, $build) = $version_parts; |
|
| 108 | + return new Version( |
|
| 109 | + (int) $major, |
|
| 110 | + (int) $minor, |
|
| 111 | + (int) $patch, |
|
| 112 | + $release, |
|
| 113 | + (int) $build |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return int |
|
| 120 | + */ |
|
| 121 | + public function major() |
|
| 122 | + { |
|
| 123 | + return $this->major; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param int|string $major |
|
| 129 | + * @throws InvalidDataTypeException |
|
| 130 | + */ |
|
| 131 | + private function setMajor($major) |
|
| 132 | + { |
|
| 133 | + if (! is_int($major)) { |
|
| 134 | + throw new InvalidDataTypeException( |
|
| 135 | + '$major', |
|
| 136 | + $major, |
|
| 137 | + 'integer' |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + $this->major = absint($major); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return int |
|
| 146 | + */ |
|
| 147 | + public function minor() |
|
| 148 | + { |
|
| 149 | + return $this->minor; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param int|string $minor |
|
| 155 | + * @throws InvalidDataTypeException |
|
| 156 | + */ |
|
| 157 | + private function setMinor($minor) |
|
| 158 | + { |
|
| 159 | + if (! is_int($minor)) { |
|
| 160 | + throw new InvalidDataTypeException( |
|
| 161 | + '$minor', |
|
| 162 | + $minor, |
|
| 163 | + 'integer' |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + $this->minor = absint($minor); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return int |
|
| 172 | + */ |
|
| 173 | + public function patch() |
|
| 174 | + { |
|
| 175 | + return $this->patch; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param int|string $patch |
|
| 181 | + * @throws InvalidDataTypeException |
|
| 182 | + */ |
|
| 183 | + private function setPatch($patch) |
|
| 184 | + { |
|
| 185 | + if (! is_int($patch)) { |
|
| 186 | + throw new InvalidDataTypeException( |
|
| 187 | + '$patch', |
|
| 188 | + $patch, |
|
| 189 | + 'integer' |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + $this->patch = absint($patch); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function release() |
|
| 200 | + { |
|
| 201 | + return $this->release; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param string $release |
|
| 207 | + * @throws InvalidArgumentException |
|
| 208 | + */ |
|
| 209 | + private function setRelease($release) |
|
| 210 | + { |
|
| 211 | + $valid_release_types = array( |
|
| 212 | + Version::RELEASE_TYPE_RC, |
|
| 213 | + Version::RELEASE_TYPE_BETA, |
|
| 214 | + Version::RELEASE_TYPE_DECAF, |
|
| 215 | + Version::RELEASE_TYPE_PROD, |
|
| 216 | + ); |
|
| 217 | + if (! in_array($release, $valid_release_types, true)) { |
|
| 218 | + throw new InvalidArgumentException( |
|
| 219 | + sprintf( |
|
| 220 | + esc_html__( |
|
| 221 | + '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
| 222 | + 'event_espresso' |
|
| 223 | + ), |
|
| 224 | + $release, |
|
| 225 | + implode(', ', $valid_release_types) |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + $this->release = $release; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function build() |
|
| 237 | + { |
|
| 238 | + return $this->build; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param int|string $build |
|
| 244 | + * @throws InvalidDataTypeException |
|
| 245 | + */ |
|
| 246 | + private function setBuild($build) |
|
| 247 | + { |
|
| 248 | + if (! is_int($build)) { |
|
| 249 | + throw new InvalidDataTypeException( |
|
| 250 | + '$build', |
|
| 251 | + $build, |
|
| 252 | + 'integer' |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + $this->build = absint($build); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @param Version $other_version |
|
| 261 | + * @return int |
|
| 262 | + */ |
|
| 263 | + public function compare(Version $other_version) |
|
| 264 | + { |
|
| 265 | + return version_compare((string) $this, (string) $other_version); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param Version $other_version |
|
| 271 | + * @return bool |
|
| 272 | + */ |
|
| 273 | + public function equals(Version $other_version) |
|
| 274 | + { |
|
| 275 | + return version_compare((string) $this, (string) $other_version, '=='); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param Version $other_version |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function newerThan(Version $other_version) |
|
| 284 | + { |
|
| 285 | + return version_compare((string) $this, (string) $other_version, '>'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param Version $other_version |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function olderThan(Version $other_version) |
|
| 294 | + { |
|
| 295 | + return version_compare((string) $this, (string) $other_version, '<'); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + public function __toString() |
|
| 303 | + { |
|
| 304 | + $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
| 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); |
|
| 307 | + } |
|
| 308 | + return $version_string; |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -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 | } |