1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CheckoutStepController.php |
4
|
|
|
* |
5
|
|
|
* @author Bram de Leeuw |
6
|
|
|
* Date: 16/03/17 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
10
|
|
|
|
11
|
|
|
use Page_Controller; |
12
|
|
|
use SSViewer; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class CheckoutStepController |
16
|
|
|
* |
17
|
|
|
* @package Broarm\EventTickets |
18
|
|
|
*/ |
19
|
|
|
abstract class CheckoutStepController extends Page_Controller |
20
|
|
|
{ |
21
|
|
|
protected $step = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Reservation|null |
25
|
|
|
*/ |
26
|
|
|
protected $reservation = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Init the controller and check if the current step is allowed |
30
|
|
|
*/ |
31
|
|
|
public function init() |
32
|
|
|
{ |
33
|
|
|
// If the step is not a registered step exit |
34
|
|
|
if (!in_array($this->step, CheckoutSteps::getSteps())) { |
35
|
|
|
$this->redirect($this->Link('/')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// If no ReservationSession exists redirect back to the base event controller |
39
|
|
|
elseif (empty(ReservationSession::get())) { |
40
|
|
|
$this->redirect($this->Link('/')); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// If the reservation has been processed end the session and redirect |
44
|
|
|
elseif (ReservationSession::get()->Status === 'PAID' && $this->step != 'success') { |
45
|
|
|
ReservationSession::end(); |
46
|
|
|
$this->redirect($this->Link('/')); |
47
|
|
|
} else { |
48
|
|
|
$this->reservation = ReservationSession::get(); |
|
|
|
|
49
|
|
|
parent::init(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Force the controller action |
55
|
|
|
* |
56
|
|
|
* @param string $action |
57
|
|
|
* |
58
|
|
|
* @return SSViewer |
59
|
|
|
*/ |
60
|
|
|
public function getViewer($action) |
61
|
|
|
{ |
62
|
|
|
if ($action === 'index') { |
63
|
|
|
$action = $this->step; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return parent::getViewer($action); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get a relative link to the current controller |
71
|
|
|
* |
72
|
|
|
* @param null $action |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function Link($action = null) |
77
|
|
|
{ |
78
|
|
|
if (!$action) { |
79
|
|
|
$action = $this->step; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->dataRecord->RelativeLink($action); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the current reservation |
87
|
|
|
* |
88
|
|
|
* @return Reservation |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
public function getReservation() { |
91
|
|
|
return $this->reservation; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get a link to the next step |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getNextStepLink() |
100
|
|
|
{ |
101
|
|
|
return $this->Link(CheckoutSteps::nextStep($this->step)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get the checkout steps |
106
|
|
|
* |
107
|
|
|
* @return \ArrayList |
108
|
|
|
*/ |
109
|
|
|
public function CheckoutSteps() |
110
|
|
|
{ |
111
|
|
|
return CheckoutSteps::get($this); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.