Elgg\Ajax\Service::isReady PHP Method

isReady() public method

Some code paths involve multiple layers of handling (e.g. router calls actions/ajax views) so we must check whether the response has already been sent to avoid sending it twice. We can't use headers_sent() because Router needs to use output buffering.
public isReady ( ) : boolean
return boolean
    public function isReady()
    {
        return !$this->response_sent && $this->isAjax2Request();
    }

Usage Example

コード例 #1
0
ファイル: ResponseFactory.php プロジェクト: elgg/elgg
 /**
  * Send OK response
  *
  * @param string $content     Response body
  * @param int    $status_code HTTP status code
  * @param array  $headers     HTTP headers (will be discarded for AJAX requets)
  * @return type
  */
 public function respondFromContent($content = '', $status_code = ELGG_HTTP_OK, array $headers = [])
 {
     if ($this->ajax->isReady()) {
         $hook_type = $this->parseContext();
         // $this->ajax->setStatusCode($status_code);
         return $this->send($this->ajax->respondFromOutput($content, $hook_type));
     }
     return $this->send($this->prepareResponse($content, $status_code, $headers));
 }