1 | <?php |
||
15 | abstract class AbstractSettings extends Model implements SettingsInterface |
||
16 | { |
||
17 | |||
18 | const ENDPOINT_PREFIX = 'sso'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $myType; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $entityId; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | public $endpointPrefix = self::ENDPOINT_PREFIX; |
||
34 | |||
35 | /** |
||
36 | * This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
||
37 | * @see GeneralConfig::$loginPath |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $loginEndpoint = 'login'; |
||
42 | |||
43 | /** |
||
44 | * This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
||
45 | * @see GeneralConfig::$loginPath |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $logoutEndpoint = 'logout'; |
||
50 | |||
51 | /** |
||
52 | * This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
||
53 | * @see GeneralConfig::$loginPath |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $loginRequestEndpoint = 'login/request'; |
||
58 | |||
59 | /** |
||
60 | * This is the endpoint used to initiate logout. In this case, `logoutPath` cannot be used. |
||
61 | * Point your logout button to this endpoint. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $logoutRequestEndpoint = 'logout/request'; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * This setting will destroy sessions when the Name Id matches a user with existing sessions. |
||
70 | * A current user session doesn't have to exist, ie, `\Craft::$app->user->isGuest === true`. |
||
71 | * |
||
72 | * This can be useful if the LogoutRequest is sent over AJAX. |
||
73 | * |
||
74 | * Warning: this will delete all current sessions for the user |
||
75 | * |
||
76 | * @var bool |
||
77 | */ |
||
78 | public $sloDestroySpecifiedSessions = false; |
||
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | */ |
||
83 | public function attributes() |
||
92 | |||
93 | /******************************************* |
||
94 | * ENTITY ID |
||
95 | *******************************************/ |
||
96 | |||
97 | /** |
||
98 | * @param $entityId |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setEntityId($entityId) |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | * @throws \craft\errors\SiteNotFoundException |
||
111 | */ |
||
112 | public function getEntityId() |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | * @throws \craft\errors\SiteNotFoundException |
||
124 | */ |
||
125 | public function getEntityIdRaw() |
||
133 | |||
134 | public function getEndpointPrefix() |
||
138 | |||
139 | /** |
||
140 | * @param $myType |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setMyType($myType) |
||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function getMyType() |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | public function getRemoteType() |
||
164 | |||
165 | /** |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function isIDP() |
||
172 | |||
173 | /** |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function isSP() |
||
180 | |||
181 | protected function buildEndpointUrl($url) |
||
185 | |||
186 | /** |
||
187 | * @inheritdoc |
||
188 | */ |
||
189 | public function getDefaultLoginEndpoint() |
||
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | public function getDefaultLogoutEndpoint() |
||
207 | |||
208 | /** |
||
209 | * @inheritdoc |
||
210 | */ |
||
211 | public function getDefaultLogoutRequestEndpoint() |
||
217 | |||
218 | /** |
||
219 | * @inheritdoc |
||
220 | */ |
||
221 | public function getDefaultLoginRequestEndpoint() |
||
227 | |||
228 | /** |
||
229 | * @inheritdoc |
||
230 | */ |
||
231 | public function getDefaultLoginPath() |
||
235 | |||
236 | /** |
||
237 | * @inheritdoc |
||
238 | */ |
||
239 | public function getDefaultLogoutPath() |
||
243 | |||
244 | /** |
||
245 | * @inheritdoc |
||
246 | */ |
||
247 | public function getDefaultLogoutRequestPath() |
||
251 | |||
252 | /** |
||
253 | * @inheritdoc |
||
254 | */ |
||
255 | public function getDefaultLoginRequestPath() |
||
260 | } |
||
261 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.