Inject WPFunctions to FieldNameObfuscator using DI

[MAILPOET-2665]
This commit is contained in:
Rostislav Wolny
2020-01-30 11:54:52 +01:00
committed by Jack Kitterhing
parent 7d596e3407
commit d0acad5c3b
5 changed files with 36 additions and 26 deletions

View File

@ -9,9 +9,16 @@ class FieldNameObfuscator {
const OBFUSCATED_FIELD_PREFIX = 'form_field_';
const HASH_LENGTH = 12;
/** @var WPFunctions */
private $wp;
public function __construct(WPFunctions $wp) {
$this->wp = $wp;
}
public function obfuscate($name) {
$authKey = defined('AUTH_KEY') ? AUTH_KEY : '';
$hash = substr(md5($authKey . WPFunctions::get()->homeUrl() . $name), 0, self::HASH_LENGTH);
$hash = substr(md5($authKey . $this->wp->homeUrl() . $name), 0, self::HASH_LENGTH);
return self::OBFUSCATED_FIELD_PREFIX . base64_encode($hash . '_' . $name);
}