public function sendResponse()
  {
    # Set HTTP Response Code
    \http_response_code($this->getResponse()->getStatusCode());

    # Set All HTTP headers from Response Object
    foreach ($this->getResponse()->getHeaders() as $header => $value) {
      if (\is_array($value)) {
        $values = \implode(';',$value);
      } else {
        $values = $value;
      }

      \header($header.': '.$values);
    }

    # Remove the "x-powered-by" header set by PHP
    if (\function_exists('header_remove')) \header_remove('x-powered-by');

    # Set Cookies
    foreach ($this->cookies as $cookie)
    {
      \setCookie( $cookie['name'],
                  $cookie['value'],
                  $cookie['expire'] ?? 0,
                  $cookie['path'] ?? '',
                  $cookie['domain'] ?? '',
                  $cookie['secure'] ?? false,
                  $cookie['httponly'] ?? false
                );
    }

    ##
    ## Send a file or a body?
    ##
    if ( !empty($this->responseFile) ) {

      if (\file_exists($this->responseFile)) {
        # Debug log
        $this->getLogger()->debug('Sending file',[
          'code'=>$this->getResponse()->getStatusCode(),
          'headers'=>$this->getResponse()->getHeaders(),
          'file'=>$this->responseFile
        ]);

        # Send the file
        \readfile($this->responseFile);

      } else {
        # Log warning
        $this->getLogger()->warning('File not found',['file'=>$this->responseFile]);

        # Fake a response
        \response('',404);

        # Set HTTP Response Code
        \http_response_code(404);
      }

    } else {
      # Get body
      $body = (string)$this->response->getBody();

      # Debug log
      $this->getLogger()->debug('Sending body',[
        'code' => $this->getResponse()->getStatusCode(),
        'headers' => $this->getResponse()->getHeaders(),
        'size' => \strlen($body)
      ]);

      # Send the Body
      echo $body;
    }

    return $this;
  }
public function sendResponse()
  {
    # Set HTTP Response Code
    \http_response_code($this->getResponse()->getStatusCode());

    # Set All HTTP headers from Response Object
    foreach ($this->getResponse()->getHeaders() as $header => $value) {
      if (\is_array($value)) {
        $values = \implode(';',$value);
      } else {
        $values = $value;
      }

      \header($header.': '.$values);
    }

    # Remove the "x-powered-by" header set by PHP
    if (\function_exists('header_remove')) \header_remove('x-powered-by');

    # Set Cookies
    foreach ($this->cookies as $cookie)
    {
      \setCookie( $cookie['name'],
                  $cookie['value'],
                  $cookie['expire'] ?? 0,
                  $cookie['path'] ?? '',
                  $cookie['domain'] ?? '',
                  $cookie['secure'] ?? false,
                  $cookie['httponly'] ?? false
                );
    }

    ##
    ## Send a file or a body?
    ##
    if ( !empty($this->responseFile) ) {

      if (\file_exists($this->responseFile)) {
        # Debug log
        $this->getLogger()->debug('Sending file',[
          'code'=>$this->getResponse()->getStatusCode(),
          'headers'=>$this->getResponse()->getHeaders(),
          'file'=>$this->responseFile
        ]);

        # Send the file
        \readfile($this->responseFile);

      } else {
        # Log warning
        $this->getLogger()->warning('File not found',['file'=>$this->responseFile]);

        # Fake a response
        \response('',404);

        # Set HTTP Response Code
        \http_response_code(404);
      }

    } else {
      # Get body
      $body = (string)$this->response->getBody();

      # Debug log
      $this->getLogger()->debug('Sending body',[
        'code' => $this->getResponse()->getStatusCode(),
        'headers' => $this->getResponse()->getHeaders(),
        'size' => \strlen($body)
      ]);

      # Send the Body
      echo $body;
    }

    return $this;
  }
public function sendResponse ( ) { # Set HTTP Response Code \ http_response_code ( $ this -> getResponse ( ) -> getStatusCode ( ) ) ; # Set All HTTP headers from Response Object foreach ( $ this -> getResponse ( ) -> getHeaders ( ) as $ header => $ value ) { if ( \ is_array ( $ value ) ) { $ values = \ implode ( ';' , $ value ) ; } else { $ values = $ value ; } \ header ( $ header . ': ' . $ values ) ; } # Remove the "x-powered-by" header set by PHP if ( \ function_exists ( 'header_remove' ) ) \ header_remove ( 'x-powered-by' ) ; # Set Cookies foreach ( $ this -> cookies as $ cookie ) { \ setCookie ( $ cookie [ 'name' ] , $ cookie [ 'value' ] , $ cookie [ 'expire' ] ?? 0 , $ cookie [ 'path' ] ?? '' , $ cookie [ 'domain' ] ?? '' , $ cookie [ 'secure' ] ?? false , $ cookie [ 'httponly' ] ?? false ) ; } ## ## Send a file or a body? ## if ( ! empty ( $ this -> responseFile ) ) { if ( \ file_exists ( $ this -> responseFile ) ) { # Debug log $ this -> getLogger ( ) -> debug ( 'Sending file' , [ 'code' => $ this -> getResponse ( ) -> getStatusCode ( ) , 'headers' => $ this -> getResponse ( ) -> getHeaders ( ) , 'file' => $ this -> responseFile ] ) ; # Send the file \ readfile ( $ this -> responseFile ) ; } else { # Log warning $ this -> getLogger ( ) -> warning ( 'File not found' , [ 'file' => $ this -> responseFile ] ) ; # Fake a response \ response ( '' , 404 ) ; # Set HTTP Response Code \ http_response_code ( 404 ) ; } } else { # Get body $ body = ( string ) $ this -> response -> getBody ( ) ; # Debug log $ this -> getLogger ( ) -> debug ( 'Sending body' , [ 'code' => $ this -> getResponse ( ) -> getStatusCode ( ) , 'headers' => $ this -> getResponse ( ) -> getHeaders ( ) , 'size' => \ strlen ( $ body ) ] ) ; # Send the Body echo $ body ; } return $ this ; }
Send Response back to client

@return bool
Send Response back to client