CipherBehavior Class Info:
- Class Declaration:
class CipherBehavior extends ModelBehavior
- File name:
- app/models/behaviors/cipher.php
- Description:
- Class Inheritance
Properties:
-
config
-
default
Default values of behavior. @key Symetric key. Default is value of 'Security.salt' configuration.
-
mapMethods array
Allows the mapping of preg-compatible regular expressions to public or private methods in this class, where the array key is a /-delimited regular expression, and the value is a class method. Similar to the functionality of the findBy* / findAllBy* magic methods.
-
settings array
Contains configuration settings for use with individual model objects. This is used because if multiple models use this Behavior, each will use the same object instance. Individual model settings should be stored as an associative array, keyed off of the model name.
Method Summary:
- _addToWhitelist( $model, $field )
- afterDelete( $model )
- afterFind( $model, $result, $primary = false )
- afterSave( $model, $created )
- beforeDelete( $model, $cascade = true )
- beforeFind( $model, $query )
- beforeSave( $model )
- beforeValidate( $model )
- cakeError( $method, $messages = array ( ) )
- cleanup( $model )
- __construct( )
- decrypt( $model, $data = NULL )
- _decryptValue( $base64Value, $config )
- dispatchMethod( $model, $method, $params = array ( ) )
- _encryptValue( $value, $config )
- _generateSalt( $value, $key = '9nHPrYcxmvTliA', $len = 4 )
- log( $msg, $type = 2 )
- Object( )
- onError( $model, $error )
- __openPersistent( $name, $type = NULL )
- _packValue( $value, $salt, $padding = 4 )
- _persist( $name, $return, $object, $type = NULL )
- requestAction( $url, $extra = array ( ) )
- _savePersistent( $name, $object )
- _set( $properties = array ( ) )
- setup( $model, $config = array ( ) )
- _stop( $status = 0 )
- toString( )
- _unpackValue( $envelope, $saltLen )
_addToWhitelist
topIf $model's whitelist property is non-empty, $field will be added to it. Note: this method should only be used in beforeValidate or beforeSave to ensure that it only modifies the whitelist for the current save operation. Also make sure you explicitly set the value of the field which you are allowing.
- Parameters:
-
-
object $model required
Model using this behavior
-
string $field required
Field to be added to $model's whitelist
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 196
- Access
protected
- Return
void
afterDelete
topAfter delete callback
- Parameters:
-
-
object $model required
Model using this behavior
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 143
- Access
public
afterFind
topModel hook to decrypt model data if auto decipher is turned on in the model behavior configuration. Only primary model data are decrypted. */
- Parameters:
-
-
$model required
-
$result required
-
$primary optional false
-
- Method defined in:
- app/models/behaviors/cipher.php on line 111
afterSave
topAfter save callback
- Parameters:
-
-
object $model required
Model using this behavior
-
boolean $created required
True if this save created a new record
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 125
- Access
public
beforeDelete
topBefore delete callback
- Parameters:
-
-
object $model required
Model using this behavior
-
boolean $cascade optional true
If true records that depend on this record will also be deleted
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 135
- Return
boolean True if the operation should continue, false if it should abort
- Access
public
beforeFind
topBefore find callback
- Parameters:
-
-
object $model required
Model using this behavior
-
$query required
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 87
- Return
boolean True if the operation should continue, false if it should abort
- Access
public
beforeSave
topModel hook to encrypt model data @param model Current model */
- Parameters:
-
-
$model required
-
- Method defined in:
- app/models/behaviors/cipher.php on line 83
beforeValidate
topBefore validate callback
- Parameters:
-
-
object $model required
Model using this behavior
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 107
- Return
boolean True if validate operation should continue, false to abort
- Access
public
cakeError
topUsed to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
- Parameters:
-
-
string $method required
Method to be called in the error class (AppError or ErrorHandler classes)
-
array $messages optional array ( )
Message that is to be displayed by the error class
-
- Method defined in:
- cake/libs/object.php on line 187
- Return
error message
- Access
public
cleanup
topClean up any initialization this behavior has done on a model. Called when a behavior is dynamically detached from a model using Model::detach().
- Parameters:
-
-
object $model required
Model using this behavior
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 73
- Access
public
- See
__construct
topClass constructor, overridden in descendant classes.
- Method defined in:
- cake/libs/object.php on line 54
decrypt
topDecrypt model value @param model Current model
- Parameters:
-
-
$model required
-
$data optional NULL
-
- Method defined in:
- app/models/behaviors/cipher.php on line 133
- Return
Deciphered model data */
_decryptValue
topDecrpyted the given base64 string using the blowfish cipher @param base64Value Base 64 encoded string.
- Parameters:
-
-
$base64Value required
-
$config required
-
- Method defined in:
- app/models/behaviors/cipher.php on line 250
- See
_encryptValue(), _unpackValue() */
dispatchMethod
topOverrides Object::dispatchMethod to account for PHP4's broken reference support
- Parameters:
-
-
$model required
-
$method required
-
$params optional array ( )
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 161
- See
Object::dispatchMethod
- Access
public
- Return
mixed
_encryptValue
topEncrpytes a value using the blowfish cipher. As key the Security.salt value is used @param value Value to cipher
- Parameters:
-
-
$value required
-
$config required
-
- Method defined in:
- app/models/behaviors/cipher.php on line 234
- Return
Return of the chiphered value in base64 encoding. To distinguish ciphed value, the ciphed value has a prefix of '$E$' i @see _decryptValue(), _packValue(), _generateSalt() */
- See
_decryptValue(), _packValue(), _generateSalt() */
_generateSalt
topCreate salt for cipher's envelope. The salt is an random string which depends on the random generator, the value, the key and on the previous generated character. @param value Value to cipher
- Parameters:
-
-
$value required
-
$key optional '9nHPrYcxmvTliA'
-
$len optional 4
-
- Method defined in:
- app/models/behaviors/cipher.php on line 168
- Return
Randomly generated salt of the given lenth */
log
topConvience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/config/core.php.
-
- Method defined in:
- cake/libs/object.php on line 148
- Return
boolean Success of log write
- Access
public
Object
topA hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
- Method defined in:
- cake/libs/object.php on line 43
- Return
Object
onError
topDataSource error callback
- Parameters:
-
-
object $model required
Model using this behavior
-
string $error required
Error generated in DataSource
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 152
- Access
public
__openPersistent
topOpen the persistent class file for reading Used by Object::_persist()
- Parameters:
-
-
string $name required
Name of persisted class
-
string $type optional NULL
Type of persistance (e.g: registry)
-
- Method defined in:
- cake/libs/object.php on line 268
- Return
void
- Access
private
_packValue
topPacks a value with a surrounding salt value. Additionaly the resulting envelope could be aligned @param value Value to envelope
- Parameters:
-
-
$value required
-
$salt required
-
$padding optional 4
-
- Method defined in:
- app/models/behaviors/cipher.php on line 195
- Return
Envelope with salt @see _unpackValue() */
- See
_unpackValue() */
_persist
topChecks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name of the class to persist
-
$return required
-
string $object required
the object to persist
-
$type optional NULL
-
- Method defined in:
- cake/libs/object.php on line 218
- Return
boolean Success
- Access
protected
- Todo
add examples to manual
requestAction
topCalls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
- Parameters:
-
-
mixed $url required
String or array-based url.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true.
-
- Method defined in:
- cake/libs/object.php on line 80
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
- Access
public
_savePersistent
topYou should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name used for object to cache
-
object $object required
the object to persist
-
- Method defined in:
- cake/libs/object.php on line 247
- Return
boolean true on save, throws error if file can not be created
- Access
protected
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- cake/libs/object.php on line 166
- Return
void
- Access
protected
setup
top- Parameters:
-
-
$model required
-
$config optional array ( )
-
- Method defined in:
- app/models/behaviors/cipher.php on line 47
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
$status optional 0
-
- Method defined in:
- cake/libs/object.php on line 135
- Return
void
- Access
public
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- cake/libs/object.php on line 64
- Return
string The name of this class
- Access
public
_unpackValue
topUnpacks an envelope and returns the packed value @param envelope
- Parameters:
-
-
$envelope required
-
$saltLen required
-
- Method defined in:
- app/models/behaviors/cipher.php on line 209
- Return
Value or false on an error @see _packValue() */
- See
_packValue() */
