예제 #1
0
 public function defineFact($data)
 {
     $ret = array();
     if (is_string($data)) {
         $data = array($data);
     }
     if (is_array($data)) {
         if (!isset($data['__template__'])) {
             // This is a static fact
             $name = array_shift($data);
             $ret[] = '(' . $name;
             foreach ($data as $d) {
                 $ret[] = $this->translate($d);
             }
         } else {
             return $this->defineFact((object) $data);
         }
     } else {
         $obj = $data;
         $name = get_class($obj);
         $reflection = new \Addendum\ReflectionAnnotatedClass($name);
         if (isset($obj->__template__)) {
             $name = $obj->__template__;
         }
         $ret[] = '(' . $name;
         foreach ($obj as $key => $value) {
             if (strpos($key, '_') === 0) {
                 // Skip _ variables
                 continue;
             }
             $ret[] = '(' . $key;
             if ($reflection->hasProperty($key)) {
                 if ($reflection->getProperty($key)->hasAnnotation('Clips\\Symbol')) {
                     $value = Symbol::symbol($value);
                 }
             }
             $ret[] = $this->translate($value) . ')';
         }
     }
     return implode(' ', $ret) . ')';
 }