示例#1
0
文件: Controller.php 项目: locphp/rsf
 /**
  * @param array $data
  * @param int $code
  */
 protected function repjson($data = [], $code = 200)
 {
     if ($code !== 200) {
         $this->response->withStatus($code, Http\Http::getStatus($code));
     }
     $this->response->withHeader('Content-Type', 'application/json; charset=' . getini('site/charset'));
     $data = $data ? output_json($data) : '';
     $this->response->write($data);
 }
示例#2
0
 public function parseHTTP(\EventHttpRequest $eventHTTPRequest)
 {
     $this->setEventHTTPRequest($eventHTTPRequest);
     $headers = $eventHTTPRequest->getInputHeaders();
     $server = array('REQUEST_URI' => $eventHTTPRequest->getUri());
     list($server['REMOTE_ADDR'], $server['REMOTE_PORT']) = $this->getRemote();
     $server['REQUEST_METHOD'] = array_search($eventHTTPRequest->getCommand(), array('GET' => \EventHttpRequest::CMD_GET, 'POST' => \EventHttpRequest::CMD_POST, 'HEAD' => \EventHttpRequest::CMD_HEAD, 'PUT' => \EventHttpRequest::CMD_PUT, 'DELETE' => \EventHttpRequest::CMD_DELETE, 'OPTIONS' => \EventHttpRequest::CMD_OPTIONS, 'TRACE ' => \EventHttpRequest::CMD_TRACE, 'CONNECT ' => \EventHttpRequest::CMD_CONNECT, 'PATCH ' => \EventHttpRequest::CMD_PATCH));
     $request = Http\Http::parseRequest($server, $headers, $eventHTTPRequest->getInputBuffer()->read(static::MAX_INPUT));
     $request->setConnection($this);
     $this->setRequest($request);
     Http\Http::handleRequest($request);
     $this->prepareEventGroup();
     $this->emitPendingEvent();
     $this->dispatchQueueEventEvent();
 }
 /**
  * Track information.
  * Updates all the cookies, makes a server side request to Google Analytics.
  *
  * Defenitions of the Analytics Parameters are stored at:
  * http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html
  * http://www.cheatography.com/jay-taylor/cheat-sheets/google-analytics-utm-parameters-v2/
  *
  * @param array $extraParams
  * @return boolean|GoogleAnalyticsServerSide
  */
 private function track(array $extraParams = array())
 {
     if ($this->botInfo !== null && $this->botInfo->isBot()) {
         return false;
     }
     $account = (string) $this->getAccount();
     if (empty($account)) {
         throw new Exception\DomainException('The account number must be set before any tracking can take place.');
     }
     $domainName = (string) $this->getServerName();
     $documentReferer = (string) $this->getDocumentReferer();
     $documentReferer = empty($documentReferer) && $documentReferer !== '0' ? '-' : urldecode($documentReferer);
     $this->setCookies();
     // Construct the gif hit url.
     $queryParams = array('utmwv' => $this->getVersion(), 'utmn' => rand(0, 0x7fffffff), 'utmhn' => $domainName, 'utmr' => $documentReferer, 'utmac' => $account, 'utmcc' => $this->getCookiesString(), 'utmul' => $this->getAcceptLanguage(), 'utmcs' => $this->getCharset(), 'utmu' => 'q~');
     if (0 === strpos($account, 'MO-')) {
         $queryParams['utmip'] = $this->getIPToReport();
     }
     $queryParams = array_merge($queryParams, $extraParams);
     if (null !== ($customVarString = $this->getCustomVariableString())) {
         $queryParams['utme'] = (isset($queryParams['utme']) && !empty($queryParams['utme']) ? $queryParams['utme'] : '') . $customVarString;
     }
     $utmUrl = self::GIF_URL . '?' . http_build_query($queryParams, null, '&');
     Http\Http::request($utmUrl);
     return $this;
 }