Encryptable
Encryptable model behavior
class Winter\Storm\Database\Behaviors\Encryptable
extends Winter\Storm\Extension\ExtensionBase
Usage:
In the model class definition:
public $implement = [
\Winter\Storm\Database\Behaviors\Encryptable::class,
];
/**
* List of attributes to encrypt.
* /
protected array $encryptable = ['api_key', 'api_secret'];
Dynamically attached to third party model:
TargetModel::extend(function ($model) {
$model->addDynamicProperty('encryptable', ['encrypt_this']);
$model->extendClassWith(\Winter\Storm\Database\Behaviors\Encryptable::class);
});
NOTE: Encrypted attributes will be serialized and unserialized as a part of the encryption / decryption process. Do not make an attribute that is encryptable also jsonable at the same time as the jsonable process will attempt to decode a value that has already been unserialized by the encrypter.
Extends
Class | Description |
---|---|
ExtensionBase
|
Extension class Allows for "Private traits" |
Traits
Trait | Description |
---|---|
ExtensionTrait
|
Extension trait |
Properties
protected
$encrypterInstance
:
Illuminate\Contracts\Encryption\Encrypter
|
null
= null
Encrypter instance.
protected $model : Winter\Storm\Database\Model
protected
$originalEncryptableValues
:
array
= []
List of original attribute values before they were encrypted.
inherited
public
static
$extendableStaticCalledClass
:
string
= null
The calling class when using a static method.
inherited
protected
static
$extensionCallbacks
:
array
= []
Used to extend the constructor of an extension class. Eg:
BehaviorClass::extend(function($obj) { })
inherited
protected
$extensionHidden
:
mixed
= {"fields":[],"methods":["extensionIsHiddenField","extensionIsHiddenMethod"]}
Methods
public __construct ($parent)
Property | Type | Description |
---|---|---|
$parent | mixed |
mixed
|
public bootEncryptable () : void
Boot the encryptable trait for a model.
public getEncryptableAttributes () : array
Returns a collection of fields that will be encrypted.
public getEncryptableValue (string $key)
Decrypts an attribute value
Property | Type | Description |
---|---|---|
$key | string |
string
|
public getEncrypter () : Illuminate\Contracts\Encryption\Encrypter
Provides the encrypter instance.
public getOriginalEncryptableValue (string $attribute)
Returns the original values of any encrypted attributes.
Property | Type | Description |
---|---|---|
$attribute | string |
string
|
public getOriginalEncryptableValues () : array
Returns the original values of any encrypted attributes.
public makeEncryptableValue (string $key, $value) : string
Encrypts an attribute value and saves it in the original locker.
Property | Type | Description |
---|---|---|
$key | string |
string
|
$value | mixed |
mixed
|
public setEncrypter (Illuminate\Contracts\Encryption\Encrypter $encrypter) : void
Sets the encrypter instance.
Property | Type | Description |
---|---|---|
$encrypter | Illuminate\Contracts\Encryption\Encrypter |
Illuminate\Contracts\Encryption\Encrypter
|
inherited public static extend (callable $callback)
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
inherited public extensionApplyInitCallbacks ()
inherited public static extensionExtendCallback (callable $callback) : void
Helper method for ::extend()
static method
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
inherited public extensionIsHiddenField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited public extensionIsHiddenMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited public static getCalledExtensionClass ()
inherited protected extensionHideField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited protected extensionHideMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|