Example #1
0
 protected function __new__($path, $detail = true)
 {
     list($ref, $class, $path) = self::reflection_class($path);
     $parent = $ref->getParentClass();
     if ($parent !== false && $parent->getName() !== "stdClass") {
         $i = new self($parent->getName(), false);
         $this->extends($i->fm_package());
     }
     $this->name($ref->getName());
     $this->updated(File::last_update($ref->getFileName()));
     $this->path(str_replace("\\", "/", $ref->getFileName()));
     try {
         $this->package(Lib::package_path($this->path()));
         if ($ref->getName() != substr($this->package, ($p = strrpos($this->package, ".")) + ($p === false ? 0 : 1))) {
             $package_path = str_replace('.', '/', $this->package) . '/';
             list($module, $null) = explode('.', substr($this->path, strpos($this->path, $package_path) + strlen($package_path)));
             $this->module = str_replace('/', '.', $module);
         }
     } catch (RuntimeException $e) {
     }
     if ($this->is_path()) {
         $class_src = str_replace(array("\r\n", "\r"), "\n", File::read($this->path()));
         $this->valid_line(sizeof(explode("\n", preg_replace("/^[\\s\t\n\r]*" . "/sm", "", preg_replace("/\\/\\*.*?\\*\\//s", "", $class_src)))));
         if (preg_match_all('/module_const\\((["\'])(.+?)\\1/', $class_src, $match)) {
             foreach ($match[2] as $n) {
                 $this->def[$this->package() . '@' . $n] = new InfoAt($this->package() . '@' . $n, $this->package());
             }
         }
         if (preg_match_all("/@const[\\s]+(.+)/", $class_src, $match)) {
             foreach ($match[1] as $m) {
                 InfoAt::merge($this->def, $m, $this->package(), $this->package() . '@');
             }
         }
         if (preg_match_all("/(\\/\\/|#)[\\s]*TODO[\t ]+(.+)/", $class_src, $todos)) {
             foreach ($todos[2] as $v) {
                 $this->tasks[] = trim($v);
             }
         }
         if ($detail) {
             $pure_class_src = explode("\n", $class_src);
             foreach ($ref->getMethods() as $method) {
                 $mname = $method->getName();
                 if (($mname[0] != '_' || $mname == '__init__' || strpos($mname, "__setup_") === 0) && (!$this->is_methods($mname) && !$this->is_setup($mname))) {
                     $package = $this->package();
                     if (empty($package)) {
                         $package = $this->name();
                     }
                     $mobj = new InfoMethod($package, $this->name(), $method);
                     if ($mobj->is_static() && $mobj->pure_perm() == "public" && strpos($mname, "__setup_") === 0 && substr($mname, -2) === "__") {
                         $this->setup($mobj->name(), $mobj);
                     } else {
                         if ($mobj->name() == '__init__') {
                             if (!$this->is_init()) {
                                 $this->init($mobj);
                             }
                         } else {
                             $this->methods($mobj->name(), $mobj);
                         }
                     }
                     if (!$mobj->is_extends()) {
                         for ($i = $method->getStartLine() - 1; $i < $method->getEndLine(); $i++) {
                             $pure_class_src[$i] = "";
                         }
                     }
                 }
             }
             ksort($this->methods);
             $this->class_method = new InfoMethod($this->package(), $this->name(), null);
             foreach (InfoDoctest::get(implode("\n", $pure_class_src), $this->name(), $this->package()) as $k => $v) {
                 $this->class_method->test($k, $v);
             }
             foreach ($ref->getDefaultProperties() as $k => $v) {
                 if ($k == "_mixin_" && !empty($v)) {
                     foreach (explode(",", $v) as $o) {
                         $r = new self($o);
                         $this->mixin_object[] = $r->package() == "" ? $r->name() : $r->package();
                     }
                     break;
                 }
             }
             if (is_subclass_of($class, "Flow") && $this->is_init()) {
                 foreach ($this->methods() as $k => $v) {
                     $this->methods[$k]->context(array_merge($this->init()->context(), $v->context()));
                     $this->methods[$k]->request(array_merge($this->init()->request(), $v->request()));
                 }
             }
             if (is_subclass_of($class, "Object")) {
                 $ex_src = array();
                 $search_src = null;
                 $default_properties = $ref->getDefaultProperties();
                 foreach ($ref->getProperties() as $prop) {
                     if (!$prop->isPrivate()) {
                         $name = $prop->getName();
                         if ($name[0] != "_" && !$prop->isStatic()) {
                             $this->properties[$name] = new InfoAt($name, $this->package());
                             if ($prop->getDocComment() != "") {
                                 $this->properties[$name]->document(str_replace(array("\r", "\n"), "", trim(preg_replace("/^[\\s]*\\*[\\s]{0,1}/m", "", str_replace(array("/" . "**", "*" . "/"), "", $prop->getDocComment())))));
                             } else {
                                 if ($prop->getDeclaringClass()->getName() == $class) {
                                     $search_src = $class_src;
                                 } else {
                                     $class_name = $prop->getDeclaringClass()->getName();
                                     if (!isset($ex_src[$class_name])) {
                                         $ex_src[$class_name] = File::read($prop->getDeclaringClass()->getFileName());
                                     }
                                     $search_src = $ex_src[$class_name];
                                 }
                                 if (preg_match("/[\\s]+(public|protected)[\\s]+\\\$" . $name . ".*;.*#(.+)/", $search_src, $match)) {
                                     $this->properties[$name]->document(trim($match[2]));
                                 }
                             }
                             if (isset($default_properties['__' . $name . '__'])) {
                                 $this->properties[$name]->set_anon($default_properties['__' . $name . '__']);
                             }
                         }
                     }
                 }
                 unset($search_src);
             }
         }
     }
     $this->document(trim(preg_replace("/^[\\s]*\\*[\\s]{0,1}/m", "", str_replace(array("/" . "**", "*" . "/"), "", $ref->getDocComment()))));
 }
