/** * @backupGlobals enabled */ public function test_actions() { \Difra\Debugger::disable(); \Difra\Ajaxer::clean(); $actions = []; \Difra\Ajaxer::notify('notification message'); $actions[] = ['action' => 'notify', 'message' => 'notification message', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::display('<span>test</span>'); $actions[] = ['action' => 'display', 'html' => '<span>test</span>']; \Difra\Ajaxer::error('error message <span>test</span>'); $actions[] = ['action' => 'error', 'message' => 'error message <span>test</span>', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::required('element'); $actions[] = ['action' => 'require', 'name' => 'element']; \Difra\Ajaxer::invalid('inv1'); $actions[] = ['action' => 'invalid', 'name' => 'inv1']; \Difra\Ajaxer::invalid('inv2'); $actions[] = ['action' => 'invalid', 'name' => 'inv2']; \Difra\Ajaxer::status('field1', 'bad value', 'problem'); $actions[] = ['action' => 'status', 'name' => 'field1', 'message' => 'bad value', 'classname' => 'problem']; \Difra\Ajaxer::redirect('/some/page'); $actions[] = ['action' => 'redirect', 'url' => '/some/page']; $_SERVER['HTTP_REFERER'] = '/current/page'; \Difra\Ajaxer::refresh(); $actions[] = ['action' => 'redirect', 'url' => '/current/page']; \Difra\Ajaxer::reload(); $actions[] = ['action' => 'reload']; \Difra\Ajaxer::load('someid', 'some <b>content</b>'); $actions[] = ['action' => 'load', 'target' => 'someid', 'html' => 'some <b>content</b>']; \Difra\Ajaxer::close(); $actions[] = ['action' => 'close']; \Difra\Ajaxer::reset(); $actions[] = ['action' => 'reset']; \Difra\Envi::setUri('/current/page'); \Difra\Ajaxer::confirm('Are you sure?'); $actions[] = ['action' => 'display', 'html' => '<form action="/current/page" class="ajaxer"><input type="hidden" name="confirm" value="1"/>' . '<div>Are you sure?</div>' . '<input type="submit" value="' . \Difra\Locales::get('ajaxer/confirm-yes') . '"/>' . '<input type="button" value="' . \Difra\Locales::get('ajaxer/confirm-no') . '" onclick="ajaxer.close(this)"/>' . '</form>']; $this->assertEquals(\Difra\Ajaxer::getResponse(), json_encode(['actions' => $actions], \Difra\Ajaxer::getJsonFlags())); \Difra\Ajaxer::clean(); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertFalse(\Difra\Ajaxer::hasProblem()); \Difra\Ajaxer::reload(); \Difra\Ajaxer::clean(true); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertTrue(\Difra\Ajaxer::hasProblem()); }
/** * Choose view depending on request type */ public static final function start() { $controller = Controller::getInstance(); if (Controller::hasUnusedParameters()) { $controller->putExpires(true); throw new HttpError(404); } elseif (!is_null(self::$output)) { $controller->putExpires(); header('Content-Type: ' . self::$outputType . '; charset="utf-8"'); echo self::$output; View::$rendered = true; } elseif (Debugger::isEnabled() and isset($_GET['xml']) and $_GET['xml']) { if ($_GET['xml'] == '2') { View\XML::fillXML(); } header('Content-Type: text/xml; charset="utf-8"'); $controller->xml->formatOutput = true; $controller->xml->encoding = 'utf-8'; echo rawurldecode($controller->xml->saveXML()); View::$rendered = true; } elseif (!View::$rendered and Request::isAjax()) { $controller->putExpires(); // should be application/json, but opera doesn't understand it and offers to save file to disk header('Content-type: text/plain'); echo Ajaxer::getResponse(); View::$rendered = true; } elseif (!View::$rendered) { $controller->putExpires(); try { View::render($controller->xml); } catch (HttpError $ex) { if (!Debugger::isConsoleEnabled()) { throw new HttpError(500); } else { echo Debugger::debugHTML(true); die; } } } }
/** * Callback for fatal errors */ public static function captureShutdown() { if (View::$rendered) { return; } // was there an error? if (!($error = error_get_last()) and !self::$handledByException) { return; } if ($error) { // add error to console log if (self::$handledByNormal != $error['message']) { $error['error'] = Libs\Debug\ErrorConstants::getInstance()->getVerbalError($error['type']); $error['class'] = 'errors'; $error['traceback'] = debug_backtrace(); array_shift($error['traceback']); self::addLineAsArray($error); } } self::$shutdown = true; // view was not rendered yet, render console standalone page if (!View::$rendered) { if (!Request::isAjax()) { echo self::debugHTML(true); } else { echo Ajaxer::getResponse(); } View::$rendered = true; } }