public function protectAndInject(
		string $tokenSharing = self::ONE_TOKEN_PER_PAGE
	):void {
		$forms = $this->document->forms;

		if($forms->length > 0) {
			$token = $this->tokenStore->generateNewToken();
			$this->tokenStore->saveToken($token);

			foreach($forms as $form) {
				$formMethod = $form->getAttribute("method");
				if(strtolower($formMethod) !== "post") {
					continue;
				}

				$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();
					$this->tokenStore->saveToken($token);
				}
			}
		}
		else {
			$token = $this->tokenStore->generateNewToken();
			$this->tokenStore->saveToken($token);
		}

		$meta = $this->document->querySelector(
			"head meta[name='" . self::TOKEN_NAME . "']"
		);

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

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

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

				$htmlElement->appendChild($head);
			}

			$head->appendChild($meta);
		}

		$meta->setAttribute("content", $token);
	}