respond(function ($req, $res, $service, $app) use ($klein) { require_once '_infos.php'; if(strpos($req->uri(), 'adm') !== false && !isset($_SESSION['USER']) && strpos($req->uri(), 'login') === false){ header("Location: {$GLOBALS['URL_SITE']}/adm/login"); exit; } $flash = $service->flashes(); $app->infoSite = $infoSite; $app->infoSite['flashes'] = $flash; $app->infoAdm = $infoAdm; $app->infoAdm['flashes'] = $flash; $app->infoLogin = array(); $app->infoLogin['flashes'] = $flash; // Handle exceptions => flash the message and redirect to the referrer $klein->onError(function ($klein, $err_msg) { // $klein->service()->flash($err_msg); // $klein->service()->back(); myLog('ERROR', $err_msg); $klein->response()->code(400)->json(['error' => $err_msg]); exit; }); // $app also can store lazy services, e.g. if you don't want to // instantiate a database connection on every response $app->register('db', function() { return new PDO('mysql:host=localhost;dbname=objetivo', 'objjjuniortteh', '2is#Ra73'); }); // $app also can store lazy services, e.g. if you don't want to // instantiate a database connection on every response $app->register('pug', function($view, $data) { $pug_options = [ 'debug' => false, // 'cache_dir' => './cache', 'cache_dir' => NULL, 'paths' => [ VIEWS ] ]; \Phug\Phug::addKeyword('phpinclude', function ($args) use ($data) { return array( 'beginPhp' => 'Phug::displayFile((' . $args . '), json_decode( \'' . str_replace( "'", "\'", json_encode($data)) . '\', true), [ \'debug\' => false, \'cache_dir\' => \'./cache\', \'paths\' => [ VIEWS ] ]);', ); }); if (DEV_MODE) { $pug_options['debug'] = true; $pug_options['cache_dir'] = null; \Phug\Phug::displayFile( $view, $data, $pug_options); exit; } \Phug\Optimizer::call( 'displayFile', [ $view, $data ], $pug_options ); exit; }); }); $klein->onHttpError(function($status){ $view = $status . '.pug'; $data = array( 'URL_SITE' => URL_SITE ); $pug_options = [ 'debug' => false, 'cache_dir' => './cache', 'paths' => [ VIEWS ] ]; if (DEV_MODE) { $pug_options['debug'] = true; $pug_options['cache_dir'] = null; \Phug\Phug::displayFile( $view, $data, $pug_options); exit; } \Phug\Optimizer::call( 'displayFile', [ $view, $data ], $pug_options ); exit; }); myLog('INFO', ' ==== END ================================'); myLog('INFO', ' ==== START =============================='); myLog('INFO', '/' . CAMINHO_SITE); $klein->with( CAMINHO_SITE, ROUTES . '/adm/index.php'); $klein->with( CAMINHO_SITE, ROUTES . '/adm/login.php'); $klein->with( CAMINHO_SITE, ROUTES . '/adm/menus.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/index.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/cursos.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/contato.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/concurso.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/aconteceu.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/secretaria.php'); $klein->with( CAMINHO_SITE, ROUTES . '/site/resultados.php'); if (in_array( $_SERVER['REQUEST_METHOD'], [ 'PUT', 'DELETE' ])) { $_POST = json_decode( file_get_contents('php://input'), true); } $klein->dispatch(); ?>