示例#1
0
 /**
  * @see FWS_Module::run()
  */
 public function run()
 {
     $input = FWS_Props::get()->input();
     $doc = FWS_Props::get()->doc();
     $id = $input->get_var('id', 'get', FWS_Input::INTEGER);
     $type = $input->correct_var('type', 'get', FWS_Input::STRING, array('call', 'var', 'func', 'const', 'error'), 'call');
     if ($id === null) {
         $this->report_error();
         return;
     }
     $loc = null;
     switch ($type) {
         case 'call':
             $loc = PC_DAO::get_calls()->get_by_id($id);
             break;
         case 'var':
             $loc = PC_DAO::get_vars()->get_by_id($id);
             break;
         case 'func':
             $loc = PC_DAO::get_functions()->get_by_id($id);
             break;
         case 'const':
             $loc = PC_DAO::get_constants()->get_by_id($id);
             break;
         case 'error':
             $loc = PC_DAO::get_errors()->get_by_id($id);
             if ($loc === null) {
                 $this->report_error();
                 return;
             }
             $loc = $loc->get_loc();
             break;
     }
     if (!is_file($loc->get_file())) {
         $this->report_error();
         return;
     }
     $lines = explode("\n", file_get_contents($loc->get_file()));
     $start_line = max(1, $loc->get_line() - 4);
     $end_line = min(count($lines), $loc->get_line() + 2);
     $code = '';
     for ($i = $start_line; $i <= $end_line; $i++) {
         $code .= $lines[$i - 1] . "\n";
     }
     $code = PC_Utils::highlight_string($code, $start_line, $loc->get_line(), false);
     $renderer = $doc->use_raw_renderer();
     $renderer->set_content($code);
 }