Created
January 6, 2015 08:55
-
-
Save maman/fcb513bb8cb49a7a0887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../vendor/autoload.php'; | |
use Pimple\Container; | |
$c = new Container(); | |
/* Starting Session First */ | |
session_cache_limiter(false); | |
session_start(); | |
/* Load Settings */ | |
$c['config'] = require 'config.php'; | |
$config = $c['config']; | |
/* Sensible PHP Settings */ | |
error_reporting($config['php.error_reporting']); | |
ini_set('display_errors', $config['php.display_errors']); | |
ini_set('log_errors', $config['php.log_errors']); | |
ini_set('error_log', $config['php.error_log']); | |
date_default_timezone_set($config['php.date.timezone']); | |
/* Setup Slim Add-Ons */ | |
$logger = new Flynsarmy\SlimMonolog\Log\MonologWriter(array( | |
'handlers' => array( | |
new Monolog\Handler\StreamHandler($config['app.log']) | |
), | |
)); | |
$twigView = new \Slim\Views\Twig(); | |
/* Setup Slim itself */ | |
$app = new \Slim\Slim(array( | |
'view' => $twigView, | |
'mode' => $c['config']['app.environment'], | |
'log.writer' => $logger, | |
'templates.path' => $config['path.templates'], | |
'cookies.encrypt' => true, | |
'cookies.lifetime' => $config['app.cookie.lifetime'], | |
'cookies.path' => $config['app.cookie.path'], | |
'cookies.domain' => $config['app.cookie.domain'], | |
'cookies.secure' => $config['app.cookie.secure'], | |
'cookies.httponly' => $config['app.cookie.httponly'], | |
'cookies.secret_key' => $config['app.cookie.secretkey'], | |
'cookies.cipher' => MCRYPT_RIJNDAEL_256, | |
'cookies.cipher_mode' => MCRYPT_MODE_CBC | |
)); | |
$app->hook('slim.before.dispatch', function () use ($app) { | |
$c['config'] = require 'config.php'; | |
$config = $c['config']; | |
$baseUrl = $config['app.base.url']; | |
$nip = null; | |
$user = null; | |
$role = null; | |
$matkul = null; | |
$prevLink = null; | |
$pathInfo = array(); | |
$currPath = $app->request->getPathInfo(); | |
$breadcrumb = explode('/', $currPath); | |
foreach ($breadcrumb as $link) { | |
if ($prevLink) { | |
$pathInfo[$link] = $baseUrl . '/' . $prevLink . '/' . $link; | |
$prevLink .= '/'; | |
} else { | |
$pathInfo[$link] = $baseUrl . '/' . $link; | |
} | |
$prevLink .= $link; | |
} | |
if (isset($_SESSION['nip'])) { | |
$nip = $_SESSION['nip']; | |
} | |
if (isset($_SESSION['username'])) { | |
$user = $_SESSION['username']; | |
} | |
if (isset($_SESSION['role'])) { | |
$role = $_SESSION['role']; | |
} | |
if (isset($_SESSION['matkul'])) { | |
$matkul = $_SESSION['matkul']; | |
} | |
$app->view()->appendData(array( | |
'baseUrl' => $baseUrl, | |
'nip' => $nip, | |
'username' => $user, | |
'role' => $role, | |
'matkuls' => $matkul, | |
'breadcrumbs' => $pathInfo | |
)); | |
}); | |
/* Setup App Env */ | |
$app->configureMode('production', function () use ($app) { | |
$app->config(array( | |
'log.enable' => true, | |
'debug' => false | |
)); | |
}); | |
$app->configureMode('development', function () use ($app) { | |
$debugbar = new \Slim\Middleware\DebugBar(); | |
$whoops = new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware(); | |
$app->add($debugbar); | |
$app->add($whoops); | |
$app->config(array( | |
'log.enable' => false, | |
'debug' => true | |
)); | |
$app->hook('slim.before', function () use ($app) { | |
$debug = true; | |
$app->view()->appendData(array( | |
'debug' => $debug | |
)); | |
}); | |
}); | |
/* Load Database */ | |
$app->container->singleton('db', function () use ($config) { | |
$dsn = $config['db.dsn']; | |
$user = $config['db.username']; | |
$password = $config['db.password']; | |
return new \alfmel\OCI8\PDO($dsn, $user, $password); | |
}); | |
/* Twig Options */ | |
$view = $app->view(); | |
$view->parserOptions = array( | |
'debug' => true, | |
'cache' => $config['path.templates.cache'] | |
); | |
/* Load Route Middlewares */ | |
foreach (glob($config['path.middlewares'] . '*.php') as $middleware) { | |
require $middleware; | |
} | |
/* Load Routes */ | |
foreach (glob($config['path.routes'] . '*.router.php') as $router) { | |
require $router; | |
} | |
/* Run the App */ | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment