protected static function KeyProviderBase::obscureValue in Key 8
Helper method to obscure a value.
Parameters
string $key_value: The key value to obscure.
array $options: Options to use when obscuring the value.
Return value
string The obscured key value.
1 call to KeyProviderBase::obscureValue()
- KeyProviderBase::obscureKeyValue in src/
Plugin/ KeyProviderBase.php - Obscures a key value.
File
- src/
Plugin/ KeyProviderBase.php, line 47
Class
- KeyProviderBase
- Defines a base class for Key Provider plugins.
Namespace
Drupal\key\PluginCode
protected static function obscureValue($key_value, array $options = []) {
// Add default options.
$options += [
'replacement_character' => '*',
'fixed_length' => '',
'visible_right' => 4,
];
if ($options['visible_right'] > 0) {
$visible_right_chars = substr($key_value, $options['visible_right'] * -1);
}
else {
$visible_right_chars = '';
}
$obscured_chars = '';
if ($options['fixed_length']) {
$obscured_chars = str_repeat($options['replacement_character'], $options['fixed_length'] - $options['visible_right']);
}
elseif (strlen($key_value) - $options['visible_right'] > 0) {
$obscured_chars = str_repeat($options['replacement_character'], strlen($key_value) - $options['visible_right']);
}
return $obscured_chars . $visible_right_chars;
}