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 getOutput() { Manager::$response->status = \Maestro\Services\HTTP\MStatusCode::OK; if (Manager::isAjaxCall()) { $this->nocache(); return $this->content; } else { //Manager::$response->setHeader('Location:', $this->object->url); header('Location: ' . $this->object->url); die; } }
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 setContent() { mdump('Executing MRuntimeError'); try { $errorHtml = $this->fetch("runtime"); if (Manager::isAjaxCall()) { $this->ajax->setType('page'); $this->ajax->setData($errorHtml); $this->ajax->setResponseType('JSON'); $this->content = $this->ajax->returnData(); } else { $this->content = $errorHtml; } } catch (\Maestro\Services\Exception\EMException $e) { } }
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)); }
public function addStyleSheetCode($code) { if (Manager::isAjaxCall()) { $fileName = md5($code) . '.css'; $file = Manager::getFrameworkPath('var/files/' . $fileName); file_put_contents($file, $code); $url = Manager::getDownloadURL('cache', $fileName, true); $this->onLoad("\$('head').append('<link href=\"{$url}\" type=\"text/css\" rel=\"stylesheet\" />');"); } else { $this->styleSheetCode .= "\n" . $code; } }
public function generate() { $idPage = $this->idPage; $isAjax = Manager::isAjaxCall(); $scripts = $this->getScripts(); $hasCode = $scripts->scripts . $scripts->code . $scripts->onload . $scripts->onsubmit; if ($hasCode != '') { if ($isAjax) { $code = <<<HERE <script type="text/javascript"> {$scripts->scripts} {$scripts->code} manager.onLoad["{$idPage}"] = function() { console.log("inside onload {$idPage}"); {$scripts->onload}; }; {$scripts->onsubmit} //--> </script> HERE; } else { $code = <<<HERE <script type="text/javascript"> {$scripts->scripts} {$scripts->code} manager.ready = function() { jQuery(function(\$) { console.log("inside onload {$idPage}"); {$scripts->onload}; }); }; {$scripts->onsubmit} //--> </script> HERE; } return "<div id=\"{$idPage}\" class=\"mScripts\">{$code}</div>"; } else { return ''; } }
public function generateContent() { if (Manager::isAjaxCall()) { $content = $this->generateToString($this->content); } else { $content = $this->generateToString($this->content); } return $content; }
function shutdown() { $error = error_get_last(); /* * TODO: handler this error message */ if ($error['type'] & Maestro\Manager::getConf('maestro.debug.severity')) { if (Maestro\Manager::isAjaxCall()) { $ajax = Maestro\Manager::getAjax(); $ob = ob_get_clean(); if ($ajax->isEmpty()) { $ajax->setType('page'); $ajax->setData($ob); } $result = $ajax->returnData(); echo $result; } } }
public function generateContent() { $this->page->setContent($this->generateToString($this->content)); if (Manager::isAjaxCall()) { $content = $this->page->generate(); } else { $content = $this->page->render(); } return $content; }