@@ -16,48 +16,48 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var \EE_Registration $target_registration |
|
| 21 | - */ |
|
| 22 | - private $target_registration; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var \EE_Registration $registration_to_copy |
|
| 27 | - */ |
|
| 28 | - private $registration_to_copy; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * CopyRegistrationDetailsCommand constructor. |
|
| 33 | - * |
|
| 34 | - * @param \EE_Registration $target_registration |
|
| 35 | - * @param \EE_Registration $registration_to_copy |
|
| 36 | - * v |
|
| 37 | - */ |
|
| 38 | - public function __construct( |
|
| 39 | - \EE_Registration $target_registration, |
|
| 40 | - \EE_Registration $registration_to_copy |
|
| 41 | - ) { |
|
| 42 | - $this->target_registration = $target_registration; |
|
| 43 | - $this->registration_to_copy = $registration_to_copy; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @return \EE_Registration |
|
| 49 | - */ |
|
| 50 | - public function targetRegistration() |
|
| 51 | - { |
|
| 52 | - return $this->target_registration; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return \EE_Registration |
|
| 58 | - */ |
|
| 59 | - public function registrationToCopy() |
|
| 60 | - { |
|
| 61 | - return $this->registration_to_copy; |
|
| 62 | - } |
|
| 19 | + /** |
|
| 20 | + * @var \EE_Registration $target_registration |
|
| 21 | + */ |
|
| 22 | + private $target_registration; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var \EE_Registration $registration_to_copy |
|
| 27 | + */ |
|
| 28 | + private $registration_to_copy; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * CopyRegistrationDetailsCommand constructor. |
|
| 33 | + * |
|
| 34 | + * @param \EE_Registration $target_registration |
|
| 35 | + * @param \EE_Registration $registration_to_copy |
|
| 36 | + * v |
|
| 37 | + */ |
|
| 38 | + public function __construct( |
|
| 39 | + \EE_Registration $target_registration, |
|
| 40 | + \EE_Registration $registration_to_copy |
|
| 41 | + ) { |
|
| 42 | + $this->target_registration = $target_registration; |
|
| 43 | + $this->registration_to_copy = $registration_to_copy; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @return \EE_Registration |
|
| 49 | + */ |
|
| 50 | + public function targetRegistration() |
|
| 51 | + { |
|
| 52 | + return $this->target_registration; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return \EE_Registration |
|
| 58 | + */ |
|
| 59 | + public function registrationToCopy() |
|
| 60 | + { |
|
| 61 | + return $this->registration_to_copy; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -24,151 +24,151 @@ |
||
| 24 | 24 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var EE_Transaction $transaction |
|
| 29 | - */ |
|
| 30 | - private $transaction; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var EE_Ticket $ticket |
|
| 34 | - */ |
|
| 35 | - private $ticket; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var EE_Line_Item $ticket_line_item |
|
| 39 | - */ |
|
| 40 | - private $ticket_line_item; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var int $reg_count |
|
| 44 | - */ |
|
| 45 | - private $reg_count; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var int $reg_group_size |
|
| 49 | - */ |
|
| 50 | - private $reg_group_size; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var string $reg_status |
|
| 54 | - */ |
|
| 55 | - private $reg_status; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EE_Registration $registration |
|
| 59 | - */ |
|
| 60 | - protected $registration; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * CreateRegistrationCommand constructor. |
|
| 65 | - * |
|
| 66 | - * @param EE_Transaction $transaction |
|
| 67 | - * @param EE_Line_Item $ticket_line_item |
|
| 68 | - * @param int $reg_count |
|
| 69 | - * @param int $reg_group_size |
|
| 70 | - * @param string $reg_status |
|
| 71 | - * @throws InvalidEntityException |
|
| 72 | - */ |
|
| 73 | - public function __construct( |
|
| 74 | - EE_Transaction $transaction, |
|
| 75 | - EE_Line_Item $ticket_line_item, |
|
| 76 | - $reg_count = 1, |
|
| 77 | - $reg_group_size = 0, |
|
| 78 | - $reg_status = EEM_Registration::status_id_incomplete |
|
| 79 | - ) { |
|
| 80 | - // grab the related ticket object for this line_item |
|
| 81 | - $this->ticket = $ticket_line_item->ticket(); |
|
| 82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
| 83 | - throw new InvalidEntityException( |
|
| 84 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
| 85 | - 'EE_Ticket', |
|
| 86 | - sprintf( |
|
| 87 | - __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 88 | - $ticket_line_item->ID() |
|
| 89 | - ) |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - $this->transaction = $transaction; |
|
| 93 | - $this->ticket_line_item = $ticket_line_item; |
|
| 94 | - $this->reg_count = absint($reg_count); |
|
| 95 | - $this->reg_group_size = absint($reg_group_size); |
|
| 96 | - $this->reg_status = $reg_status; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
| 102 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 103 | - */ |
|
| 104 | - public function getCapCheck() |
|
| 105 | - { |
|
| 106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
| 107 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
| 108 | - } |
|
| 109 | - return $this->cap_check; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return EE_Transaction |
|
| 115 | - */ |
|
| 116 | - public function transaction() |
|
| 117 | - { |
|
| 118 | - return $this->transaction; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return EE_Ticket |
|
| 124 | - */ |
|
| 125 | - public function ticket() |
|
| 126 | - { |
|
| 127 | - return $this->ticket; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return EE_Line_Item |
|
| 133 | - */ |
|
| 134 | - public function ticketLineItem() |
|
| 135 | - { |
|
| 136 | - return $this->ticket_line_item; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return int |
|
| 142 | - */ |
|
| 143 | - public function regCount() |
|
| 144 | - { |
|
| 145 | - return $this->reg_count; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return int |
|
| 151 | - */ |
|
| 152 | - public function regGroupSize() |
|
| 153 | - { |
|
| 154 | - return $this->reg_group_size; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function regStatus() |
|
| 162 | - { |
|
| 163 | - return $this->reg_status; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @return EE_Registration |
|
| 169 | - */ |
|
| 170 | - public function registration() |
|
| 171 | - { |
|
| 172 | - return $this->registration; |
|
| 173 | - } |
|
| 27 | + /** |
|
| 28 | + * @var EE_Transaction $transaction |
|
| 29 | + */ |
|
| 30 | + private $transaction; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var EE_Ticket $ticket |
|
| 34 | + */ |
|
| 35 | + private $ticket; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var EE_Line_Item $ticket_line_item |
|
| 39 | + */ |
|
| 40 | + private $ticket_line_item; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var int $reg_count |
|
| 44 | + */ |
|
| 45 | + private $reg_count; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var int $reg_group_size |
|
| 49 | + */ |
|
| 50 | + private $reg_group_size; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var string $reg_status |
|
| 54 | + */ |
|
| 55 | + private $reg_status; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EE_Registration $registration |
|
| 59 | + */ |
|
| 60 | + protected $registration; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * CreateRegistrationCommand constructor. |
|
| 65 | + * |
|
| 66 | + * @param EE_Transaction $transaction |
|
| 67 | + * @param EE_Line_Item $ticket_line_item |
|
| 68 | + * @param int $reg_count |
|
| 69 | + * @param int $reg_group_size |
|
| 70 | + * @param string $reg_status |
|
| 71 | + * @throws InvalidEntityException |
|
| 72 | + */ |
|
| 73 | + public function __construct( |
|
| 74 | + EE_Transaction $transaction, |
|
| 75 | + EE_Line_Item $ticket_line_item, |
|
| 76 | + $reg_count = 1, |
|
| 77 | + $reg_group_size = 0, |
|
| 78 | + $reg_status = EEM_Registration::status_id_incomplete |
|
| 79 | + ) { |
|
| 80 | + // grab the related ticket object for this line_item |
|
| 81 | + $this->ticket = $ticket_line_item->ticket(); |
|
| 82 | + if (! $this->ticket instanceof EE_Ticket) { |
|
| 83 | + throw new InvalidEntityException( |
|
| 84 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
| 85 | + 'EE_Ticket', |
|
| 86 | + sprintf( |
|
| 87 | + __('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 88 | + $ticket_line_item->ID() |
|
| 89 | + ) |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + $this->transaction = $transaction; |
|
| 93 | + $this->ticket_line_item = $ticket_line_item; |
|
| 94 | + $this->reg_count = absint($reg_count); |
|
| 95 | + $this->reg_group_size = absint($reg_group_size); |
|
| 96 | + $this->reg_status = $reg_status; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
|
| 102 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 103 | + */ |
|
| 104 | + public function getCapCheck() |
|
| 105 | + { |
|
| 106 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
| 107 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
| 108 | + } |
|
| 109 | + return $this->cap_check; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return EE_Transaction |
|
| 115 | + */ |
|
| 116 | + public function transaction() |
|
| 117 | + { |
|
| 118 | + return $this->transaction; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return EE_Ticket |
|
| 124 | + */ |
|
| 125 | + public function ticket() |
|
| 126 | + { |
|
| 127 | + return $this->ticket; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return EE_Line_Item |
|
| 133 | + */ |
|
| 134 | + public function ticketLineItem() |
|
| 135 | + { |
|
| 136 | + return $this->ticket_line_item; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return int |
|
| 142 | + */ |
|
| 143 | + public function regCount() |
|
| 144 | + { |
|
| 145 | + return $this->reg_count; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return int |
|
| 151 | + */ |
|
| 152 | + public function regGroupSize() |
|
| 153 | + { |
|
| 154 | + return $this->reg_group_size; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function regStatus() |
|
| 162 | + { |
|
| 163 | + return $this->reg_status; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @return EE_Registration |
|
| 169 | + */ |
|
| 170 | + public function registration() |
|
| 171 | + { |
|
| 172 | + return $this->registration; |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | ) { |
| 80 | 80 | // grab the related ticket object for this line_item |
| 81 | 81 | $this->ticket = $ticket_line_item->ticket(); |
| 82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
| 82 | + if ( ! $this->ticket instanceof EE_Ticket) { |
|
| 83 | 83 | throw new InvalidEntityException( |
| 84 | 84 | is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
| 85 | 85 | 'EE_Ticket', |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getCapCheck() |
| 105 | 105 | { |
| 106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
| 106 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
| 107 | 107 | return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
| 108 | 108 | } |
| 109 | 109 | return $this->cap_check; |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | class AddActionHook implements CommandBusMiddlewareInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param CommandInterface $command |
|
| 20 | - * @param Closure $next |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - public function handle(CommandInterface $command, Closure $next) |
|
| 24 | - { |
|
| 25 | - do_action( |
|
| 26 | - 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__before', |
|
| 27 | - $command |
|
| 28 | - ); |
|
| 29 | - $results = $next($command); |
|
| 30 | - do_action( |
|
| 31 | - 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__after', |
|
| 32 | - $command |
|
| 33 | - ); |
|
| 34 | - return $results; |
|
| 35 | - } |
|
| 18 | + /** |
|
| 19 | + * @param CommandInterface $command |
|
| 20 | + * @param Closure $next |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + public function handle(CommandInterface $command, Closure $next) |
|
| 24 | + { |
|
| 25 | + do_action( |
|
| 26 | + 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__before', |
|
| 27 | + $command |
|
| 28 | + ); |
|
| 29 | + $results = $next($command); |
|
| 30 | + do_action( |
|
| 31 | + 'AHEE__EventEspresso_core_services_commands_middleware_AddActionHook__handle__after', |
|
| 32 | + $command |
|
| 33 | + ); |
|
| 34 | + return $results; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -16,35 +16,35 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @access public |
|
| 21 | - * @param mixed $command_bus_middleware_object |
|
| 22 | - * @param string $message |
|
| 23 | - * @param int $code |
|
| 24 | - * @param \Exception $previous |
|
| 25 | - */ |
|
| 26 | - public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null) |
|
| 27 | - { |
|
| 28 | - $command_bus_middleware = is_object($command_bus_middleware_object) |
|
| 29 | - ? get_class($command_bus_middleware_object) |
|
| 30 | - : gettype($command_bus_middleware_object); |
|
| 19 | + /** |
|
| 20 | + * @access public |
|
| 21 | + * @param mixed $command_bus_middleware_object |
|
| 22 | + * @param string $message |
|
| 23 | + * @param int $code |
|
| 24 | + * @param \Exception $previous |
|
| 25 | + */ |
|
| 26 | + public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null) |
|
| 27 | + { |
|
| 28 | + $command_bus_middleware = is_object($command_bus_middleware_object) |
|
| 29 | + ? get_class($command_bus_middleware_object) |
|
| 30 | + : gettype($command_bus_middleware_object); |
|
| 31 | 31 | |
| 32 | - if (empty($message)) { |
|
| 33 | - $message = sprintf( |
|
| 34 | - __( |
|
| 35 | - 'The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ', |
|
| 36 | - 'event_espresso' |
|
| 37 | - ), |
|
| 38 | - $command_bus_middleware |
|
| 39 | - ); |
|
| 40 | - } |
|
| 41 | - parent::__construct( |
|
| 42 | - '$command_bus_middleware', |
|
| 43 | - $command_bus_middleware, |
|
| 44 | - 'CommandBusMiddlewareInterface', |
|
| 45 | - $message, |
|
| 46 | - $code, |
|
| 47 | - $previous |
|
| 48 | - ); |
|
| 49 | - } |
|
| 32 | + if (empty($message)) { |
|
| 33 | + $message = sprintf( |
|
| 34 | + __( |
|
| 35 | + 'The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ', |
|
| 36 | + 'event_espresso' |
|
| 37 | + ), |
|
| 38 | + $command_bus_middleware |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | + parent::__construct( |
|
| 42 | + '$command_bus_middleware', |
|
| 43 | + $command_bus_middleware, |
|
| 44 | + 'CommandBusMiddlewareInterface', |
|
| 45 | + $message, |
|
| 46 | + $code, |
|
| 47 | + $previous |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -24,37 +24,37 @@ |
||
| 24 | 24 | class CapChecker implements CommandBusMiddlewareInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @type CapabilitiesCheckerInterface $capabilities_checker |
|
| 29 | - */ |
|
| 30 | - private $capabilities_checker; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * CapChecker constructor |
|
| 35 | - * |
|
| 36 | - * @param CapabilitiesCheckerInterface $capabilities_checker |
|
| 37 | - */ |
|
| 38 | - public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
| 39 | - { |
|
| 40 | - $this->capabilities_checker = $capabilities_checker; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param CommandInterface $command |
|
| 46 | - * @param Closure $next |
|
| 47 | - * @return mixed |
|
| 48 | - * @throws InvalidClassException |
|
| 49 | - * @throws InsufficientPermissionsException |
|
| 50 | - */ |
|
| 51 | - public function handle(CommandInterface $command, Closure $next) |
|
| 52 | - { |
|
| 53 | - if ($command instanceof CommandRequiresCapCheckInterface) { |
|
| 54 | - $this->capabilities_checker->processCapCheck( |
|
| 55 | - $command->getCapCheck() |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - return $next($command); |
|
| 59 | - } |
|
| 27 | + /** |
|
| 28 | + * @type CapabilitiesCheckerInterface $capabilities_checker |
|
| 29 | + */ |
|
| 30 | + private $capabilities_checker; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * CapChecker constructor |
|
| 35 | + * |
|
| 36 | + * @param CapabilitiesCheckerInterface $capabilities_checker |
|
| 37 | + */ |
|
| 38 | + public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
| 39 | + { |
|
| 40 | + $this->capabilities_checker = $capabilities_checker; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param CommandInterface $command |
|
| 46 | + * @param Closure $next |
|
| 47 | + * @return mixed |
|
| 48 | + * @throws InvalidClassException |
|
| 49 | + * @throws InsufficientPermissionsException |
|
| 50 | + */ |
|
| 51 | + public function handle(CommandInterface $command, Closure $next) |
|
| 52 | + { |
|
| 53 | + if ($command instanceof CommandRequiresCapCheckInterface) { |
|
| 54 | + $this->capabilities_checker->processCapCheck( |
|
| 55 | + $command->getCapCheck() |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + return $next($command); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -16,112 +16,112 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var \EE_Transaction $transaction |
|
| 21 | - */ |
|
| 22 | - private $transaction; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var \EE_Ticket $ticket |
|
| 26 | - */ |
|
| 27 | - private $ticket; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var \EE_Line_Item $ticket_line_item |
|
| 31 | - */ |
|
| 32 | - protected $ticket_line_item; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var int $quantity |
|
| 36 | - */ |
|
| 37 | - protected $quantity; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param \EE_Registration $registration |
|
| 42 | - * @param int $quantity |
|
| 43 | - */ |
|
| 44 | - public static function fromRegistration(\EE_Registration $registration, $quantity = 1) |
|
| 45 | - { |
|
| 46 | - new self( |
|
| 47 | - $registration->transaction(), |
|
| 48 | - $registration->ticket(), |
|
| 49 | - 1, |
|
| 50 | - $registration->ticket_line_item() |
|
| 51 | - ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param \EE_Line_Item $ticket_line_item |
|
| 57 | - * @param int $quantity |
|
| 58 | - */ |
|
| 59 | - public static function fromTicketLineItem( |
|
| 60 | - \EE_Line_Item $ticket_line_item, |
|
| 61 | - $quantity = 1 |
|
| 62 | - ) { |
|
| 63 | - new self( |
|
| 64 | - $ticket_line_item->transaction(), |
|
| 65 | - $ticket_line_item->ticket(), |
|
| 66 | - $quantity, |
|
| 67 | - $ticket_line_item |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * CancelTicketLineItemCommand constructor. |
|
| 74 | - * |
|
| 75 | - * @param \EE_Transaction $transaction |
|
| 76 | - * @param \EE_Ticket $ticket |
|
| 77 | - * @param int $quantity |
|
| 78 | - * @param \EE_Line_Item $ticket_line_item |
|
| 79 | - */ |
|
| 80 | - public function __construct( |
|
| 81 | - \EE_Transaction $transaction, |
|
| 82 | - \EE_Ticket $ticket, |
|
| 83 | - $quantity = 1, |
|
| 84 | - \EE_Line_Item $ticket_line_item = null |
|
| 85 | - ) { |
|
| 86 | - $this->transaction = $transaction; |
|
| 87 | - $this->ticket = $ticket; |
|
| 88 | - $this->quantity = min(1, absint($quantity)); |
|
| 89 | - $this->ticket_line_item = $ticket_line_item; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return \EE_Transaction |
|
| 95 | - */ |
|
| 96 | - public function transaction() |
|
| 97 | - { |
|
| 98 | - return $this->transaction; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return \EE_Ticket |
|
| 104 | - */ |
|
| 105 | - public function ticket() |
|
| 106 | - { |
|
| 107 | - return $this->ticket; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return \EE_Line_Item |
|
| 113 | - */ |
|
| 114 | - public function ticketLineItem() |
|
| 115 | - { |
|
| 116 | - return $this->ticket_line_item; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return int |
|
| 122 | - */ |
|
| 123 | - public function quantity() |
|
| 124 | - { |
|
| 125 | - return $this->quantity; |
|
| 126 | - } |
|
| 19 | + /** |
|
| 20 | + * @var \EE_Transaction $transaction |
|
| 21 | + */ |
|
| 22 | + private $transaction; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var \EE_Ticket $ticket |
|
| 26 | + */ |
|
| 27 | + private $ticket; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var \EE_Line_Item $ticket_line_item |
|
| 31 | + */ |
|
| 32 | + protected $ticket_line_item; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var int $quantity |
|
| 36 | + */ |
|
| 37 | + protected $quantity; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param \EE_Registration $registration |
|
| 42 | + * @param int $quantity |
|
| 43 | + */ |
|
| 44 | + public static function fromRegistration(\EE_Registration $registration, $quantity = 1) |
|
| 45 | + { |
|
| 46 | + new self( |
|
| 47 | + $registration->transaction(), |
|
| 48 | + $registration->ticket(), |
|
| 49 | + 1, |
|
| 50 | + $registration->ticket_line_item() |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param \EE_Line_Item $ticket_line_item |
|
| 57 | + * @param int $quantity |
|
| 58 | + */ |
|
| 59 | + public static function fromTicketLineItem( |
|
| 60 | + \EE_Line_Item $ticket_line_item, |
|
| 61 | + $quantity = 1 |
|
| 62 | + ) { |
|
| 63 | + new self( |
|
| 64 | + $ticket_line_item->transaction(), |
|
| 65 | + $ticket_line_item->ticket(), |
|
| 66 | + $quantity, |
|
| 67 | + $ticket_line_item |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * CancelTicketLineItemCommand constructor. |
|
| 74 | + * |
|
| 75 | + * @param \EE_Transaction $transaction |
|
| 76 | + * @param \EE_Ticket $ticket |
|
| 77 | + * @param int $quantity |
|
| 78 | + * @param \EE_Line_Item $ticket_line_item |
|
| 79 | + */ |
|
| 80 | + public function __construct( |
|
| 81 | + \EE_Transaction $transaction, |
|
| 82 | + \EE_Ticket $ticket, |
|
| 83 | + $quantity = 1, |
|
| 84 | + \EE_Line_Item $ticket_line_item = null |
|
| 85 | + ) { |
|
| 86 | + $this->transaction = $transaction; |
|
| 87 | + $this->ticket = $ticket; |
|
| 88 | + $this->quantity = min(1, absint($quantity)); |
|
| 89 | + $this->ticket_line_item = $ticket_line_item; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return \EE_Transaction |
|
| 95 | + */ |
|
| 96 | + public function transaction() |
|
| 97 | + { |
|
| 98 | + return $this->transaction; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return \EE_Ticket |
|
| 104 | + */ |
|
| 105 | + public function ticket() |
|
| 106 | + { |
|
| 107 | + return $this->ticket; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return \EE_Line_Item |
|
| 113 | + */ |
|
| 114 | + public function ticketLineItem() |
|
| 115 | + { |
|
| 116 | + return $this->ticket_line_item; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return int |
|
| 122 | + */ |
|
| 123 | + public function quantity() |
|
| 124 | + { |
|
| 125 | + return $this->quantity; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -16,77 +16,77 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var \EE_Transaction $transaction |
|
| 21 | - */ |
|
| 22 | - private $transaction; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var \EE_Ticket $ticket |
|
| 26 | - */ |
|
| 27 | - private $ticket; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var int $quantity |
|
| 31 | - */ |
|
| 32 | - private $quantity = 1; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var \EE_Line_Item $ticket_line_item |
|
| 36 | - */ |
|
| 37 | - protected $ticket_line_item; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * CreateTicketLineItemCommand constructor. |
|
| 42 | - * |
|
| 43 | - * @param \EE_Transaction $transaction |
|
| 44 | - * @param \EE_Ticket $ticket |
|
| 45 | - * @param int $quantity |
|
| 46 | - */ |
|
| 47 | - public function __construct( |
|
| 48 | - \EE_Transaction $transaction, |
|
| 49 | - \EE_Ticket $ticket, |
|
| 50 | - $quantity = 1 |
|
| 51 | - ) { |
|
| 52 | - $this->transaction = $transaction; |
|
| 53 | - $this->ticket = $ticket; |
|
| 54 | - $this->quantity = $quantity; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return \EE_Transaction |
|
| 60 | - */ |
|
| 61 | - public function transaction() |
|
| 62 | - { |
|
| 63 | - return $this->transaction; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return \EE_Ticket |
|
| 69 | - */ |
|
| 70 | - public function ticket() |
|
| 71 | - { |
|
| 72 | - return $this->ticket; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return int |
|
| 78 | - */ |
|
| 79 | - public function quantity() |
|
| 80 | - { |
|
| 81 | - return $this->quantity; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return \EE_Line_Item |
|
| 87 | - */ |
|
| 88 | - public function ticketLineItem() |
|
| 89 | - { |
|
| 90 | - return $this->ticket_line_item; |
|
| 91 | - } |
|
| 19 | + /** |
|
| 20 | + * @var \EE_Transaction $transaction |
|
| 21 | + */ |
|
| 22 | + private $transaction; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var \EE_Ticket $ticket |
|
| 26 | + */ |
|
| 27 | + private $ticket; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var int $quantity |
|
| 31 | + */ |
|
| 32 | + private $quantity = 1; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var \EE_Line_Item $ticket_line_item |
|
| 36 | + */ |
|
| 37 | + protected $ticket_line_item; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * CreateTicketLineItemCommand constructor. |
|
| 42 | + * |
|
| 43 | + * @param \EE_Transaction $transaction |
|
| 44 | + * @param \EE_Ticket $ticket |
|
| 45 | + * @param int $quantity |
|
| 46 | + */ |
|
| 47 | + public function __construct( |
|
| 48 | + \EE_Transaction $transaction, |
|
| 49 | + \EE_Ticket $ticket, |
|
| 50 | + $quantity = 1 |
|
| 51 | + ) { |
|
| 52 | + $this->transaction = $transaction; |
|
| 53 | + $this->ticket = $ticket; |
|
| 54 | + $this->quantity = $quantity; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return \EE_Transaction |
|
| 60 | + */ |
|
| 61 | + public function transaction() |
|
| 62 | + { |
|
| 63 | + return $this->transaction; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return \EE_Ticket |
|
| 69 | + */ |
|
| 70 | + public function ticket() |
|
| 71 | + { |
|
| 72 | + return $this->ticket; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return int |
|
| 78 | + */ |
|
| 79 | + public function quantity() |
|
| 80 | + { |
|
| 81 | + return $this->quantity; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return \EE_Line_Item |
|
| 87 | + */ |
|
| 88 | + public function ticketLineItem() |
|
| 89 | + { |
|
| 90 | + return $this->ticket_line_item; |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | protected function setBaseUrl($base_url) |
| 143 | 143 | { |
| 144 | - if (! is_string($base_url)) { |
|
| 144 | + if ( ! is_string($base_url)) { |
|
| 145 | 145 | throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
| 146 | 146 | } |
| 147 | 147 | if (empty($base_url)) { |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
| 174 | 174 | { |
| 175 | - if (! is_string($form_step_url_key)) { |
|
| 175 | + if ( ! is_string($form_step_url_key)) { |
|
| 176 | 176 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
| 177 | 177 | } |
| 178 | 178 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | protected function setDefaultFormStep($default_form_step) |
| 196 | 196 | { |
| 197 | - if (! is_string($default_form_step)) { |
|
| 197 | + if ( ! is_string($default_form_step)) { |
|
| 198 | 198 | throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
| 199 | 199 | } |
| 200 | 200 | $this->default_form_step = $default_form_step; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | protected function setCurrentStepFromRequest() |
| 210 | 210 | { |
| 211 | 211 | $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep()); |
| 212 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
| 212 | + if ( ! $this->form_steps->setCurrent($current_step_slug)) { |
|
| 213 | 213 | throw new InvalidIdentifierException( |
| 214 | 214 | $current_step_slug, |
| 215 | 215 | $this->defaultFormStep(), |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function getCurrentStep() |
| 233 | 233 | { |
| 234 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
| 234 | + if ( ! $this->form_steps->current() instanceof SequentialStepForm) { |
|
| 235 | 235 | throw new InvalidFormHandlerException($this->form_steps->current()); |
| 236 | 236 | } |
| 237 | 237 | return $this->form_steps->current(); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function formAction() |
| 246 | 246 | { |
| 247 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
| 247 | + if ( ! is_string($this->form_action) || empty($this->form_action)) { |
|
| 248 | 248 | $this->form_action = $this->baseUrl(); |
| 249 | 249 | } |
| 250 | 250 | return $this->form_action; |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function setFormAction($form_action) |
| 259 | 259 | { |
| 260 | - if (! is_string($form_action)) { |
|
| 260 | + if ( ! is_string($form_action)) { |
|
| 261 | 261 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
| 262 | 262 | } |
| 263 | 263 | $this->form_action = $form_action; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | public function addFormActionArgs($form_action_args = array()) |
| 273 | 273 | { |
| 274 | - if (! is_array($form_action_args)) { |
|
| 274 | + if ( ! is_array($form_action_args)) { |
|
| 275 | 275 | throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
| 276 | 276 | } |
| 277 | 277 | $form_action_args = ! empty($form_action_args) |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | protected function getProgressStepsCollection() |
| 337 | 337 | { |
| 338 | 338 | static $collection = null; |
| 339 | - if (! $collection instanceof ProgressStepCollection) { |
|
| 339 | + if ( ! $collection instanceof ProgressStepCollection) { |
|
| 340 | 340 | $collection = new ProgressStepCollection(); |
| 341 | 341 | } |
| 342 | 342 | return $collection; |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | /** @var SequentialStepForm $form_step */ |
| 359 | 359 | foreach ($this->form_steps as $form_step) { |
| 360 | 360 | // is this step active ? |
| 361 | - if (! $form_step->initialize()) { |
|
| 361 | + if ( ! $form_step->initialize()) { |
|
| 362 | 362 | continue; |
| 363 | 363 | } |
| 364 | 364 | $progress_steps_collection->add( |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | { |
| 428 | 428 | $form_step = $this->buildCurrentStepForm(); |
| 429 | 429 | // no displayable content ? then skip straight to processing |
| 430 | - if (! $form_step->displayable()) { |
|
| 430 | + if ( ! $form_step->displayable()) { |
|
| 431 | 431 | $this->addFormActionArgs(); |
| 432 | 432 | $form_step->setFormAction($this->formAction()); |
| 433 | 433 | wp_safe_redirect($form_step->formAction()); |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | public function displayProgressSteps($return_as_string = true) |
| 504 | 504 | { |
| 505 | 505 | $form_step = $this->getCurrentStep(); |
| 506 | - if (! $form_step->displayable()) { |
|
| 506 | + if ( ! $form_step->displayable()) { |
|
| 507 | 507 | return ''; |
| 508 | 508 | } |
| 509 | 509 | $progress_steps = apply_filters( |
@@ -29,585 +29,585 @@ |
||
| 29 | 29 | abstract class SequentialStepFormManager |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * a simplified URL with no form related parameters |
|
| 34 | - * that will be used to build the form's redirect URLs |
|
| 35 | - * |
|
| 36 | - * @var string $base_url |
|
| 37 | - */ |
|
| 38 | - private $base_url = ''; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * the key used for the URL param that denotes the current form step |
|
| 42 | - * defaults to 'ee-form-step' |
|
| 43 | - * |
|
| 44 | - * @var string $form_step_url_key |
|
| 45 | - */ |
|
| 46 | - private $form_step_url_key = ''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var string $default_form_step |
|
| 50 | - */ |
|
| 51 | - private $default_form_step = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var string $form_action |
|
| 55 | - */ |
|
| 56 | - private $form_action; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * value of one of the string constant above |
|
| 60 | - * |
|
| 61 | - * @var string $form_config |
|
| 62 | - */ |
|
| 63 | - private $form_config; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var string $progress_step_style |
|
| 67 | - */ |
|
| 68 | - private $progress_step_style = ''; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var EE_Request $request |
|
| 72 | - */ |
|
| 73 | - private $request; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var Collection $form_steps |
|
| 77 | - */ |
|
| 78 | - protected $form_steps; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var ProgressStepManager $progress_step_manager |
|
| 82 | - */ |
|
| 83 | - protected $progress_step_manager; |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return Collection|null |
|
| 88 | - */ |
|
| 89 | - abstract protected function getFormStepsCollection(); |
|
| 90 | - |
|
| 91 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 92 | - /** |
|
| 93 | - * StepsManager constructor |
|
| 94 | - * |
|
| 95 | - * @param string $base_url |
|
| 96 | - * @param string $default_form_step |
|
| 97 | - * @param string $form_action |
|
| 98 | - * @param string $form_config |
|
| 99 | - * @param EE_Request $request |
|
| 100 | - * @param string $progress_step_style |
|
| 101 | - * @throws InvalidDataTypeException |
|
| 102 | - * @throws InvalidArgumentException |
|
| 103 | - */ |
|
| 104 | - public function __construct( |
|
| 105 | - $base_url, |
|
| 106 | - $default_form_step, |
|
| 107 | - $form_action = '', |
|
| 108 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 109 | - $progress_step_style = 'number_bubbles', |
|
| 110 | - EE_Request $request |
|
| 111 | - ) { |
|
| 112 | - $this->setBaseUrl($base_url); |
|
| 113 | - $this->setDefaultFormStep($default_form_step); |
|
| 114 | - $this->setFormAction($form_action); |
|
| 115 | - $this->setFormConfig($form_config); |
|
| 116 | - $this->setProgressStepStyle($progress_step_style); |
|
| 117 | - $this->request = $request; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return string |
|
| 123 | - * @throws InvalidFormHandlerException |
|
| 124 | - */ |
|
| 125 | - public function baseUrl() |
|
| 126 | - { |
|
| 127 | - if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
| 128 | - add_query_arg( |
|
| 129 | - array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
| 130 | - $this->base_url |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - return $this->base_url; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param string $base_url |
|
| 139 | - * @throws InvalidDataTypeException |
|
| 140 | - * @throws InvalidArgumentException |
|
| 141 | - */ |
|
| 142 | - protected function setBaseUrl($base_url) |
|
| 143 | - { |
|
| 144 | - if (! is_string($base_url)) { |
|
| 145 | - throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
| 146 | - } |
|
| 147 | - if (empty($base_url)) { |
|
| 148 | - throw new InvalidArgumentException( |
|
| 149 | - esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - $this->base_url = $base_url; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return string |
|
| 158 | - * @throws InvalidDataTypeException |
|
| 159 | - */ |
|
| 160 | - public function formStepUrlKey() |
|
| 161 | - { |
|
| 162 | - if (empty($this->form_step_url_key)) { |
|
| 163 | - $this->setFormStepUrlKey(); |
|
| 164 | - } |
|
| 165 | - return $this->form_step_url_key; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $form_step_url_key |
|
| 171 | - * @throws InvalidDataTypeException |
|
| 172 | - */ |
|
| 173 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
| 174 | - { |
|
| 175 | - if (! is_string($form_step_url_key)) { |
|
| 176 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
| 177 | - } |
|
| 178 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @return string |
|
| 184 | - */ |
|
| 185 | - public function defaultFormStep() |
|
| 186 | - { |
|
| 187 | - return $this->default_form_step; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param $default_form_step |
|
| 193 | - * @throws InvalidDataTypeException |
|
| 194 | - */ |
|
| 195 | - protected function setDefaultFormStep($default_form_step) |
|
| 196 | - { |
|
| 197 | - if (! is_string($default_form_step)) { |
|
| 198 | - throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
| 199 | - } |
|
| 200 | - $this->default_form_step = $default_form_step; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @return void |
|
| 206 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 207 | - * @throws InvalidDataTypeException |
|
| 208 | - */ |
|
| 209 | - protected function setCurrentStepFromRequest() |
|
| 210 | - { |
|
| 211 | - $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep()); |
|
| 212 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
| 213 | - throw new InvalidIdentifierException( |
|
| 214 | - $current_step_slug, |
|
| 215 | - $this->defaultFormStep(), |
|
| 216 | - $message = sprintf( |
|
| 217 | - esc_html__( |
|
| 218 | - 'The "%1$s" form step could not be set.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - $current_step_slug |
|
| 222 | - ) |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return object|SequentialStepFormInterface |
|
| 230 | - * @throws InvalidFormHandlerException |
|
| 231 | - */ |
|
| 232 | - public function getCurrentStep() |
|
| 233 | - { |
|
| 234 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
| 235 | - throw new InvalidFormHandlerException($this->form_steps->current()); |
|
| 236 | - } |
|
| 237 | - return $this->form_steps->current(); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @return string |
|
| 243 | - * @throws InvalidFormHandlerException |
|
| 244 | - */ |
|
| 245 | - public function formAction() |
|
| 246 | - { |
|
| 247 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
| 248 | - $this->form_action = $this->baseUrl(); |
|
| 249 | - } |
|
| 250 | - return $this->form_action; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param string $form_action |
|
| 256 | - * @throws InvalidDataTypeException |
|
| 257 | - */ |
|
| 258 | - public function setFormAction($form_action) |
|
| 259 | - { |
|
| 260 | - if (! is_string($form_action)) { |
|
| 261 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 262 | - } |
|
| 263 | - $this->form_action = $form_action; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param array $form_action_args |
|
| 269 | - * @throws InvalidDataTypeException |
|
| 270 | - * @throws InvalidFormHandlerException |
|
| 271 | - */ |
|
| 272 | - public function addFormActionArgs($form_action_args = array()) |
|
| 273 | - { |
|
| 274 | - if (! is_array($form_action_args)) { |
|
| 275 | - throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
| 276 | - } |
|
| 277 | - $form_action_args = ! empty($form_action_args) |
|
| 278 | - ? $form_action_args |
|
| 279 | - : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
| 280 | - $this->getCurrentStep()->setFormAction( |
|
| 281 | - add_query_arg($form_action_args, $this->formAction()) |
|
| 282 | - ); |
|
| 283 | - $this->form_action = $this->getCurrentStep()->formAction(); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function formConfig() |
|
| 291 | - { |
|
| 292 | - return $this->form_config; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param string $form_config |
|
| 298 | - */ |
|
| 299 | - public function setFormConfig($form_config) |
|
| 300 | - { |
|
| 301 | - $this->form_config = $form_config; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function progressStepStyle() |
|
| 309 | - { |
|
| 310 | - return $this->progress_step_style; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @param string $progress_step_style |
|
| 316 | - */ |
|
| 317 | - public function setProgressStepStyle($progress_step_style) |
|
| 318 | - { |
|
| 319 | - $this->progress_step_style = $progress_step_style; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return EE_Request |
|
| 325 | - */ |
|
| 326 | - public function request() |
|
| 327 | - { |
|
| 328 | - return $this->request; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @return Collection|null |
|
| 334 | - * @throws InvalidInterfaceException |
|
| 335 | - */ |
|
| 336 | - protected function getProgressStepsCollection() |
|
| 337 | - { |
|
| 338 | - static $collection = null; |
|
| 339 | - if (! $collection instanceof ProgressStepCollection) { |
|
| 340 | - $collection = new ProgressStepCollection(); |
|
| 341 | - } |
|
| 342 | - return $collection; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param Collection $progress_steps_collection |
|
| 348 | - * @return ProgressStepManager |
|
| 349 | - * @throws InvalidInterfaceException |
|
| 350 | - * @throws InvalidClassException |
|
| 351 | - * @throws InvalidDataTypeException |
|
| 352 | - * @throws InvalidEntityException |
|
| 353 | - * @throws InvalidFormHandlerException |
|
| 354 | - */ |
|
| 355 | - protected function generateProgressSteps(Collection $progress_steps_collection) |
|
| 356 | - { |
|
| 357 | - $current_step = $this->getCurrentStep(); |
|
| 358 | - /** @var SequentialStepForm $form_step */ |
|
| 359 | - foreach ($this->form_steps as $form_step) { |
|
| 360 | - // is this step active ? |
|
| 361 | - if (! $form_step->initialize()) { |
|
| 362 | - continue; |
|
| 363 | - } |
|
| 364 | - $progress_steps_collection->add( |
|
| 365 | - new ProgressStep( |
|
| 366 | - $form_step->order(), |
|
| 367 | - $form_step->slug(), |
|
| 368 | - $form_step->slug(), |
|
| 369 | - $form_step->formName() |
|
| 370 | - ), |
|
| 371 | - $form_step->slug() |
|
| 372 | - ); |
|
| 373 | - } |
|
| 374 | - // set collection pointer back to current step |
|
| 375 | - $this->form_steps->setCurrentUsingObject($current_step); |
|
| 376 | - return new ProgressStepManager( |
|
| 377 | - $this->progressStepStyle(), |
|
| 378 | - $this->defaultFormStep(), |
|
| 379 | - $this->formStepUrlKey(), |
|
| 380 | - $progress_steps_collection |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @throws InvalidClassException |
|
| 387 | - * @throws InvalidDataTypeException |
|
| 388 | - * @throws InvalidEntityException |
|
| 389 | - * @throws InvalidIdentifierException |
|
| 390 | - * @throws InvalidInterfaceException |
|
| 391 | - * @throws InvalidArgumentException |
|
| 392 | - * @throws InvalidFormHandlerException |
|
| 393 | - */ |
|
| 394 | - public function buildForm() |
|
| 395 | - { |
|
| 396 | - $this->buildCurrentStepFormForDisplay(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @param array $form_data |
|
| 402 | - * @throws InvalidArgumentException |
|
| 403 | - * @throws InvalidClassException |
|
| 404 | - * @throws InvalidDataTypeException |
|
| 405 | - * @throws InvalidEntityException |
|
| 406 | - * @throws InvalidFormHandlerException |
|
| 407 | - * @throws InvalidIdentifierException |
|
| 408 | - * @throws InvalidInterfaceException |
|
| 409 | - */ |
|
| 410 | - public function processForm($form_data = array()) |
|
| 411 | - { |
|
| 412 | - $this->buildCurrentStepFormForProcessing(); |
|
| 413 | - $this->processCurrentStepForm($form_data); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @throws InvalidClassException |
|
| 419 | - * @throws InvalidDataTypeException |
|
| 420 | - * @throws InvalidEntityException |
|
| 421 | - * @throws InvalidInterfaceException |
|
| 422 | - * @throws InvalidIdentifierException |
|
| 423 | - * @throws InvalidArgumentException |
|
| 424 | - * @throws InvalidFormHandlerException |
|
| 425 | - */ |
|
| 426 | - public function buildCurrentStepFormForDisplay() |
|
| 427 | - { |
|
| 428 | - $form_step = $this->buildCurrentStepForm(); |
|
| 429 | - // no displayable content ? then skip straight to processing |
|
| 430 | - if (! $form_step->displayable()) { |
|
| 431 | - $this->addFormActionArgs(); |
|
| 432 | - $form_step->setFormAction($this->formAction()); |
|
| 433 | - wp_safe_redirect($form_step->formAction()); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * @throws InvalidClassException |
|
| 440 | - * @throws InvalidDataTypeException |
|
| 441 | - * @throws InvalidEntityException |
|
| 442 | - * @throws InvalidInterfaceException |
|
| 443 | - * @throws InvalidIdentifierException |
|
| 444 | - * @throws InvalidArgumentException |
|
| 445 | - * @throws InvalidFormHandlerException |
|
| 446 | - */ |
|
| 447 | - public function buildCurrentStepFormForProcessing() |
|
| 448 | - { |
|
| 449 | - $this->buildCurrentStepForm(false); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param bool $for_display |
|
| 455 | - * @return SequentialStepFormInterface |
|
| 456 | - * @throws InvalidArgumentException |
|
| 457 | - * @throws InvalidClassException |
|
| 458 | - * @throws InvalidDataTypeException |
|
| 459 | - * @throws InvalidEntityException |
|
| 460 | - * @throws InvalidFormHandlerException |
|
| 461 | - * @throws InvalidIdentifierException |
|
| 462 | - * @throws InvalidInterfaceException |
|
| 463 | - */ |
|
| 464 | - private function buildCurrentStepForm($for_display = true) |
|
| 465 | - { |
|
| 466 | - $this->form_steps = $this->getFormStepsCollection(); |
|
| 467 | - $this->setCurrentStepFromRequest(); |
|
| 468 | - $form_step = $this->getCurrentStep(); |
|
| 469 | - if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
| 470 | - $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
| 471 | - } |
|
| 472 | - if ($for_display && $form_step->displayable()) { |
|
| 473 | - $this->progress_step_manager = $this->generateProgressSteps( |
|
| 474 | - $this->getProgressStepsCollection() |
|
| 475 | - ); |
|
| 476 | - $this->progress_step_manager->setCurrentStep( |
|
| 477 | - $form_step->slug() |
|
| 478 | - ); |
|
| 479 | - // mark all previous progress steps as completed |
|
| 480 | - $this->progress_step_manager->setPreviousStepsCompleted(); |
|
| 481 | - $this->progress_step_manager->enqueueStylesAndScripts(); |
|
| 482 | - $this->addFormActionArgs(); |
|
| 483 | - $form_step->setFormAction($this->formAction()); |
|
| 484 | - } else { |
|
| 485 | - $form_step->setRedirectUrl($this->baseUrl()); |
|
| 486 | - $form_step->addRedirectArgs( |
|
| 487 | - array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - $form_step->generate(); |
|
| 491 | - if ($for_display) { |
|
| 492 | - $form_step->enqueueStylesAndScripts(); |
|
| 493 | - } |
|
| 494 | - return $form_step; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * @param bool $return_as_string |
|
| 500 | - * @return string |
|
| 501 | - * @throws InvalidFormHandlerException |
|
| 502 | - */ |
|
| 503 | - public function displayProgressSteps($return_as_string = true) |
|
| 504 | - { |
|
| 505 | - $form_step = $this->getCurrentStep(); |
|
| 506 | - if (! $form_step->displayable()) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $progress_steps = apply_filters( |
|
| 510 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
| 511 | - '' |
|
| 512 | - ); |
|
| 513 | - $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
| 514 | - $progress_steps .= apply_filters( |
|
| 515 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
| 516 | - '' |
|
| 517 | - ); |
|
| 518 | - if ($return_as_string) { |
|
| 519 | - return $progress_steps; |
|
| 520 | - } |
|
| 521 | - echo $progress_steps; |
|
| 522 | - return ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * @param bool $return_as_string |
|
| 528 | - * @return string |
|
| 529 | - * @throws InvalidFormHandlerException |
|
| 530 | - */ |
|
| 531 | - public function displayCurrentStepForm($return_as_string = true) |
|
| 532 | - { |
|
| 533 | - if ($return_as_string) { |
|
| 534 | - return $this->getCurrentStep()->display(); |
|
| 535 | - } |
|
| 536 | - echo $this->getCurrentStep()->display(); |
|
| 537 | - return ''; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @param array $form_data |
|
| 543 | - * @return void |
|
| 544 | - * @throws InvalidArgumentException |
|
| 545 | - * @throws InvalidDataTypeException |
|
| 546 | - * @throws InvalidFormHandlerException |
|
| 547 | - */ |
|
| 548 | - public function processCurrentStepForm($form_data = array()) |
|
| 549 | - { |
|
| 550 | - // grab instance of current step because after calling next() below, |
|
| 551 | - // any calls to getCurrentStep() will return the "next" step because we advanced |
|
| 552 | - $current_step = $this->getCurrentStep(); |
|
| 553 | - try { |
|
| 554 | - // form processing should either throw exceptions or return true |
|
| 555 | - $current_step->process($form_data); |
|
| 556 | - } catch (Exception $e) { |
|
| 557 | - // something went wrong, convert the Exception to an EE_Error |
|
| 558 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 559 | - // prevent redirect to next step or other if exception was thrown |
|
| 560 | - if ( |
|
| 561 | - $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
| 562 | - || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
| 563 | - ) { |
|
| 564 | - $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - // save notices to a transient so that when we redirect back |
|
| 568 | - // to the display portion for this step |
|
| 569 | - // those notices can be displayed |
|
| 570 | - EE_Error::get_notices(false, true); |
|
| 571 | - $this->redirectForm($current_step); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * handles where to go to next |
|
| 577 | - * |
|
| 578 | - * @param SequentialStepFormInterface $current_step |
|
| 579 | - * @throws InvalidArgumentException |
|
| 580 | - * @throws InvalidDataTypeException |
|
| 581 | - * @throws InvalidFormHandlerException |
|
| 582 | - */ |
|
| 583 | - public function redirectForm(SequentialStepFormInterface $current_step) |
|
| 584 | - { |
|
| 585 | - $redirect_step = $current_step; |
|
| 586 | - switch ($current_step->redirectTo()) { |
|
| 587 | - case SequentialStepForm::REDIRECT_TO_OTHER: |
|
| 588 | - // going somewhere else, so just check out now |
|
| 589 | - wp_safe_redirect($redirect_step->redirectUrl()); |
|
| 590 | - exit(); |
|
| 591 | - break; |
|
| 592 | - case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
| 593 | - $redirect_step = $this->form_steps->previous(); |
|
| 594 | - break; |
|
| 595 | - case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
| 596 | - $this->form_steps->next(); |
|
| 597 | - if ($this->form_steps->valid()) { |
|
| 598 | - $redirect_step = $this->form_steps->current(); |
|
| 599 | - } |
|
| 600 | - break; |
|
| 601 | - case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
| 602 | - default: |
|
| 603 | - // $redirect_step is already set |
|
| 604 | - } |
|
| 605 | - $current_step->setRedirectUrl($this->baseUrl()); |
|
| 606 | - $current_step->addRedirectArgs( |
|
| 607 | - // use the slug for whatever step we are redirecting too |
|
| 608 | - array($this->formStepUrlKey() => $redirect_step->slug()) |
|
| 609 | - ); |
|
| 610 | - wp_safe_redirect($current_step->redirectUrl()); |
|
| 611 | - exit(); |
|
| 612 | - } |
|
| 32 | + /** |
|
| 33 | + * a simplified URL with no form related parameters |
|
| 34 | + * that will be used to build the form's redirect URLs |
|
| 35 | + * |
|
| 36 | + * @var string $base_url |
|
| 37 | + */ |
|
| 38 | + private $base_url = ''; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * the key used for the URL param that denotes the current form step |
|
| 42 | + * defaults to 'ee-form-step' |
|
| 43 | + * |
|
| 44 | + * @var string $form_step_url_key |
|
| 45 | + */ |
|
| 46 | + private $form_step_url_key = ''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var string $default_form_step |
|
| 50 | + */ |
|
| 51 | + private $default_form_step = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var string $form_action |
|
| 55 | + */ |
|
| 56 | + private $form_action; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * value of one of the string constant above |
|
| 60 | + * |
|
| 61 | + * @var string $form_config |
|
| 62 | + */ |
|
| 63 | + private $form_config; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var string $progress_step_style |
|
| 67 | + */ |
|
| 68 | + private $progress_step_style = ''; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var EE_Request $request |
|
| 72 | + */ |
|
| 73 | + private $request; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var Collection $form_steps |
|
| 77 | + */ |
|
| 78 | + protected $form_steps; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var ProgressStepManager $progress_step_manager |
|
| 82 | + */ |
|
| 83 | + protected $progress_step_manager; |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return Collection|null |
|
| 88 | + */ |
|
| 89 | + abstract protected function getFormStepsCollection(); |
|
| 90 | + |
|
| 91 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 92 | + /** |
|
| 93 | + * StepsManager constructor |
|
| 94 | + * |
|
| 95 | + * @param string $base_url |
|
| 96 | + * @param string $default_form_step |
|
| 97 | + * @param string $form_action |
|
| 98 | + * @param string $form_config |
|
| 99 | + * @param EE_Request $request |
|
| 100 | + * @param string $progress_step_style |
|
| 101 | + * @throws InvalidDataTypeException |
|
| 102 | + * @throws InvalidArgumentException |
|
| 103 | + */ |
|
| 104 | + public function __construct( |
|
| 105 | + $base_url, |
|
| 106 | + $default_form_step, |
|
| 107 | + $form_action = '', |
|
| 108 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 109 | + $progress_step_style = 'number_bubbles', |
|
| 110 | + EE_Request $request |
|
| 111 | + ) { |
|
| 112 | + $this->setBaseUrl($base_url); |
|
| 113 | + $this->setDefaultFormStep($default_form_step); |
|
| 114 | + $this->setFormAction($form_action); |
|
| 115 | + $this->setFormConfig($form_config); |
|
| 116 | + $this->setProgressStepStyle($progress_step_style); |
|
| 117 | + $this->request = $request; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return string |
|
| 123 | + * @throws InvalidFormHandlerException |
|
| 124 | + */ |
|
| 125 | + public function baseUrl() |
|
| 126 | + { |
|
| 127 | + if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
| 128 | + add_query_arg( |
|
| 129 | + array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
| 130 | + $this->base_url |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + return $this->base_url; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $base_url |
|
| 139 | + * @throws InvalidDataTypeException |
|
| 140 | + * @throws InvalidArgumentException |
|
| 141 | + */ |
|
| 142 | + protected function setBaseUrl($base_url) |
|
| 143 | + { |
|
| 144 | + if (! is_string($base_url)) { |
|
| 145 | + throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
| 146 | + } |
|
| 147 | + if (empty($base_url)) { |
|
| 148 | + throw new InvalidArgumentException( |
|
| 149 | + esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + $this->base_url = $base_url; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return string |
|
| 158 | + * @throws InvalidDataTypeException |
|
| 159 | + */ |
|
| 160 | + public function formStepUrlKey() |
|
| 161 | + { |
|
| 162 | + if (empty($this->form_step_url_key)) { |
|
| 163 | + $this->setFormStepUrlKey(); |
|
| 164 | + } |
|
| 165 | + return $this->form_step_url_key; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $form_step_url_key |
|
| 171 | + * @throws InvalidDataTypeException |
|
| 172 | + */ |
|
| 173 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
| 174 | + { |
|
| 175 | + if (! is_string($form_step_url_key)) { |
|
| 176 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
| 177 | + } |
|
| 178 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @return string |
|
| 184 | + */ |
|
| 185 | + public function defaultFormStep() |
|
| 186 | + { |
|
| 187 | + return $this->default_form_step; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param $default_form_step |
|
| 193 | + * @throws InvalidDataTypeException |
|
| 194 | + */ |
|
| 195 | + protected function setDefaultFormStep($default_form_step) |
|
| 196 | + { |
|
| 197 | + if (! is_string($default_form_step)) { |
|
| 198 | + throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
| 199 | + } |
|
| 200 | + $this->default_form_step = $default_form_step; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @return void |
|
| 206 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 207 | + * @throws InvalidDataTypeException |
|
| 208 | + */ |
|
| 209 | + protected function setCurrentStepFromRequest() |
|
| 210 | + { |
|
| 211 | + $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep()); |
|
| 212 | + if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
| 213 | + throw new InvalidIdentifierException( |
|
| 214 | + $current_step_slug, |
|
| 215 | + $this->defaultFormStep(), |
|
| 216 | + $message = sprintf( |
|
| 217 | + esc_html__( |
|
| 218 | + 'The "%1$s" form step could not be set.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + $current_step_slug |
|
| 222 | + ) |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return object|SequentialStepFormInterface |
|
| 230 | + * @throws InvalidFormHandlerException |
|
| 231 | + */ |
|
| 232 | + public function getCurrentStep() |
|
| 233 | + { |
|
| 234 | + if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
| 235 | + throw new InvalidFormHandlerException($this->form_steps->current()); |
|
| 236 | + } |
|
| 237 | + return $this->form_steps->current(); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return string |
|
| 243 | + * @throws InvalidFormHandlerException |
|
| 244 | + */ |
|
| 245 | + public function formAction() |
|
| 246 | + { |
|
| 247 | + if (! is_string($this->form_action) || empty($this->form_action)) { |
|
| 248 | + $this->form_action = $this->baseUrl(); |
|
| 249 | + } |
|
| 250 | + return $this->form_action; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param string $form_action |
|
| 256 | + * @throws InvalidDataTypeException |
|
| 257 | + */ |
|
| 258 | + public function setFormAction($form_action) |
|
| 259 | + { |
|
| 260 | + if (! is_string($form_action)) { |
|
| 261 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 262 | + } |
|
| 263 | + $this->form_action = $form_action; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param array $form_action_args |
|
| 269 | + * @throws InvalidDataTypeException |
|
| 270 | + * @throws InvalidFormHandlerException |
|
| 271 | + */ |
|
| 272 | + public function addFormActionArgs($form_action_args = array()) |
|
| 273 | + { |
|
| 274 | + if (! is_array($form_action_args)) { |
|
| 275 | + throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
| 276 | + } |
|
| 277 | + $form_action_args = ! empty($form_action_args) |
|
| 278 | + ? $form_action_args |
|
| 279 | + : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
| 280 | + $this->getCurrentStep()->setFormAction( |
|
| 281 | + add_query_arg($form_action_args, $this->formAction()) |
|
| 282 | + ); |
|
| 283 | + $this->form_action = $this->getCurrentStep()->formAction(); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function formConfig() |
|
| 291 | + { |
|
| 292 | + return $this->form_config; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param string $form_config |
|
| 298 | + */ |
|
| 299 | + public function setFormConfig($form_config) |
|
| 300 | + { |
|
| 301 | + $this->form_config = $form_config; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function progressStepStyle() |
|
| 309 | + { |
|
| 310 | + return $this->progress_step_style; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @param string $progress_step_style |
|
| 316 | + */ |
|
| 317 | + public function setProgressStepStyle($progress_step_style) |
|
| 318 | + { |
|
| 319 | + $this->progress_step_style = $progress_step_style; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return EE_Request |
|
| 325 | + */ |
|
| 326 | + public function request() |
|
| 327 | + { |
|
| 328 | + return $this->request; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @return Collection|null |
|
| 334 | + * @throws InvalidInterfaceException |
|
| 335 | + */ |
|
| 336 | + protected function getProgressStepsCollection() |
|
| 337 | + { |
|
| 338 | + static $collection = null; |
|
| 339 | + if (! $collection instanceof ProgressStepCollection) { |
|
| 340 | + $collection = new ProgressStepCollection(); |
|
| 341 | + } |
|
| 342 | + return $collection; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param Collection $progress_steps_collection |
|
| 348 | + * @return ProgressStepManager |
|
| 349 | + * @throws InvalidInterfaceException |
|
| 350 | + * @throws InvalidClassException |
|
| 351 | + * @throws InvalidDataTypeException |
|
| 352 | + * @throws InvalidEntityException |
|
| 353 | + * @throws InvalidFormHandlerException |
|
| 354 | + */ |
|
| 355 | + protected function generateProgressSteps(Collection $progress_steps_collection) |
|
| 356 | + { |
|
| 357 | + $current_step = $this->getCurrentStep(); |
|
| 358 | + /** @var SequentialStepForm $form_step */ |
|
| 359 | + foreach ($this->form_steps as $form_step) { |
|
| 360 | + // is this step active ? |
|
| 361 | + if (! $form_step->initialize()) { |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 364 | + $progress_steps_collection->add( |
|
| 365 | + new ProgressStep( |
|
| 366 | + $form_step->order(), |
|
| 367 | + $form_step->slug(), |
|
| 368 | + $form_step->slug(), |
|
| 369 | + $form_step->formName() |
|
| 370 | + ), |
|
| 371 | + $form_step->slug() |
|
| 372 | + ); |
|
| 373 | + } |
|
| 374 | + // set collection pointer back to current step |
|
| 375 | + $this->form_steps->setCurrentUsingObject($current_step); |
|
| 376 | + return new ProgressStepManager( |
|
| 377 | + $this->progressStepStyle(), |
|
| 378 | + $this->defaultFormStep(), |
|
| 379 | + $this->formStepUrlKey(), |
|
| 380 | + $progress_steps_collection |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @throws InvalidClassException |
|
| 387 | + * @throws InvalidDataTypeException |
|
| 388 | + * @throws InvalidEntityException |
|
| 389 | + * @throws InvalidIdentifierException |
|
| 390 | + * @throws InvalidInterfaceException |
|
| 391 | + * @throws InvalidArgumentException |
|
| 392 | + * @throws InvalidFormHandlerException |
|
| 393 | + */ |
|
| 394 | + public function buildForm() |
|
| 395 | + { |
|
| 396 | + $this->buildCurrentStepFormForDisplay(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @param array $form_data |
|
| 402 | + * @throws InvalidArgumentException |
|
| 403 | + * @throws InvalidClassException |
|
| 404 | + * @throws InvalidDataTypeException |
|
| 405 | + * @throws InvalidEntityException |
|
| 406 | + * @throws InvalidFormHandlerException |
|
| 407 | + * @throws InvalidIdentifierException |
|
| 408 | + * @throws InvalidInterfaceException |
|
| 409 | + */ |
|
| 410 | + public function processForm($form_data = array()) |
|
| 411 | + { |
|
| 412 | + $this->buildCurrentStepFormForProcessing(); |
|
| 413 | + $this->processCurrentStepForm($form_data); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @throws InvalidClassException |
|
| 419 | + * @throws InvalidDataTypeException |
|
| 420 | + * @throws InvalidEntityException |
|
| 421 | + * @throws InvalidInterfaceException |
|
| 422 | + * @throws InvalidIdentifierException |
|
| 423 | + * @throws InvalidArgumentException |
|
| 424 | + * @throws InvalidFormHandlerException |
|
| 425 | + */ |
|
| 426 | + public function buildCurrentStepFormForDisplay() |
|
| 427 | + { |
|
| 428 | + $form_step = $this->buildCurrentStepForm(); |
|
| 429 | + // no displayable content ? then skip straight to processing |
|
| 430 | + if (! $form_step->displayable()) { |
|
| 431 | + $this->addFormActionArgs(); |
|
| 432 | + $form_step->setFormAction($this->formAction()); |
|
| 433 | + wp_safe_redirect($form_step->formAction()); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * @throws InvalidClassException |
|
| 440 | + * @throws InvalidDataTypeException |
|
| 441 | + * @throws InvalidEntityException |
|
| 442 | + * @throws InvalidInterfaceException |
|
| 443 | + * @throws InvalidIdentifierException |
|
| 444 | + * @throws InvalidArgumentException |
|
| 445 | + * @throws InvalidFormHandlerException |
|
| 446 | + */ |
|
| 447 | + public function buildCurrentStepFormForProcessing() |
|
| 448 | + { |
|
| 449 | + $this->buildCurrentStepForm(false); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param bool $for_display |
|
| 455 | + * @return SequentialStepFormInterface |
|
| 456 | + * @throws InvalidArgumentException |
|
| 457 | + * @throws InvalidClassException |
|
| 458 | + * @throws InvalidDataTypeException |
|
| 459 | + * @throws InvalidEntityException |
|
| 460 | + * @throws InvalidFormHandlerException |
|
| 461 | + * @throws InvalidIdentifierException |
|
| 462 | + * @throws InvalidInterfaceException |
|
| 463 | + */ |
|
| 464 | + private function buildCurrentStepForm($for_display = true) |
|
| 465 | + { |
|
| 466 | + $this->form_steps = $this->getFormStepsCollection(); |
|
| 467 | + $this->setCurrentStepFromRequest(); |
|
| 468 | + $form_step = $this->getCurrentStep(); |
|
| 469 | + if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
| 470 | + $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
| 471 | + } |
|
| 472 | + if ($for_display && $form_step->displayable()) { |
|
| 473 | + $this->progress_step_manager = $this->generateProgressSteps( |
|
| 474 | + $this->getProgressStepsCollection() |
|
| 475 | + ); |
|
| 476 | + $this->progress_step_manager->setCurrentStep( |
|
| 477 | + $form_step->slug() |
|
| 478 | + ); |
|
| 479 | + // mark all previous progress steps as completed |
|
| 480 | + $this->progress_step_manager->setPreviousStepsCompleted(); |
|
| 481 | + $this->progress_step_manager->enqueueStylesAndScripts(); |
|
| 482 | + $this->addFormActionArgs(); |
|
| 483 | + $form_step->setFormAction($this->formAction()); |
|
| 484 | + } else { |
|
| 485 | + $form_step->setRedirectUrl($this->baseUrl()); |
|
| 486 | + $form_step->addRedirectArgs( |
|
| 487 | + array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + $form_step->generate(); |
|
| 491 | + if ($for_display) { |
|
| 492 | + $form_step->enqueueStylesAndScripts(); |
|
| 493 | + } |
|
| 494 | + return $form_step; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @param bool $return_as_string |
|
| 500 | + * @return string |
|
| 501 | + * @throws InvalidFormHandlerException |
|
| 502 | + */ |
|
| 503 | + public function displayProgressSteps($return_as_string = true) |
|
| 504 | + { |
|
| 505 | + $form_step = $this->getCurrentStep(); |
|
| 506 | + if (! $form_step->displayable()) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $progress_steps = apply_filters( |
|
| 510 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
| 511 | + '' |
|
| 512 | + ); |
|
| 513 | + $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
| 514 | + $progress_steps .= apply_filters( |
|
| 515 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
| 516 | + '' |
|
| 517 | + ); |
|
| 518 | + if ($return_as_string) { |
|
| 519 | + return $progress_steps; |
|
| 520 | + } |
|
| 521 | + echo $progress_steps; |
|
| 522 | + return ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * @param bool $return_as_string |
|
| 528 | + * @return string |
|
| 529 | + * @throws InvalidFormHandlerException |
|
| 530 | + */ |
|
| 531 | + public function displayCurrentStepForm($return_as_string = true) |
|
| 532 | + { |
|
| 533 | + if ($return_as_string) { |
|
| 534 | + return $this->getCurrentStep()->display(); |
|
| 535 | + } |
|
| 536 | + echo $this->getCurrentStep()->display(); |
|
| 537 | + return ''; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @param array $form_data |
|
| 543 | + * @return void |
|
| 544 | + * @throws InvalidArgumentException |
|
| 545 | + * @throws InvalidDataTypeException |
|
| 546 | + * @throws InvalidFormHandlerException |
|
| 547 | + */ |
|
| 548 | + public function processCurrentStepForm($form_data = array()) |
|
| 549 | + { |
|
| 550 | + // grab instance of current step because after calling next() below, |
|
| 551 | + // any calls to getCurrentStep() will return the "next" step because we advanced |
|
| 552 | + $current_step = $this->getCurrentStep(); |
|
| 553 | + try { |
|
| 554 | + // form processing should either throw exceptions or return true |
|
| 555 | + $current_step->process($form_data); |
|
| 556 | + } catch (Exception $e) { |
|
| 557 | + // something went wrong, convert the Exception to an EE_Error |
|
| 558 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 559 | + // prevent redirect to next step or other if exception was thrown |
|
| 560 | + if ( |
|
| 561 | + $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
| 562 | + || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
| 563 | + ) { |
|
| 564 | + $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + // save notices to a transient so that when we redirect back |
|
| 568 | + // to the display portion for this step |
|
| 569 | + // those notices can be displayed |
|
| 570 | + EE_Error::get_notices(false, true); |
|
| 571 | + $this->redirectForm($current_step); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * handles where to go to next |
|
| 577 | + * |
|
| 578 | + * @param SequentialStepFormInterface $current_step |
|
| 579 | + * @throws InvalidArgumentException |
|
| 580 | + * @throws InvalidDataTypeException |
|
| 581 | + * @throws InvalidFormHandlerException |
|
| 582 | + */ |
|
| 583 | + public function redirectForm(SequentialStepFormInterface $current_step) |
|
| 584 | + { |
|
| 585 | + $redirect_step = $current_step; |
|
| 586 | + switch ($current_step->redirectTo()) { |
|
| 587 | + case SequentialStepForm::REDIRECT_TO_OTHER: |
|
| 588 | + // going somewhere else, so just check out now |
|
| 589 | + wp_safe_redirect($redirect_step->redirectUrl()); |
|
| 590 | + exit(); |
|
| 591 | + break; |
|
| 592 | + case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
| 593 | + $redirect_step = $this->form_steps->previous(); |
|
| 594 | + break; |
|
| 595 | + case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
| 596 | + $this->form_steps->next(); |
|
| 597 | + if ($this->form_steps->valid()) { |
|
| 598 | + $redirect_step = $this->form_steps->current(); |
|
| 599 | + } |
|
| 600 | + break; |
|
| 601 | + case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
| 602 | + default: |
|
| 603 | + // $redirect_step is already set |
|
| 604 | + } |
|
| 605 | + $current_step->setRedirectUrl($this->baseUrl()); |
|
| 606 | + $current_step->addRedirectArgs( |
|
| 607 | + // use the slug for whatever step we are redirecting too |
|
| 608 | + array($this->formStepUrlKey() => $redirect_step->slug()) |
|
| 609 | + ); |
|
| 610 | + wp_safe_redirect($current_step->redirectUrl()); |
|
| 611 | + exit(); |
|
| 612 | + } |
|
| 613 | 613 | } |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | class InvalidFormHandlerException extends \UnexpectedValueException |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * InvalidFormHandlerException constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $actual the FormHandler object that was received |
|
| 20 | - * @param string $message |
|
| 21 | - * @param int $code |
|
| 22 | - * @param \Exception $previous |
|
| 23 | - */ |
|
| 24 | - public function __construct($actual, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | - { |
|
| 26 | - if (empty($message)) { |
|
| 27 | - $message = sprintf( |
|
| 28 | - __( |
|
| 29 | - 'A valid Form Handler was expected but instead "%1$s" was received.', |
|
| 30 | - 'event_espresso' |
|
| 31 | - ), |
|
| 32 | - $actual |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - parent::__construct($message, $code, $previous); |
|
| 36 | - } |
|
| 16 | + /** |
|
| 17 | + * InvalidFormHandlerException constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $actual the FormHandler object that was received |
|
| 20 | + * @param string $message |
|
| 21 | + * @param int $code |
|
| 22 | + * @param \Exception $previous |
|
| 23 | + */ |
|
| 24 | + public function __construct($actual, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | + { |
|
| 26 | + if (empty($message)) { |
|
| 27 | + $message = sprintf( |
|
| 28 | + __( |
|
| 29 | + 'A valid Form Handler was expected but instead "%1$s" was received.', |
|
| 30 | + 'event_espresso' |
|
| 31 | + ), |
|
| 32 | + $actual |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + parent::__construct($message, $code, $previous); |
|
| 36 | + } |
|
| 37 | 37 | } |