Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Extract extra info from headers_sent #13

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Emitter/SapiEmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ trait SapiEmitterTrait
*/
private function assertNoPreviousOutput()
{
if (headers_sent()) {
throw EmitterException::forHeadersSent();
$file = $line = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define on separate lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you need ... if not, please specify

if (headers_sent($file, $line)) {
throw EmitterException::forHeadersSent($file, $line);
}

if (ob_get_level() > 0 && ob_get_length() > 0) {
Expand Down
10 changes: 8 additions & 2 deletions src/Exception/EmitterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

class EmitterException extends RuntimeException implements ExceptionInterface
{
public static function forHeadersSent() : self
public static function forHeadersSent(string $file, int $line) : self
{
return new self('Unable to emit response; headers already sent');
return new self(
sprintf(
'Unable to emit response; headers already sent, output started at %s:%d',
$file,
$line
)
);
}

public static function forOutputSent() : self
Expand Down