public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $session = $request->getSession();
     /* @var $session \Symfony\Component\HttpFoundation\Session\Session */
     $profiler = new Profiler($session, Profiler::LOG_PROFILING);
     if (in_array($response->getStatusCode(), [301, 302])) {
         $profiler->log('redirect', $response->headers->get('Location'));
         return;
     }
     $this->data['records'] = $profiler->getRecords();
 }
Example #2
0
 public function set($name, $value = null)
 {
     if (is_null($value)) {
         $this->profiler->debug('session.remove.' . $name);
         $this->session->remove($value);
     } else {
         if ($value instanceof Entity) {
             $value = $value->export();
         }
         $this->profiler->debug('session.set.' . $name, $value);
         $this->session->set($name, $value);
     }
 }
Example #3
0
 /**
  * @param $action
  * @param Entity $data
  * @return ApiResponse
  */
 public function request($action, Entity $data = null)
 {
     $apiRequest = new ApiRequest();
     $apiRequest->setAction($action)->setToken($this->token)->setUserToken($this->userToken)->setData($data);
     $this->profiler->log('api_client.' . $this->getName() . '.request', $apiRequest);
     $apiRequestContent = $apiRequest->__toString();
     curl_setopt($this->curl, CURLOPT_POSTFIELDS, $apiRequestContent);
     $this->logger->debug(sprintf('Api client %s: request "%s" >>> %s', $this->getName(), $action, $apiRequestContent));
     $result = curl_exec($this->curl);
     $responseData = json_decode($result, true);
     $apiResponse = new ApiResponse($responseData);
     $this->profiler->log('api_client.' . $this->getName() . '.response', $apiResponse);
     $newUserToken = $apiResponse->getUserToken();
     if ($newUserToken) {
         $this->profiler->log('api_client.' . $this->getName() . '.new_token', $newUserToken);
         $this->userToken = $newUserToken;
         foreach ($this->newUserTokenListeners as $userTokenListener) {
             /* @var $userTokenListener NewUserTokenListenerInterface */
             $userTokenListener->setNewUserToken($newUserToken);
         }
     }
     $this->logger->debug(sprintf('Api client %s: %s response >>> %s', $this->getName(), $apiResponse->getStatus() ? 'SUCCESS' : 'FAIL', $result));
     return $apiResponse;
 }