Created
December 19, 2012 22:16
-
-
Save jeserkin/4341055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param bool $throw | |
| * @throws RuntimeException | |
| * @return bool | |
| */ | |
| private function canSendHeaders( $throw = false ) | |
| { | |
| $result = headers_sent( $inFile, $atLine ); | |
| if ( $result && $throw ) | |
| { | |
| throw new RuntimeException( "Headers already sent in file: {$inFile} at line {$atLine}" ); | |
| } | |
| return ! $result; | |
| } | |
| /** | |
| * @return void | |
| */ | |
| public function sendResponse() | |
| { | |
| $this->sendHeaders(); | |
| $this->sendContent(); | |
| } | |
| /** | |
| * @return void | |
| */ | |
| public function sendHeaders() | |
| { | |
| if ( ! $this->canSendHeaders( true ) ) | |
| { | |
| return; | |
| } | |
| header( 'HTTP/1.0 ' . $this->statusCode . ' ' . $this->statusText ); | |
| if ( ! in_array( 'Content-Type', $this->httpHeaders ) ) | |
| { | |
| header( 'Content-Type: ' . $this->contentType . ( empty( $this->charset ) ? '' : '; charset=' . $this->charset ) ); | |
| } | |
| foreach ( $this->httpHeaders as $headerName => $headerValue ) | |
| { | |
| header( $headerName . ': ' . $headerValue ); | |
| } | |
| } | |
| /** | |
| * @return void | |
| */ | |
| public function sendContent() | |
| { | |
| echo $this->content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment