/** * Gets a list of all defined frog tags and caches it in the private static * member variable $tagList. */ private static function set_tag_list() { $tagClasses = get_sub_classes('FrogTags'); $tags = array(); foreach ($tagClasses as $class) { $classTags = self::get_tags_from_class($class); foreach ($classTags as $tag) { $tagName = $tag['name']; if (isset($tags[$tagName])) { throw new Exception('Multiple defined tag "' . $tagName . '" in classes "' . $tag['class'] . '" and "' . $tags[$tagName]['class'] . '"!'); } } $tags = array_merge($tags, $classTags); } self::$tagList = $tags; }
/** * Creates a new FrogTagParser object for $page. */ public function __construct($page) { $this->page = $page; $this->tags = FrogTagsList::get(); }
/** * Parses a php source file for functions whose names start with "tag_". If * a function declaration has a preceding comment, this comment is treated * as brief for the particular tag. * * This parser is actually quite dumb as it doesn't check whether the * parsed function belongs to a class derived from FrogTags. But it checks * if the function belongs to a tag in the tag list. So there should only * be problems if there is an other function with the same name. */ protected function parse_source($string) { $definedTags = FrogTagsList::get(); $this->briefnum = 0; $string = preg_replace_callback("|/\\*(.*)\\*/|Us", array($this, 'comment_to_tag'), $string); // preprocessing preg_match_all("|<(brief-\\d+)>(.*)</\\1>\\s+(public\\s)?\\s*function\\s+tag_(\\w+)\\s*\\(.*\\)\\s*|Us", $string, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $name = $match[4]; $brief = $match[2]; if (isset($definedTags[$name])) { array_push($this->briefs, new FrogTagBrief($name, $brief)); } } }