public static function run()
 {
     self::$time_start = microtime(true);
     $log_msg = "";
     // TODO: Substituir por $_POST
     if (isset($_GET['class'])) {
         $class_name = $_GET['class'];
         if (class_exists($class_name)) {
             try {
                 /** @var SimpleAction $action */
                 $action = new $class_name();
                 $result = $action->run();
                 self::$result = array_merge(self::$result, $result);
                 TTransaction::close();
             } catch (PDOException $pdo_e) {
                 // Grava a excessão que ocorreu.
                 $log_msg = $pdo_e->getMessage();
                 switch ($pdo_e->errorInfo[1]) {
                     case 1062:
                     case 1452:
                         self::$result["error"] = $pdo_e->errorInfo[1];
                         break;
                     default:
                         self::$result["error"] = 101;
                 }
                 TTransaction::rollback();
             } catch (Exception $e) {
                 // Grava a excessão que ocorreu.
                 $log_msg = $e->getMessage();
                 self::$result["error"] = 1;
                 TTransaction::rollback();
             }
         } else {
             self::$result["error"] = 2;
         }
         if (self::$result["msg"] == null) {
             self::$result["msg"] = Tools::get_error_msg(self::$result["error"]);
         }
         $log_msg = $log_msg ? $log_msg : self::$result["msg"];
         if (isset(self::$result["error"]) && self::$result["error"] != 0) {
             TTransaction::log($log_msg, 'error');
         }
         self::addCurrentTime('Fim de chamada');
         self::$result['time'] = self::$times;
         echo json_encode(self::$result);
     }
 }
 /** @param $params bool|array|null */
 public function __construct($params = null)
 {
     if ($params === 'SKIP') {
         return 'SKIPPED';
     }
     if ($this->get_error() != 0) {
         return 'ERROR';
     }
     $this->is_called_within = $params != null;
     TTransaction::open("my_db");
     TTransaction::setLogger(new TLoggerTXT(get_class($this)));
     // Se houver parâmetros no construtor, trabalha com eles, caso contrário, utiliza o _POST
     if (!$this->is_called_within) {
         $params = $_GET;
         /// TODO: substituir por _POST após a fase de testes
     }
     // Se entre os parâmetros todas as entradas existirem, guarda os parâmetros, caso contrário há um erro
     $missing_input = array_diff_key($this->input_vars, $params);
     if (count($missing_input) == 0) {
         // Carrega os parâmetros padrão
         foreach (array_keys($this->input_vars) as $var_name) {
             $this->set_input($var_name, $params[$var_name]);
         }
         // Se foi chamado internamente, carrega os paramêtros não-padrão
         if ($this->is_called_within) {
             foreach (array_diff_key($params, $this->input_vars) as $var_name) {
                 $this->set_input($var_name, $params[$var_name]);
             }
         }
     } else {
         $this->set_error(100);
         // Grava a entrada que faltou.
         TTransaction::log(Tools::get_error_msg($this->get_error()), $missing_input, 'error');
     }
     return 0;
 }