Example #1
0
 /**
  * Parse PHP source code and return the parsed tree.
  *
  * @param string $source
  *   PHP source code
  * @param string $filename
  *   (Optional) Filename of source.
  * @return RootNode
  *   The top-level node of the parsed tree
  */
 public static function parseSource($source, $filename = NULL)
 {
     static $tokenizer, $parser = NULL;
     if (!isset($parser)) {
         $tokenizer = new Tokenizer();
         $parser = new self();
     }
     $tokens = $tokenizer->getAll($source, $filename);
     $parser->filename = $filename;
     return $parser->buildTree(new TokenIterator($tokens));
 }
Example #2
0
 /**
  * Append a SCRIPT element to the page output
  *
  * @param string $hook   "output"
  * @param string $type   "page"
  * @param string $html   Full page HTML
  * @param array  $params Hook params
  *
  * @return string
  */
 public static function handlePageOutput($hook, $type, $html, $params)
 {
     $profiler = new self();
     $min_percentage = elgg_get_config('profiling_minimum_percentage');
     if ($min_percentage !== null) {
         $profiler->minimum_percentage = $min_percentage;
     }
     $tree = $profiler->buildTree(_elgg_services()->timer);
     $tree = $profiler->formatTree($tree);
     $data['tree'] = $tree;
     $data['total'] = $tree['duration'] . " seconds";
     $list = [];
     $profiler->flattenTree($list, $tree);
     $root = elgg_get_config('path');
     $list = array_map(function ($period) use($root) {
         $period['name'] = str_replace("Closure {$root}", "Closure ", $period['name']);
         return "{$period['percentage']}% ({$period['duration']}) {$period['name']}";
     }, $list);
     $data['list'] = $list;
     $html .= "<script>console.log(" . json_encode($data) . ");</script>";
     return $html;
 }