Example #2
0
 protected function __set_document__($doc)
 {
     $this->document = strpos($doc, "\n") === false && preg_match("/@see[\\s](.+)/", $doc) ? trim($doc) : trim(preg_replace("/@.+/", "", $doc));
     $this->author = preg_match("/@author[\\s](.+)/", $doc, $match) ? trim($match[1]) : null;
     if (preg_match_all("/@request[\\s]+(.+)/", $doc, $match)) {
         foreach ($match[1] as $m) {
             InfoAt::merge($this->request, $m, $this->class_package);
             InfoAt::merge($this->context, $m, $this->class_package);
         }
     }
     if (preg_match_all("/@context[\\s]+(.+)/", $doc, $match)) {
         foreach ($match[1] as $m) {
             InfoAt::merge($this->context, $m, $this->class_package);
         }
     }
     if (preg_match("/@return[\\s](.+)/", $doc, $match)) {
         $r = new InfoAt();
         $this->return = $r->set(trim($match[1]), $this->class_package);
     }
     if (preg_match("/@output[\\s](.+)/", $doc, $match)) {
         $this->output = trim($match[1]);
     }
     if (preg_match_all("/@param[\\s]+(.+)/", $doc, $match)) {
         foreach ($match[1] as $m) {
             InfoAt::merge($this->param, $m, $this->class_package);
         }
     }
     if (preg_match_all("/@module[\\s]+(.+)/", $doc, $match)) {
         foreach ($match[1] as $m) {
             InfoAt::merge($this->module, $m, $this->class_package);
         }
     }
     if (preg_match_all("/@arg[\\s]+(.+)/", $doc, $match)) {
         foreach ($match[1] as $m) {
             InfoAt::merge($this->arg, $m, $this->class_package);
         }
     }
 }