/** * returns a not authenticated response * * @param string $message localized message * @param string $returnCode return code (e.g. not_authenticated) * @param array $data optional data * @return Cake\Network\Response */ public function notAuthenticated($message = null, $returnCode = null, $data = []) { if (empty($returnCode)) { $returnCode = ApiReturnCode::NOT_AUTHENTICATED; } if (empty($message)) { $message = __d('notifications', 'auth_error'); } $statusCode = ApiReturnCode::getStatusCodeMapping()[$returnCode]; $this->response->statusCode($statusCode); $responseData = ['code' => $returnCode, 'message' => $message, 'data' => $data]; $this->response->type('json'); $this->response->body(json_encode($responseData)); return $this->response; }
/** * Constructor hook method. * * Implement this method to avoid having to overwrite * the constructor and call parent. * * @param array $config The configuration settings provided to this component. * @return void */ public function initialize(array $config) { $this->_statusCodeMapping = ApiReturnCode::getStatusCodeMapping(); }