for a given string message, prepare a basic json response for the browser

@param string $message
338520
private function _send($message)
    {
        // Errors come from HTTPException. This helps set the proper envelope data
        /** @var Response $response */
        $response = $this->di->get('response');
        $response->setStatusCode($this->httpCode, $this->httpMessage);

        // HEAD does everything exactly the same as GET, but contains no body
        // empty responses (such as a 204 result) should also skip JSON configuration
        if ($this->head || !$message) {
            $response->setContentType(null); //forces content-type to not be sent
        } else {
            $jsonConfig = $this->di->get('config')['application']['debugApp'] ? JSON_PRETTY_PRINT : 0;
            $response->setJsonContent($message, $jsonConfig);
        }

        $response->send();
    }
603533
public static function processMessage(string $message, $replace) : string {
		if (is_json($replace)) {
			$replace = json_decode($replace, true);
		}
		foreach ($replace as $k => $v) {
			if (is_string($v)) {
				if (substr($v, 0, 2) == '~~') {
					$v = substr($v, 2);
				} else {
					$v = i18n(null, $v);
				}
			} else {
				$v = \Format::id($v);
			}
			$replace[$k] = $v;
		}
		return i18n(null, $message, ['replace' => $replace]);
	}
1333585
function json($data = '', $code = 0, $message = '')
    {
        $json = array('code' => $code, 'message' => $message, 'data' => $data);
        if (!empty($_REQUEST['jsonp']))
        {
            $this->http->header('Content-type', 'application/x-javascript');
            return $_REQUEST['jsonp'] . "(" . json_encode($json) . ");";
        }
        else
        {
            $this->http->header('Content-type', 'application/json');
            return json_encode($json);
        }
    }
649247
public static function write($message){
      if( preg_match('~<[^>]+>~',$message)) {
         // Use preg_replace_callback for fast regex matches navigation
         echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
            static::write($m[1]);
            $color = strtoupper(trim($m[2]));
            if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
            static::$color_stack[] = $color;
            static::write($m[3]);
            array_pop(static::$color_stack);
            $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL';
            if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color];
            static::write($m[4]);
         },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]);
      } else {
         echo strtr($message,["&BR;"=>PHP_EOL]);
      }
   }
684602
public static function respond($status = 404, $message = '') {
        http_response_code($status);
        if (Request::isAjaxRequest()) {
            @header('ajax: 1');
            Response::getInstance()->output(['message' => $message ? $message : __('error occurred')]);
            Response::getInstance()->close();
        } else {
            if ($status == 404) {
                $data ['message'] = $message;
                $view             = template('404.tpl', $data);
            } else if ($status == 403) {
                $data ['message'] = $message;
                $view             = template('403.tpl', $data);
            } else if ($status == 500) {
                $data ['message'] = $message;
                $view             = template('500.tpl', $data);
            } else if ($status == 503) {
                $data ['message'] = $message;
                $view             = template('503.tpl', $data);
            } else if ($message) {
                if (is_array($message)) {
                    $view = new JsonView($message);
                } else {
                    $view = new SimpleView($message);
                }
            } else {
                $view = null;
            }
            if ($view) {
                Response::getInstance()->output($view);
                Response::getInstance()->close();
            }
        }
        exit (1);
    }
1368763
public function respondWithMessage($message = "Ok")
    {
        $data = $this->getResponseStructure(true, null, $message);

        return $this->respond($data);
    }
1342014
private static function prepare( $type, $message )
	{
		// to avoid typos and other mistakes we 
		// validate the alert type
		$type = strtolower( $type );
		if ( !in_array( $type, static::$_types ) ) 
		{
			throw new Exception( "UI\Alert - Unknown alert type '{$type}'!" );
		}

		// We always need to return an array
		if ( !is_array( $message ) )
		{
			return array( $message );
		}
		return $message;
	}
277945
public function sendMessage(Message $message): void
    {
        // Ensure the message will always be sent to the default channel if asked for.
        if ($this->options['sticky_channel']) {
            $message->setChannel($this->options['channel']);
        }

        $payload = $this->preparePayload($message);

        $encoded = \json_encode($payload, JSON_UNESCAPED_UNICODE);

        if (false === $encoded) {
            throw new \RuntimeException(\sprintf('JSON encoding error %s: %s', \json_last_error(), \json_last_error_msg()));
        }

        $this->httpClient->post('', [], $encoded);
    }
23576
private function formatMessage(&$message)
    {
        if ($this->extraMessage) {
            $message = array_merge($message, $this->extraMessage->toArray());
        }

        foreach ($this->options as $option => $value) {
            Arr::set($message, $option, $value);
        }
    }
