2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 // Copyright (c) 2009 Facebook
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * AJAX endpoint for XHProf function name typeahead is implemented
20 * as a thin wrapper around this file. The wrapper must set up
21 * the global $xhprof_runs_impl to correspond to an object that
22 * implements the iXHProfRuns interface.
24 * @author(s) Kannan Muthukkaruppan
29 require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/xhprof_lib.php';
31 // param name, its type, and default value
32 $params = array('q' => array(XHPROF_STRING_PARAM, ''),
33 'run' => array(XHPROF_STRING_PARAM, ''),
34 'run1' => array(XHPROF_STRING_PARAM, ''),
35 'run2' => array(XHPROF_STRING_PARAM, ''),
36 'source' => array(XHPROF_STRING_PARAM, 'xhprof'),
39 // pull values of these params, and create named globals for each param
40 xhprof_param_init($params);
45 $raw_data = $xhprof_runs_impl->get_run($run, $source, $desc_unused);
46 $functions = xhprof_get_matching_functions($q, $raw_data);
48 } else if (!empty($run1) && !empty($run2)) {
51 $raw_data = $xhprof_runs_impl->get_run($run1, $source, $desc_unused);
52 $functions1 = xhprof_get_matching_functions($q, $raw_data);
54 $raw_data = $xhprof_runs_impl->get_run($run2, $source, $desc_unused);
55 $functions2 = xhprof_get_matching_functions($q, $raw_data);
58 $functions = array_unique(array_merge($functions1, $functions2));
61 xhprof_error("no valid runs specified to typeahead endpoint");
65 // If exact match is present move it to the front
66 if (in_array($q, $functions)) {
67 $old_functions = $functions;
69 $functions = array($q);
70 foreach ($old_functions as $f) {
71 // exact match case has already been added to the front
78 foreach ($functions as $f) {