-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
130 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* This file is part of the Glitch package | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
declare(strict_types=1); | ||
namespace DecodeLabs\Glitch; | ||
|
||
class Packet | ||
{ | ||
protected $body; | ||
protected $contentType; | ||
|
||
/** | ||
* Init with body and content type | ||
*/ | ||
public function __construct(string $body, string $contentType) | ||
{ | ||
$this->body = $body; | ||
$this->contentType = $contentType; | ||
} | ||
|
||
/** | ||
* Get body | ||
*/ | ||
public function getBody(): string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
/** | ||
* Get content type | ||
*/ | ||
public function getContentType(): string | ||
{ | ||
return $this->contentType; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* This file is part of the Glitch package | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
declare(strict_types=1); | ||
namespace DecodeLabs\Glitch\Transport; | ||
|
||
use DecodeLabs\Glitch\Transport; | ||
use DecodeLabs\Glitch\Packet; | ||
|
||
class Http implements Transport | ||
{ | ||
/** | ||
* Send dump straight to output | ||
*/ | ||
public function sendDump(Packet $packet, bool $final): void | ||
{ | ||
$this->sendPacket($packet, $final); | ||
} | ||
|
||
/** | ||
* Send exception dump straight to output | ||
*/ | ||
public function sendException(Packet $packet, bool $final): void | ||
{ | ||
$this->sendPacket($packet, $final); | ||
} | ||
|
||
/** | ||
* Send packet | ||
*/ | ||
protected function sendPacket(Packet $packet, bool $final): void | ||
{ | ||
if ($final && !headers_sent()) { | ||
header('HTTP/1.1 501'); | ||
header('Content-Type: '.$packet->getContentType().'; charset=UTF-8'); | ||
header('Cache-Control: no-cache, no-store, must-revalidate'); | ||
header('Pragma: no-cache'); | ||
|
||
if ($headerBufferSender = Glitch::getHeaderBufferSender()) { | ||
$headerBufferSender(); | ||
} | ||
} | ||
|
||
echo $packet->getBody(); | ||
} | ||
} |
This file contains 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