Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Dec 4, 2018
1 parent 4be8431 commit 293a0c1
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/HTMLDocumentProtector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ public function protectAndInject(
$this->tokenStore->saveToken($token);

foreach($forms as $form) {
$csrfElement = $this->document->createElement("input");
$csrfElement->setAttribute("name", static::TOKEN_NAME);
$csrfElement->setAttribute("value", $token);
$csrfElement->setAttribute("type", "hidden");
$form->insertBefore($csrfElement, $form->firstChild);
$csrfElement = $this->document->createElement(
"input"
);
$csrfElement->setAttribute(
"name",
static::TOKEN_NAME
);
$csrfElement->setAttribute(
"value",
$token
);
$csrfElement->setAttribute(
"type",
"hidden"
);
$form->insertBefore(
$csrfElement,
$form->firstChild
);

if($tokenSharing === self::ONE_TOKEN_PER_FORM) {
$token = $this->tokenStore->generateNewToken();
Expand All @@ -78,12 +92,23 @@ public function protectAndInject(

if(is_null($meta)) {
$meta = $this->document->createElement("meta");
$meta->setAttribute("name", self::TOKEN_NAME);
$meta->setAttribute(
"name",
self::TOKEN_NAME
);

$head = $this->document->querySelector(
"head"
);

$head = $this->document->querySelector("head");
if(is_null($head)) {
$head = $this->document->createElement("head");
$htmlElement = $this->document->querySelector("html");
$head = $this->document->createElement(
"head"
);
$htmlElement = $this->document->querySelector(
"html"
);

$htmlElement->appendChild($head);
}

Expand Down

0 comments on commit 293a0c1

Please sign in to comment.