HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
CSerializeBehavior.php
Go to the documentation of this file.
1 <?php
26 class CSerializeBehavior extends CActiveRecordBehavior
27 {
31  public $serialAttributes = array();
32 
39  public function beforeSave($event)
40  {
41  if (count($this->serialAttributes)) {
42  foreach ($this->serialAttributes as $attribute) {
43  $_att = $this->getOwner()->$attribute;
44 
45  // check if the attribute is an array, and serialize it
46  if (is_array($_att)) {
47  $this->getOwner()->$attribute = base64_encode(serialize($_att));
48  } else {
49  // if its a string, lets see if its unserializable, if not
50  // fuck it set it to null
51  if (is_scalar($_att)) {
52  $a = @unserialize(@base64_decode($_att));
53  if ($a === false) {
54  $this->getOwner()->$attribute = null;
55  }
56  }
57  }
58  }
59  }
60  }
61 
65  public function afterSave($event)
66  {
67  if (count($this->serialAttributes)) {
68  foreach ($this->serialAttributes as $attribute) {
69  $_att = $this->getOwner()->$attribute;
70  if (!empty($_att)
71  && is_scalar($_att)
72  ) {
73  $a = @unserialize(@base64_decode($_att));
74  if ($a !== false) {
75  $this->getOwner()->$attribute = $a;
76  } else {
77  $this->getOwner()->$attribute = null;
78  }
79  }
80  }
81  }
82  }
83 
84  public function afterFind($event)
85  {
86  if (count($this->serialAttributes)) {
87  foreach ($this->serialAttributes as $attribute) {
88  $_att = $this->getOwner()->$attribute;
89  if (!empty($_att)
90  && is_scalar($_att)
91  ) {
92  $a = @unserialize(@base64_decode($_att));
93  if ($a !== false) {
94  $this->getOwner()->$attribute = $a;
95  } else {
96  $this->getOwner()->$attribute = array();
97  }
98  }
99  }
100  }
101  }
102 }