This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔔 Add XML debugger, Dispatcher->test(Receipt, bool): void
- Loading branch information
1 parent
8e20cd4
commit 478eebd
Showing
2 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace FilipSedivy\EET\Utils\Debugger; | ||
|
||
use DOMDocument; | ||
|
||
class LastRequest | ||
{ | ||
private const SENSITIVE_TAGS = [ | ||
'DigestValue', | ||
'SignatureValue', | ||
'BinarySecurityToken' | ||
]; | ||
|
||
/** @var bool */ | ||
public $highlight = true; | ||
|
||
/** @var bool */ | ||
public $format = true; | ||
|
||
/** @var bool */ | ||
public $hiddenSensitiveData = true; | ||
|
||
/** @var string */ | ||
public $sensitiveValue = '**** CENSURE ****'; | ||
|
||
/** @var string */ | ||
private $lastRequest; | ||
|
||
public function __construct(string $lastRequest) | ||
{ | ||
$this->lastRequest = $lastRequest; | ||
} | ||
|
||
public function out(): void | ||
{ | ||
if ($this->hiddenSensitiveData) { | ||
$this->doHiddenSensitiveData(); | ||
} | ||
|
||
if ($this->format) { | ||
$this->doFormat(); | ||
} | ||
|
||
if ($this->highlight) { | ||
$this->doHighlight(); | ||
} | ||
|
||
printf('<pre>%s</pre>', $this->lastRequest); | ||
} | ||
|
||
private function doFormat(): void | ||
{ | ||
$dom = new DOMDocument; | ||
|
||
$dom->preserveWhiteSpace = false; | ||
$dom->formatOutput = true; | ||
|
||
$dom->loadXML($this->lastRequest); | ||
|
||
$this->lastRequest = $dom->saveXML(); | ||
} | ||
|
||
private function doHighlight(): void | ||
{ | ||
$s = htmlspecialchars($this->lastRequest); | ||
|
||
$s = preg_replace("#<([/]*?)(.*)([\s]*?)>#sU", | ||
"<span style=\"color: #0000FF\"><\\1\\2\\3></span>", $s); | ||
|
||
$s = preg_replace("#<([\?])(.*)([\?])>#sU", | ||
"<span style=\"color: #800000\"><\\1\\2\\3></span>", $s); | ||
|
||
$s = preg_replace("#<([^\s\?/=])(.*)([\[\s/]|>)#iU", | ||
"<<span style=\"color: #808000\">\\1\\2</span>\\3", $s); | ||
|
||
$s = preg_replace("#<([/])([^\s]*?)([\s\]]*?)>#iU", | ||
"<\\1<span style=\"color: #808000\">\\2</span>\\3>", $s); | ||
|
||
$s = preg_replace("#([^\s]*?)\=("|')(.*)("|')#isU", | ||
"<span style=\"color: #800080\">\\1</span>=<span style=\"color: #FF00FF\">\\2\\3\\4</span>", $s); | ||
|
||
$s = preg_replace("#<(.*)(\[)(.*)(\])>#isU", | ||
"<\\1<span style=\"color: #800080\">\\2\\3\\4</span>>", $s); | ||
|
||
$this->lastRequest = nl2br($s); | ||
} | ||
|
||
private function doHiddenSensitiveData(): void | ||
{ | ||
$dom = new DOMDocument; | ||
$dom->loadXML($this->lastRequest); | ||
|
||
foreach (self::SENSITIVE_TAGS as $tag) { | ||
$nodeList = $dom->getElementsByTagName($tag); | ||
|
||
for ($i = 0; $i < $nodeList->length; $i++) { | ||
$node = $nodeList->item($i); | ||
$node->nodeValue = $this->sensitiveValue; | ||
} | ||
} | ||
|
||
$this->lastRequest = $dom->saveXML(); | ||
} | ||
} |