Exemple #1
0
<?php

// Initialize flags, config, models, cache, etc.
require_once 'init.php';
require_once BASE_DIR . '/vendor/Slim/Slim/Slim.php';
require_once BASE_DIR . '/vendor/Slim-Extras/Log Writers/TimestampLogFileWriter.php';
$app = new Slim(array('mode' => defined('PRODUCTION') ? 'production' : 'development', 'debug' => false, 'log.enabled' => true, 'log.writer' => new TimestampLogFileWriter(array('path' => BASE_DIR, 'name_format' => '\\s\\l\\i\\m\\_\\l\\o\\g'))));
$app->configureMode('development', function () use($app) {
    $app->config(array('debug' => true));
});
$app->configureMode('production', function () use($app) {
    error_reporting(0);
    $app->notFound(function () use($app) {
        $page = new ErrorController(404);
        $page->render();
    });
    $app->error(function (Exception $e) use($app) {
        $app->response()->status(500);
        if (!$app->request()->isAjax()) {
            $page = new ErrorController(500);
            $page->render();
        }
        $app->stop();
        if (file_exists(BASE_DIR . '/.gbemail')) {
            foreach (explode('\\n', file_get_contents(BASE_DIR . '/.gbemail')) as $email) {
                mail(trim($email), "GetchaBooks Error", get_error_message($e));
            }
        }
    });
});
$app->hook('slim.before', function () use($app) {
Exemple #2
0
// ORM::configure('setting_name', 'value_for_setting');
// ORM::configure('id', 'primary_key');
// ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
/**
 *  Instantiante Slim instance
 */
$app = new Slim(array('view' => new TwigView(), 'templates.path' => APPATH . '/templates', 'mode' => 'prod'));
/**
 *  Setup Sessions with Slim
 */
$app->add(new Slim_Middleware_SessionCookie(), array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slim_session', 'secret' => SECRET, 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC));
/**
 * Production mode config settings
 * 
 */
function mode_prod()
{
    global $app;
    $app->config(array('log.enable' => true, 'log.path' => ABSPATH . 'logs', 'debug' => false));
}
$app->configureMode('prod', 'mode_production');
/**
 * Development mode config settings
 * 
 */
function mode_dev()
{
    global $app;
    $app->config(array('log.enable' => false, 'debug' => true));
}
$app->configureMode('dev', 'mode_development');
Exemple #3
0
/* == *
 *
 * SLIM INIT
 *
 * ==============================================*/
$app = new Slim(array('mode' => 'dev', 'templates.path' => 'templates', 'view' => $index_view, 'cookies.secret_key' => 'r+hhiXlmC4NvsQpq/jaZPK6h+sornz0LC3cbdJNj', 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'cookies.secure' => false));
// set name
//$app->setName('reviewApp');
// End SLIM INIT
/* == *
 *
 * CONFIGS
 *
 * ==============================================*/
$app->configureMode('prod', function () use($app) {
    $app->config(array('log.enable' => true, 'log.path' => '../logs', 'debug' => false));
});
$app->configureMode('dev', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true));
});
// End CONFIGS
/* == *
 *
 * UTILS
 *
 * ==============================================*/
// recall template
function recall_template()
{
    $template_path = $app->config('templates.path');
    //returns "../templates"
Exemple #4
0
 /**
  * Test mode configuration when not callable
  */
 public function testModeConfigurationWhenNotCallable()
 {
     $flag = 0;
     $s = new Slim(array('mode' => 'production'));
     $s->configureMode('production', 'foo');
     $this->assertEquals(0, $flag);
 }
 /**
  * Test Slim Logging for given mode
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Set custom Logger for current app mode;
  *
  * Post-conditions:
  * Slim app Logger correct based on mode;
  */
 public function testSlimLoggerInMode()
 {
     $app = new Slim(array('mode' => 'test'));
     $app->configureMode('test', function () use($app) {
         $app->config(array('log.enable' => true, 'log.logger' => new CustomLogger()));
     });
     $app->configureMode('development', function () use($app) {
         $app->config(array('log.enable' => true));
     });
     $this->assertTrue($app->getLog()->getLogger() instanceof CustomLogger);
 }
Exemple #6
0
<?php

require_once 'slim/Slim.php';
require_once 'slim/SmartyView.php';
require_once 'classes/app.php';
$app = new Slim(array('templates.path' => 'templates', 'view' => 'SmartyView', 'log.path' => 'slim/Logs', 'log.level' => 4, 'cookies.secret_key' => "[SALT]", 'mode' => 'development'));
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
});
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => true));
});
//# Set your API_Key and Client secret                #//
//#   Available here: https://eventbrite.com/api/key  #//
$app->config('api_key', 'YOUR_API_KEY_HERE');
$app->config('client_secret', 'YOUR_CLIENT_SECRET_HERE');
function authenticate()
{
    $app = Slim::getInstance();
    if (!App::user()) {
        $app->redirect("/connect/");
    }
}
//## ROUTES ##//
$app->get('/', function () use($app) {
    $params = App::start();
    $params['title'] = "Home";
    $params['page'] = "home";
    if (!App::user()) {
        $params['button'] = "Connect";
    } else {
Exemple #7
0
 /**
  * Test Slim mode with default
  *
  * Pre-conditions:
  * ENV[SLIM_MODE] not set;
  * Slim app initialized without config mode;
  *
  * Post-conditions:
  * Only the development configuration is called;
  */
 public function testSlimModeDefault()
 {
     $this->expectOutputString('dev mode');
     Slim::init();
     Slim::configureMode('development', function () {
         echo "dev mode";
     });
     Slim::configureMode('production', function () {
         echo "production mode";
     });
 }