public function testSetFlashForCurrentRequest() { $s = new \Slim\Slim(); $s->get('/bar', function () use($s) { $s->flashNow('info', 'bar'); }); $s->run(); $env = $s->environment(); $this->assertEquals('bar', $env['slim.flash']['info']); }
} else { return $r; } $c = explode(':', $sesija); $s = $em->find('Sesija', $c[1]); if ($s->getKljuc() == $c[0] && $s->getValidna()) { $r['status'] = true; $r['korisnik'] = $s; $r['korisnik_string'] = var_export($s, true); return $r; } else { setcookie('session', '', time() - 60 * 60 * 24 * 30, $urls['rootUri'] . '/'); } } $app->hook('slim.before.router', function () use($app) { $env = $app->environment(); $env['ulogovan'] = is_ulogovan($app->request->params('session')); }); function is_android() { global $app; return stristr($app->request->headers->get('USER_AGENT'), 'Android') != false ? true : false; } $acl_map = array(500 => 'admin', 501 => 'editor', 502 => 'chat', 503 => 'user', 'admin' => 500, 'editor' => 501, 'chat' => 502, 'user' => 503); $login = function ($rola = 'user') { global $app, $acl_map; $env = $app->environment(); return function () use($app, $rola, $env, $acl_map) { if (!$env['ulogovan']['status']) { $app->redirect('/login/'); } else {
require_once 'libs/Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->config('debug', true); //here set all routes $app->map('/writesketch', 'writesketchController')->via('POST'); $app->map('/diyexec', 'diyexecController')->via('POST'); $app->map('/reboot', 'rebootController')->via('GET'); $app->map('/reload', 'reloadController')->via('GET'); $app->map('/showall', 'showallController')->via('GET'); $app->map('/ps', 'psController')->via('GET'); $app->map('/isAlive', 'isAliveController')->via('GET'); $app->map('/isAlivelocal', 'isAlivelocalController')->via('GET'); //function not found $app->notFound(function () use($app) { $controller = $app->environment(); $controller = substr($controller["PATH_INFO"], 1); try { if (strtoupper($app->request()->getMethod() != 'GET')) { throw new Exception(ExceptionMessages::MethodNotFound, ExceptionCodes::MethodNotFound); } else { throw new Exception(ExceptionMessages::FunctionNotFound, ExceptionCodes::FunctionNotFound); } } catch (Exception $e) { $result["status"] = $e->getCode(); $result["message"] = "[" . $app->request()->getMethod() . "][" . $controller . "]:" . $e->getMessage(); } echo json_encode($result); //echo toGreek( json_encode( $result ) ); }); $app->run();
public function GetUrl() { return $this->slim->environment()->offsetGet('slim.url_scheme') . '://' . $this->slim->environment()->offsetGet('HOST'); }
/** * Test default error handler logs the error when debug is false. * * Pre-conditions: * Invoked app route calls default error handler; * * Post-conditions: * Error log is called */ public function testDefaultHandlerLogsTheErrorWhenDebugIsFalse() { $s = new \Slim\Slim(array('debug' => false)); $s->get('/bar', function () use($s) { throw new \InvalidArgumentException('my specific error message'); }); $env = $s->environment(); $env['slim.log'] = new EchoErrorLogger(); // <-- inject the fake logger ob_start(); $s->run(); $output = ob_get_clean(); $this->assertTrue(strpos($output, 'InvalidArgumentException:my specific error message') !== false); }