From 32a7e57e02a2c887a13350363c65049d67032fc2 Mon Sep 17 00:00:00 2001 From: schmittrigger Date: Mon, 13 Mar 2017 16:41:57 +0100 Subject: [PATCH] [APISDK-5] Added device fingerprint builder as frontend service --- src/Exception/FrontendException.php | 16 +++ src/Frontend/DeviceFingerprintBuilder.php | 128 ++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 src/Exception/FrontendException.php create mode 100644 src/Frontend/DeviceFingerprintBuilder.php diff --git a/src/Exception/FrontendException.php b/src/Exception/FrontendException.php new file mode 100755 index 0000000..0a4cc0b --- /dev/null +++ b/src/Exception/FrontendException.php @@ -0,0 +1,16 @@ +setSnippetId($snippetId); + } else { + throw new FrontendException("DeviceFingerprintBuilder: Snippet id must be set"); + } + + if (!empty($uniqueIdentifier)) { + $this->createToken($uniqueIdentifier); + } else { + throw new FrontendException("DeviceFingerprintBuilder: Transaction identifier must be set"); + } + } + + /** + * @param string $snippetId + */ + public function setSnippetId($snippetId) + { + $this->snippetId = $snippetId; + } + + /** + * Sets DFP token + * + * @param string $token + */ + public function setToken($token) + { + $this->token = $token; + } + + /** + * Returns DFP token + * + * @return string + */ + public function getToken() + { + return $this->token; + } + + /** + * Returns DFP snippet code (JS code) + * @return string + */ + public function getDfpSnippetCode($smarty = false) + { + $snippet = sprintf( + (!$smarty) ? "" : "", + json_encode([ + 't' => $this->token, + 'v' => $this->snippetId, + 'l' => $this->location + ]) + ); + + $snippet .= sprintf( + "", + $this->uri, + $this->snippetId + ); + + $snippet .= sprintf( + "", + $this->uri, + $this->token, + $this->snippetId, + $this->location + ); + + return $snippet; + } + + /** + * Creates unique token + * + * @param $uniqueIdentifier + */ + private function createToken($uniqueIdentifier) { + $this->token = md5($this->snippetId . "_" . $uniqueIdentifier . "_" . microtime()); + } + +} \ No newline at end of file