1 <?php
2 /**
3 * Class File
4 *
5 * @author Tobias Munk <schmunk@usrbin.de>
6 * @link http://www.phundament.com/
7 * @copyright Copyright © 2005-2010 diemeisterei GmbH
8 * @license http://www.phundament.com/license/
9 */
10
11 /**
12 * Behavior, encrypts given attributes with CSecurityManager
13 *
14 * @author Tobias Munk <schmunk@usrbin.de>
15 * @package p3extensions.behaviors
16 * @since 3.0.3
17 */
18 class P3CryptBehavior extends CActiveRecordBehavior {
19
20 /**
21 * Attributes which should be crypted
22 *
23 * @var type array
24 */
25 public $attributes = array();
26
27 public function beforeSave($event) {
28
29 foreach($this->Owner->attributes AS $key => $value) {
30 if(in_array($key, $this->attributes) && $value) {
31 // utf8 encode / decode is needed
32 $this->Owner->$key = utf8_encode(Yii::app()->securityManager->encrypt($value));
33 #exit;
34 }
35
36 }
37 }
38
39 public function afterFind($event) {
40 foreach($this->Owner->attributes AS $key => $value) {
41 if(in_array($key, $this->attributes) && $value)
42 // utf8 encode / decode is needed
43 $this->Owner->$key = Yii::app()->securityManager->decrypt(utf8_decode($value));
44 }
45 }
46
47 }
48 ?>
49