Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   1  <?php
   2  //  Copyright (c) 2009 Facebook
   3  //
   4  //  Licensed under the Apache License, Version 2.0 (the "License");
   5  //  you may not use this file except in compliance with the License.
   6  //  You may obtain a copy of the License at
   7  //
   8  //      http://www.apache.org/licenses/LICENSE-2.0
   9  //
  10  //  Unless required by applicable law or agreed to in writing, software
  11  //  distributed under the License is distributed on an "AS IS" BASIS,
  12  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13  //  See the License for the specific language governing permissions and
  14  //  limitations under the License.
  15  //
  16  
  17  /**
  18   * AJAX endpoint for XHProf function name typeahead is implemented
  19   * as a thin wrapper around this file. The wrapper must set up
  20   * the global $xhprof_runs_impl to correspond to an object that
  21   * implements the iXHProfRuns interface.
  22   *
  23   * @author(s)  Kannan Muthukkaruppan
  24   *             Changhao Jiang
  25   */
  26  
  27  
  28  require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/xhprof_lib.php';
  29  
  30  // param name, its type, and default value
  31  $params = array('q'          => array(XHPROF_STRING_PARAM, ''),
  32                  'run'        => array(XHPROF_STRING_PARAM, ''),
  33                  'run1'       => array(XHPROF_STRING_PARAM, ''),
  34                  'run2'       => array(XHPROF_STRING_PARAM, ''),
  35                  'source'     => array(XHPROF_STRING_PARAM, 'xhprof'),
  36                  );
  37  
  38  // pull values of these params, and create named globals for each param
  39  xhprof_param_init($params);
  40  
  41  if (!empty($run)) {
  42  
  43    // single run mode
  44    $raw_data = $xhprof_runs_impl->get_run($run, $source, $desc_unused);
  45    $functions = xhprof_get_matching_functions($q, $raw_data);
  46  
  47  } else if (!empty($run1) && !empty($run2)) {
  48  
  49    // diff mode
  50    $raw_data = $xhprof_runs_impl->get_run($run1, $source, $desc_unused);
  51    $functions1 = xhprof_get_matching_functions($q, $raw_data);
  52  
  53    $raw_data = $xhprof_runs_impl->get_run($run2, $source, $desc_unused);
  54    $functions2 = xhprof_get_matching_functions($q, $raw_data);
  55  
  56  
  57    $functions = array_unique(array_merge($functions1, $functions2));
  58    asort($functions);
  59  } else {
  60    xhprof_error("no valid runs specified to typeahead endpoint");
  61    $functions = array();
  62  }
  63  
  64  // If exact match is present move it to the front
  65  if (in_array($q, $functions)) {
  66    $old_functions = $functions;
  67  
  68    $functions = array($q);
  69    foreach ($old_functions as $f) {
  70      // exact match case has already been added to the front
  71      if ($f != $q) {
  72        $functions[] = $f;
  73      }
  74    }
  75  }
  76  
  77  foreach ($functions as $f) {
  78    echo $f."\n";
  79  }