1111
1212class KnownUser
1313{
14+ const QueueITAjaxHeaderKey = "x-queueit-ajaxpageurl " ;
1415 //used for unittest
1516 private static $ userInQueueService = null ;
1617 private static function getUserInQueueService () {
@@ -45,46 +46,10 @@ public static function extendQueueCookie($eventId, $cookieValidityMinute, $cooki
4546 $ userInQueueService ->extendQueueCookie ($ eventId , $ cookieValidityMinute , $ cookieDomain , $ secretKey );
4647 }
4748
48- public static function resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , QueueEventConfig $ queueConfig , $ customerId , $ secretKey ) {
49- if (KnownUser::getIsDebug ($ queueitToken , $ secretKey ))
50- {
51- $ dic = array (
52- "TargetUrl " => $ targetUrl ,
53- "QueueitToken " => $ queueitToken ,
54- "QueueConfig " =>$ queueConfig != null ? $ queueConfig ->getString () : "NULL " ,
55- "OriginalUrl " => KnownUser::getHttpRequestProvider ()->getAbsoluteUri ());
56- KnownUser::logMoreRequestDetails ($ dic );
57- KnownUser::doCookieLog ($ dic );
58- }
59- if (Utils::isNullOrEmptyString ($ customerId )) {
60- throw new KnownUserException ("customerId can not be null or empty. " );
61- }
62-
63- if (Utils::isNullOrEmptyString ($ secretKey )) {
64- throw new KnownUserException ("secretKey can not be null or empty. " );
65- }
66-
67- if (Utils::isNullOrEmptyString ($ queueConfig ->eventId )) {
68- throw new KnownUserException ("eventId from queueConfig can not be null or empty. " );
69- }
7049
71- if (Utils::isNullOrEmptyString ($ queueConfig ->queueDomain )) {
72- throw new KnownUserException ("queueDomain from queueConfig can not be null or empty. " );
73- }
74-
75- if (!is_int ($ queueConfig ->cookieValidityMinute ) || intval ($ queueConfig ->cookieValidityMinute ) <= 0 ) {
76- throw new KnownUserException ("cookieValidityMinute from queueConfig should be integer greater than 0. " );
77- }
78-
79- if (!is_bool ($ queueConfig ->extendCookieValidity )) {
80- throw new KnownUserException ("extendCookieValidity from queueConfig should be valid boolean. " );
81- }
82-
83- $ userInQueueService = KnownUser::getUserInQueueService ();
84- return $ userInQueueService ->validateQueueRequest ($ targetUrl , $ queueitToken , $ queueConfig , $ customerId , $ secretKey );
85- }
8650
8751 public static function cancelRequestByLocalConfig ($ targetUrl , $ queueitToken ,CancelEventConfig $ cancelConfig , $ customerId , $ secretKey ) {
52+ $ targetUrl = KnownUser::generateTargetUrl ($ targetUrl );
8853 if (KnownUser::getIsDebug ($ queueitToken , $ secretKey ))
8954 {
9055 $ dic = array (
@@ -114,8 +79,11 @@ public static function cancelRequestByLocalConfig($targetUrl, $queueitToken,Canc
11479 if (Utils::isNullOrEmptyString ($ cancelConfig ->queueDomain )) {
11580 throw new KnownUserException ("queueDomain from cancelConfig can not be null or empty. " );
11681 }
82+
11783 $ userInQueueService = KnownUser::getUserInQueueService ();
118- return $ userInQueueService ->validateCancelRequest ($ targetUrl , $ cancelConfig , $ customerId , $ secretKey );
84+ $ result = $ userInQueueService ->validateCancelRequest ($ targetUrl , $ cancelConfig , $ customerId , $ secretKey );
85+ $ result ->isAjaxResult = KnownUser::isQueueAjaxCall ();
86+ return $ result ;
11987 }
12088
12189 public static function validateRequestByIntegrationConfig ($ currentUrlWithoutQueueITToken , $ queueitToken , $ integrationsConfigString , $ customerId , $ secretKey ) {
@@ -175,7 +143,9 @@ public static function validateRequestByIntegrationConfig($currentUrlWithoutQueu
175143 else //IgnoreAction
176144 {
177145 $ userInQueueService = KnownUser::getUserInQueueService ();
178- return $ userInQueueService ->getIgnoreActionResult ();
146+ $ result = $ userInQueueService ->getIgnoreActionResult ();
147+ $ result ->isAjaxResult = KnownUser::isQueueAjaxCall ();
148+ return $ result ;
179149 }
180150 }
181151 catch (\Exception $ e ) {
@@ -184,7 +154,52 @@ public static function validateRequestByIntegrationConfig($currentUrlWithoutQueu
184154
185155
186156 }
157+ public static function resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , QueueEventConfig $ queueConfig , $ customerId , $ secretKey ) {
158+ $ targetUrl = KnownUser::generateTargetUrl ($ targetUrl );
159+ return KnownUser::_resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , $ queueConfig , $ customerId , $ secretKey );
160+ }
161+ private static function _resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , QueueEventConfig $ queueConfig , $ customerId , $ secretKey ) {
162+
163+ if (KnownUser::getIsDebug ($ queueitToken , $ secretKey ))
164+ {
165+ $ dic = array (
166+ "TargetUrl " => $ targetUrl ,
167+ "QueueitToken " => $ queueitToken ,
168+ "QueueConfig " =>$ queueConfig != null ? $ queueConfig ->getString () : "NULL " ,
169+ "OriginalUrl " => KnownUser::getHttpRequestProvider ()->getAbsoluteUri ());
170+ KnownUser::logMoreRequestDetails ($ dic );
171+ KnownUser::doCookieLog ($ dic );
172+ }
173+ if (Utils::isNullOrEmptyString ($ customerId )) {
174+ throw new KnownUserException ("customerId can not be null or empty. " );
175+ }
176+
177+ if (Utils::isNullOrEmptyString ($ secretKey )) {
178+ throw new KnownUserException ("secretKey can not be null or empty. " );
179+ }
180+
181+ if (Utils::isNullOrEmptyString ($ queueConfig ->eventId )) {
182+ throw new KnownUserException ("eventId from queueConfig can not be null or empty. " );
183+ }
187184
185+ if (Utils::isNullOrEmptyString ($ queueConfig ->queueDomain )) {
186+ throw new KnownUserException ("queueDomain from queueConfig can not be null or empty. " );
187+ }
188+
189+ if (!is_int ($ queueConfig ->cookieValidityMinute ) || intval ($ queueConfig ->cookieValidityMinute ) <= 0 ) {
190+ throw new KnownUserException ("cookieValidityMinute from queueConfig should be integer greater than 0. " );
191+ }
192+
193+ if (!is_bool ($ queueConfig ->extendCookieValidity )) {
194+ throw new KnownUserException ("extendCookieValidity from queueConfig should be valid boolean. " );
195+ }
196+
197+
198+ $ userInQueueService = KnownUser::getUserInQueueService ();
199+ $ result = $ userInQueueService ->validateQueueRequest ($ targetUrl , $ queueitToken , $ queueConfig , $ customerId , $ secretKey );
200+ $ result ->isAjaxResult = KnownUser::isQueueAjaxCall ();
201+ return $ result ;
202+ }
188203 private static function handleQueueAction (
189204 $ currentUrlWithoutQueueITToken , $ queueitToken ,
190205 $ customerIntegration , $ customerId ,
@@ -202,32 +217,33 @@ private static function handleQueueAction(
202217 $ eventConfig ->cookieValidityMinute = $ matchedConfig ["CookieValidityMinute " ];
203218 $ eventConfig ->version = $ customerIntegration ["Version " ];
204219
205- switch ($ matchedConfig ["RedirectLogic " ]) {
206- case "ForcedTargetUrl " :
207- case "ForecedTargetUrl " :
208- $ targetUrl = $ matchedConfig ["ForcedTargetUrl " ];
209- break ;
210- case "EventTargetUrl " :
211- $ targetUrl = "" ;
212- break ;
213- default :
214- $ targetUrl = $ currentUrlWithoutQueueITToken ;
215- }
216- return KnownUser::resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , $ eventConfig , $ customerId , $ secretKey );
217- }
220+ switch ($ matchedConfig ["RedirectLogic " ]) {
221+ case "ForcedTargetUrl " :
222+ case "ForecedTargetUrl " :
223+ $ targetUrl = $ matchedConfig ["ForcedTargetUrl " ];
224+ break ;
225+ case "EventTargetUrl " :
226+ $ targetUrl = "" ;
227+ break ;
228+ default :
229+ $ targetUrl = KnownUser::generateTargetUrl ($ currentUrlWithoutQueueITToken );
230+ }
231+
232+ return KnownUser::_resolveRequestByLocalEventConfig ($ targetUrl , $ queueitToken , $ eventConfig , $ customerId , $ secretKey );
233+ }
218234
219235 private static function handleCancelAction (
220236 $ currentUrlWithoutQueueITToken , $ queueitToken ,
221237 $ customerIntegration , $ customerId ,
222238 $ secretKey ,
223239 $ matchedConfig )
224240 {
225- $ cancelEventConfig = new CancelEventConfig ();
226- $ cancelEventConfig ->eventId = $ matchedConfig ["EventId " ];
227- $ cancelEventConfig ->queueDomain = $ matchedConfig ["QueueDomain " ];
228- $ cancelEventConfig ->cookieDomain = $ matchedConfig ["CookieDomain " ];
229- $ cancelEventConfig ->version = $ customerIntegration ["Version " ];
230- return KnownUser::cancelRequestByLocalConfig ($ currentUrlWithoutQueueITToken , $ queueitToken , $ cancelEventConfig , $ customerId , $ secretKey );
241+ $ cancelEventConfig = new CancelEventConfig ();
242+ $ cancelEventConfig ->eventId = $ matchedConfig ["EventId " ];
243+ $ cancelEventConfig ->queueDomain = $ matchedConfig ["QueueDomain " ];
244+ $ cancelEventConfig ->cookieDomain = $ matchedConfig ["CookieDomain " ];
245+ $ cancelEventConfig ->version = $ customerIntegration ["Version " ];
246+ return KnownUser::cancelRequestByLocalConfig ($ currentUrlWithoutQueueITToken , $ queueitToken , $ cancelEventConfig , $ customerId , $ secretKey );
231247 }
232248 private static function logMoreRequestDetails (array &$ debugInfos )
233249 {
@@ -276,6 +292,21 @@ private static function getIsDebug($queueitToken, $secretKey)
276292 }
277293 return false ;
278294 }
295+
296+ private static function generateTargetUrl ($ originalTargetUrl )
297+ {
298+ return !KnownUser::isQueueAjaxCall () ?
299+ $ originalTargetUrl :
300+ urldecode (KnownUser::getHttpRequestProvider ()->getHeaderArray ()[KnownUser::QueueITAjaxHeaderKey]);
301+ }
302+ private static function isQueueAjaxCall ()
303+ {
304+ return array_key_exists (KnownUser::QueueITAjaxHeaderKey,
305+ KnownUser::getHttpRequestProvider ()->getHeaderArray ());
306+
307+ }
308+
309+
279310}
280311
281312class CookieManager implements ICookieManager
0 commit comments