예제 #1
0
 /**
  * Will call for the measurement protocol endpoint
  *
  * @param \AppserverIo\Psr\HttpMessage\RequestInterface          $request        A request object
  * @param \AppserverIo\Psr\HttpMessage\ResponseInterface         $response       A response object
  * @param \AppserverIo\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  *
  * @return null
  */
 public function call(RequestInterface $request, ResponseInterface $response, RequestContextInterface $requestContext)
 {
     // merge default and configured parameters into our list
     $parameters = array_merge($this->defaultParameters, $this->parameters);
     // we want the request to be like it came from the same host, so we will reuse part of it
     $parameters['ua'] = $request->getHeader(HttpProtocol::HEADER_USER_AGENT);
     $parameters['uip'] = $requestContext->getServerVar(ServerVars::REMOTE_ADDR);
     // the client will be a random UUID, at least if we do not get a matching cookie
     if ($request->hasHeader(HttpProtocol::HEADER_COOKIE)) {
         // the user is known to us
         $cookie = $request->getHeader(HttpProtocol::HEADER_COOKIE);
         $matches = array();
         preg_match('/_ga=GA[0-9]\\.[0-9]\\.(.+)/', $cookie, $matches);
         if (isset($matches[1])) {
             $parameters['cid'] = $matches[1];
             // remove the cookie to avoid additional calls
             $response->removeCookie('_ga');
             // filter the parameters for a known cookie
             $parameters = $this->filterParameters($parameters, self::COOKIE_PRESENT);
         }
     }
     // if there is no known client id we will set one randomly
     if (!isset($parameters['cid'])) {
         $uuid4 = Uuid::uuid4();
         $parameters['cid'] = $uuid4->toString();
         // filter the parameters for usage without cookie
         $parameters = $this->filterParameters($parameters, self::COOKIE_NOT_PRESENT);
     }
     // make the actual call
     $this->sendToService($parameters);
 }