Skip to content

Commit

Permalink
Wrap Dom Document required elements
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Dec 17, 2014
1 parent 83c258f commit 8a495b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/Cli/Gateway.php
Expand Up @@ -22,10 +22,6 @@ class Gateway {
* @return mixed An instance of the $phpgt class
*/
public static function serve($uri, $phpgt = "\Gt\Core\Start") {
// Will be overridden by ResponseContent. text/plain used for
// early-finishing scripts.
header("Content-type: text/plain");

if(self::isStaticFileRequest($uri)) {
$filePath = self::getAbsoluteFilePath($uri);
self::serveStaticFile($filePath);
Expand Down
21 changes: 19 additions & 2 deletions src/Dom/Document.php
Expand Up @@ -137,6 +137,23 @@ public function __construct($source = null, $config = null) {
$uuid = uniqid("nodeMap-", true);
$this->domDocument->uuid = $uuid;

// Find and reference the DOCTYPE element:
foreach ($this->childNodes as $rootChild) {
if($rootChild->nodeType === XML_DOCUMENT_TYPE_NODE) {
$rootChild->description = "DOCTYPE NODE";
}
}

$htmlNodeList = $this->getElementsByTagName("html");
if(count($htmlNodeList) === 0) {
$htmlNode = $this->document->createElement("html");
$this->document->appendChild($htmlNode);
}
else {
$htmlNode = $htmlNodeList[0];
}
$htmlNode = Node::wrapNative($htmlNode);

// Check the head and body tags exist in the document, no matter what.
$requiredRootTagArray = ["head", "body"];
foreach ($requiredRootTagArray as $tag) {
Expand All @@ -146,8 +163,8 @@ public function __construct($source = null, $config = null) {
}
else {
$this->$tag = $this->createElement($tag);
$this->insertBefore(
$this->$tag, $this->firstChild);
$htmlNode->insertBefore(
$this->$tag, $htmlNode->firstChild);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Dom/Node.php
Expand Up @@ -146,6 +146,10 @@ public function __set($name, $value) {
$this->setAttribute("class", $value);
break;

case "description":
$this->description = $value;
break;

case "textContent":
case "innerText":
$value = htmlentities($value, ENT_COMPAT | ENT_HTML5);
Expand Down

0 comments on commit 8a495b5

Please sign in to comment.