public static function handlerRequest($data = NULL)
 {
     try {
         // se é uma chamada Ajax, inicializa MAjax
         if (Manager::isAjaxCall()) {
             Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
         }
         MApp::contextualize();
         self::setData($data ?: $_REQUEST);
         mtrace('DTO Data:');
         mtrace(self::getData());
         self::init();
         do {
             self::$result = MApp::handler();
         } while (self::$forward != '');
         self::terminate();
     } catch (\Maestro\Services\Exception\ENotFoundException $e) {
         self::$result = new Results\MNotFound($e);
     } catch (\Maestro\Services\Exception\ESecurityException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Maestro\Services\Exception\ETimeOutException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Maestro\Services\Exception\ERuntimeException $e) {
         self::$result = new Results\MRunTimeError($e);
     } catch (\Maestro\Services\Exception\EMException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Exception $e) {
         self::$result = new Results\MInternalError($e);
     }
 }
 public function dispatch($action)
 {
     mtrace('mcontroller::dispatch = ' . $action);
     if (!method_exists($this, $action)) {
         mtrace('action does not exists = ' . $action);
         try {
             $this->render($action);
         } catch (\Exception $e) {
             mdump($e->getMessage() . ' ' . $e->getFile() . ' - ' . $e->getLine());
             throw new ENotFoundException(_M("App: [%s], Module: [%s], Controller: [%s] : action [%s} not found!", [$this->application, $this->module, $this->name, $action]));
         }
     } else {
         try {
             $this->action = $action;
             //if (Manager::getPage()->isPostBack()) {
             //    $actionPost = $action . 'Post';
             //    if (method_exists($this, $actionPost)) {
             //        $action = $actionPost;
             //    }
             //}
             mtrace('executing = ' . $action);
             $method = new \ReflectionMethod(get_class($this), $action);
             $params = $method->getParameters();
             $values = array();
             foreach ($params as $param) {
                 $value = $this->data->{$param->getName()};
                 if (!$value && $param->isDefaultValueAvailable()) {
                     $value = $param->getDefaultValue();
                 }
                 $values[] = $value;
             }
             $result = call_user_func_array([$this, $action], $values);
             if (!$this->getResult()) {
                 if (!Manager::isAjaxCall()) {
                     Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
                 }
                 $this->setResult(new Results\MRenderJSON(json_encode($result)));
             }
         } catch (\Exception $e) {
             mdump($e->getMessage());
             if (Manager::PROD()) {
                 $this->renderPrompt('error', $e->getMessage());
             } else {
                 $this->renderPrompt('error', "[<b>" . $this->name . '/' . $action . "</b>]" . $e->getMessage());
             }
         }
     }
 }
 public function renderJSON($json = '')
 {
     if (!Manager::isAjaxCall()) {
         Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
     }
     $ajax = Manager::getAjax();
     $ajax->setData($this->data);
     $this->setResult(new Results\MRenderJSON($json));
 }