/** * Execute the command. */ public function execute(\Closure $reporter = null) { // Clear all existing tags. $this->database->truncate(); // Export built-in tags. $tags = $this->extensionTags->getTags(); if ($reporter !== null) { $reporter(sprintf("Importing tags for %d built-in modules...\n", count($tags))); } foreach ($tags as $module => $moduleTags) { $this->database->addTags("<{$module}>", $moduleTags); } // Start indexing the tags and report progress. $reporter(sprintf("Importing %d source files...\n", count($this->files))); $tagCount = 0; foreach ($this->files as $index => $file) { try { $tags = $this->parser->getTags($file); $tagCount += count($tags); $this->database->addTags($file, $tags); } catch (ParserError $e) { if ($reporter !== null) { $reporter(sprintf("\nError '%s' in '%s'\n", $e->getMessage(), $file)); } } if ($reporter !== null) { $reporter(sprintf("\r [%d files, %d tags, %d%%]", $index + 1, $tagCount, ceil(($index + 1) / count($this->files) * 100))); } } }
/** * Execute the command. * * @param string $pattern * @param string $usageType Find tags of type 'reference' or 'definition' (default) * @param bool $ignoreCase Case sentitive search (optional) * @param string $tagType Filter by tag type (optional) * @param string $format Output format * @return string */ public function findByPattern($pattern, $usageType = PhpTags\Tag::DEFINITION, $ignoreCase = true, $tagType = null, $format = null) { if ($tagType === 'any') { $tagType = null; } $tags = $this->database->findByPattern($pattern, $usageType, $ignoreCase, $tagType); foreach ($tags as $index => $tag) { // Usage type is part of the query, no need to return it. unset($tag['usage_type']); foreach ($tag as $field => $value) { $tag[$field] = $this->escapeString($tag[$field]); } $tags[$index] = $tag; } switch ($format) { case self::FORMAT_CTAGS: return $this->formatCtags($tags); case self::FORMAT_LISP: return $this->formatLisp($tags); default: return $this->formatTabSeparated($tags); } }