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

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

Inherited from ExtensionTrait

The calling class when using a static method.

inherited protected static $extensionCallbacks : array

Inherited from ExtensionTrait

Used to extend the constructor of an extension class. Eg:

BehaviorClass::extend(function($obj) { })

inherited protected $extensionHidden : mixed

Inherited from ExtensionTrait

Methods

public __construct ($parent)

Parameters
Property Description
$parent
mixed
Returns
mixed

public bootEncryptable () : void

Boot the encryptable trait for a model.

Returns
void

public getEncryptableAttributes () : array

Returns a collection of fields that will be encrypted.

Returns
array

public getEncryptableValue (string $key)

Decrypts an attribute value

Parameters
Property Description
$key
string
Returns
mixed

public getEncrypter () : Illuminate\Contracts\Encryption\Encrypter

Provides the encrypter instance.

Returns
Illuminate\Contracts\Encryption\Encrypter

public getOriginalEncryptableValue (string $attribute)

Returns the original values of any encrypted attributes.

Parameters
Property Description
$attribute
string
Returns
mixed

public getOriginalEncryptableValues () : array

Returns the original values of any encrypted attributes.

Returns
array

public makeEncryptableValue (string $key, $value) : string

Encrypts an attribute value and saves it in the original locker.

Parameters
Property Description
$key
string
$value
mixed
Returns
string

public setEncrypter (Illuminate\Contracts\Encryption\Encrypter $encrypter) : void

Sets the encrypter instance.

Parameters
Property Description
$encrypter
Illuminate\Contracts\Encryption\Encrypter
Returns
void

inherited public static extend (callable $callback)

Inherited from ExtensionBase
Parameters
Property Description
$callback
callable
Returns
mixed

inherited public extensionApplyInitCallbacks ()

Inherited from ExtensionTrait
Returns
mixed

inherited public static extensionExtendCallback (callable $callback) : void

Inherited from ExtensionTrait

Helper method for ::extend() static method

Parameters
Property Description
$callback
callable
Returns
void

inherited public extensionIsHiddenField ($name)

Inherited from ExtensionTrait
Parameters
Property Description
$name
mixed
Returns
mixed

inherited public extensionIsHiddenMethod ($name)

Inherited from ExtensionTrait
Parameters
Property Description
$name
mixed
Returns
mixed

inherited public static getCalledExtensionClass ()

Inherited from ExtensionTrait
Returns
mixed

inherited protected extensionHideField ($name)

Inherited from ExtensionTrait
Parameters
Property Description
$name
mixed
Returns
mixed

inherited protected extensionHideMethod ($name)

Inherited from ExtensionTrait
Parameters
Property Description
$name
mixed
Returns
mixed
Copyright © 2024 Winter CMS