Commit 4ed0025f authored by Mark Harding's avatar Mark Harding

(fix): move create referral cookie step to shutdown function vs api result

parent 8450551b
Pipeline #83834341 passed with stages
in 10 minutes and 49 seconds
......@@ -146,9 +146,6 @@ class Factory
*/
public static function response($data = [])
{
Di::_()->get('Referrals\Cookie')
->create();
$data = array_merge([
'status' => 'success', //should success be assumed?
], $data);
......
......@@ -16,6 +16,14 @@ class ReferralCookie
/** @var Entity */
private $entity;
public function __construct()
{
register_shutdown_function(function () {
error_log('shutdown called');
$this->create();
});
}
/**
* Set the router request
* @param Request $request
......@@ -45,7 +53,9 @@ class ReferralCookie
*/
public function create(): void
{
error_log('referral create function called!');
if (!$this->request) {
error_log('no request');
return;
}
......@@ -53,12 +63,14 @@ class ReferralCookie
$params = $this->request->getQueryParams();
if (isset($cookies['referrer'])) {
error_log('found referrer cookie');
return; // Do not override previosuly set cookie
}
$referrerGuid = null;
if (isset($params['referrer'])) { // Is a referrer param set in the request?
error_log('referrer param is ' . $params['referrer']);
$referrerGuid = $params['referrer'];
} elseif ($this->entity) { // Was an entity set?
switch (get_class($this->entity)) {
......@@ -80,5 +92,10 @@ class ReferralCookie
->create();
$_COOKIE['referrer'] = $referrerGuid; // TODO: replace with Response object later
}
error_log("referrerGuid is $referrerGuid");
error_log(print_r($params, true));
error_log(print_r($this->request, true));
error_log(print_r($this->entity, true));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment