/** * Protected constructor because its a bit ugly (without method-overloading) * * @param string $str the file or string * @param bool $is_file whether $str is a file */ protected function __construct($str, $is_file) { if ($is_file) { $this->file = $str; $str = FWS_FileUtils::read($str); } $this->tokens = token_get_all($str); $this->tokCount = count($this->tokens); for ($i = 0; $i < $this->tokCount; $i++) { if (!is_array($this->tokens[$i])) { $this->tokens[$i] = array(ord($this->tokens[$i]), $this->tokens[$i]); } } $this->pos = -1; $this->line = 1; self::$T_DOC_COMMENT = defined('T_DOC_COMMENT') ? constant('T_DOC_COMMENT') : 10000; }
/** * Highlights the given file * * @param string $file the file * @param int $line optional the line to mark * @return string the highlighted source */ public static function highlight_file($file, $line = 0) { if (is_file($file)) { $source = FWS_FileUtils::read($file); } else { $source = ''; } return self::highlight_string($source, 1, $line); }