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