Пример #1
0
 /**
  *
  * @param model $model
  */
 public function setUp($model)
 {
     parent::setUp($model);
     if (!class_exists($this->_getCommentClass())) {
         create_class($this->_getCommentClass(), 'commentPrototype');
         // PHP 5 >= 5.3.0
         //eval('class c extends a{}');
         $tableName = $model->getCollection()->getTableName() . '_comment';
         // (s)
         $model->getStorage()->registerCollection($this->_getCommentClass(), $tableName);
     }
 }
Пример #2
0
 /**
  * Deserialize an SimpleXMLElement
  * @param SimpleXMLElement $ele The element to deserialize
  * @return mixed
  */
 private function deserialize_element($ele, $conf)
 {
     $m = create_class($conf->class);
     $node_conf = $conf ? $conf : $this->node_conf;
     if ($node_conf->attributes) {
         foreach ($conf->attributes->items as $a) {
             $an = $a->name;
             if ($ele[$an]) {
                 $m->{$an} = (string) html_entity_decode($ele[$an]);
             }
         }
     }
     if ($conf->content) {
         foreach ($conf->content->items as $child) {
             switch ($child->type) {
                 case 'html':
                     $m->{$child->name} = xss_clean(trim((string) $ele));
                     break;
                 case 'string':
                     $m->{$child->name} = xss_clean((string) $ele->{$child->name});
                     break;
                 case 'array':
                     if (!$m->{$child->name}) {
                         $m->{$child->name} = array();
                     }
                     $children = $ele->{$child->name}->children();
                     $childconf = self::GetNodeConf($child->contains);
                     foreach ($children as $childele) {
                         $parsed = $this->deserialize_element($childele, $childconf);
                         $m->{$child->name}[] = $parsed;
                     }
                     break;
                 case 'hash':
                     $children = $ele->{$child->name}->children();
                     $childconf = self::GetNodeConf($child->contains);
                     if (!$m->{$child->name}) {
                         $m->{$child->name} = array();
                     }
                     foreach ($children as $childele) {
                         $parsed = $this->deserialize_element($childele, $childconf);
                         $m->{$child->name}[$parsed->{$child->key}] = $parsed;
                     }
                     break;
                 default:
                     $childconf = self::GetNodeConf($child->type);
                     $m->{$child->name} = $this->deserialize_element($ele->{$child->name}, $childconf);
                     break;
             }
         }
     }
     return $m;
 }
Пример #3
0
 /**
  * Deserializes an element of an array into an object
  * 
  * @param string $node The name of the node being deserialized
  * @param mixed $ele The array element being deserialized 
  * @return mixed The deserialized object
  */
 private function deserialize_element($node, $ele, $conf)
 {
     $m = create_class($conf->class);
     if ($conf->attributes) {
         foreach ($conf->attributes->items as $a) {
             $an = $a->name;
             if (isset($ele[$an])) {
                 $m->{$an} = $ele[$an];
             }
         }
     }
     if ($conf->content) {
         foreach ($conf->content->items as $child) {
             switch ($child->type) {
                 case 'html':
                     if (isset($ele[$child->name])) {
                         $m->{$child->name} = html_entity_decode($ele[$child->name]);
                     }
                     break;
                 case 'string':
                     if (isset($ele[$child->name])) {
                         $m->{$child->name} = $ele[$child->name];
                     }
                     break;
                 case 'array':
                     $cc = self::GetNodeConf($child->contains);
                     if (!$m->{$child->name}) {
                         $m->{$child->name} = array();
                     }
                     foreach ($ele[$child->name] as $childele) {
                         $parsed = $this->deserialize_element($child->contains, $childele, $cc);
                         $m->{$child->name}[] = $parsed;
                     }
                     break;
                 case 'hash':
                     $cc = self::GetNodeConf($child->contains);
                     if (!$m->{$child->name}) {
                         $m->{$child->name} = array();
                     }
                     foreach ($ele[$child->name] as $key => $childele) {
                         $parsed = $this->deserialize_element($child->contains, $childele, $cc);
                         $m->{$child->name}[$parsed->{$child->key}] = $parsed;
                     }
                     break;
                 default:
                     $cc = self::GetNodeConf($child->type);
                     $m->{$child->name} = $this->deserialize_element($child->name, $ele[$child->name], $cc);
                     break;
             }
         }
     }
     return $m;
 }