232343
public function respondCreated($message = "Created")
    {
        $reponse = $this->setStatusCode(ResponseHTTP::HTTP_CREATED)
            ->respondWithMessage($message);
        return $reponse;
    }
773717
protected function stringifyMessage($message)
    {
        if (is_array($message) || is_object($message) || is_bool($message)) {
            return (string)var_export($message, true);
        }
        return (string)$message;
    }
1187124
private function _setHistory($message) {
        $this->addError('URL : http://' . $this->request->env('HTTP_HOST') . $this->request->env('REQUEST_URI') . ' (' . $this->response->status() . ') / SRC "' . $this->request->src . '" / CONTROLLER "' . $this->request->controller . '" / ACTION "' . $this->request->action . '" / CACHE "' . $this->request->cache . '" / ORIGIN : ' . $this->request->env('HTTP_REFERER') . ' / IP : ' . $this->request->env('REMOTE_ADDR') . ' / ' . $message, 0, 0, 0, LOG_HISTORY);
    }
757200
protected function prepareMessage($message)
    {
        list($text, $level, $category, $timestamp) = $message;

        $level = Logger::getLevelName($level);
        $timestamp = date('c', $timestamp);

        $result = ArrayHelper::merge(
            $this->parseText($text),
            ['level' => $level, 'category' => $category, '@timestamp' => $timestamp]
        );

        if (isset($message[4]) === true) {
            $result['trace'] = $message[4];
        }

        return $result;
    }
515018
public function onWorkerReplyMessage(string $message)
    {
        try {
            $data = json_decode($message, true);
            if (empty($data) || !isset($data['request'])) {
                throw new ServerException('Invalid worker request received.');
            }
            $result = null;
            switch ($data['request']) {
                case 'register_job':
                    $result = $this->registerJob($data['job_name'], $data['worker_id']);
                    break;
                case 'unregister_job':
                    $result = $this->unregisterJob($data['job_name'], $data['worker_id']);
                    break;
                case 'change_state':
                    $result = $this->changeWorkerState($data['worker_id'], $data['state']);
                    break;
                case 'job_completed':
                    $this->onJobCompleted($data['worker_id'], $data['job_id'], $data['result']);
                    break;
            }
            $response = ($result === true) ? 'ok' : 'error';
            $this->workerReplySocket->send($response);
        } catch (ServerException $e) {
            $errorMsgPattern = 'Worker message error: %s (%s:%d)';
            $this->logger->error(sprintf($errorMsgPattern, $e->getMessage(), $e->getFile(), $e->getLine()));
        }
    }
1337803
public static function success($message = '', $style = null) {
		if (is_array($message)) {
			$msg     = unget($message, 'message');
			$args    = $message;
			$message = $msg ? $msg : '';
		} else {
			$args = [];
		}

		return new JsonView([
			'code'    => self::SUCCESS,
			'message' => $message,
			'args'    => $args,
			'style'   => $style
		], ['ajax' => '1']);
	}
436285
public function Message($Message) {
   
      // htmlspecialchars_decode is being used here to revert any specialchar escaping done by Gdn_Format::Text()
      // which, untreated, would result in &#039; in the message in place of single quotes.
   
      if ($this->PhpMailer->ContentType == 'text/html') {
         $TextVersion = FALSE;
         if (stristr($Message, '<!-- //TEXT VERSION FOLLOWS//')) {
            $EmailParts = explode('<!-- //TEXT VERSION FOLLOWS//', $Message);
            $TextVersion = array_pop($EmailParts);
            $Message = array_shift($EmailParts);
            $TextVersion = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$TextVersion)));
            $Message = trim($Message);
         }
         
         $this->PhpMailer->MsgHTML(htmlspecialchars_decode($Message,ENT_QUOTES));
         if ($TextVersion !== FALSE && !empty($TextVersion)) {
            $TextVersion = html_entity_decode($TextVersion);
            $this->PhpMailer->AltBody = $TextVersion;
         }
      } else {
         $this->PhpMailer->Body = htmlspecialchars_decode($Message,ENT_QUOTES);
      }
      return $this;
   }
232376
public function prepareForResponse(Response $response) {
		if ('application/json' == $response->getRequest()->getAcceptRange()
	               ->bestMatch(['text/html', 'application/json'])) {
            	$this->payload = new JhtmlJsonPayload($this->additionalAttrs);
               	$this->payload->applyRedirect($this->directive, $this->httpLocation, $this->jhtmlExec);
			$this->payload->prepareForResponse($response);
	        return;
	    } 
	    
		$this->payload = new Redirect($this->httpLocation);
		$this->payload->prepareForResponse($response);
	}