예제 #1
0
 /**
  * Constructor
  * 
  * @param Slim $slim Object of slim
  */
 public function __construct(\Slim\Slim $slim, $config)
 {
     $this->slim = $slim;
     $this->setConfig($config);
     if (isset($config['cache']) && $config['cache']['enabled']) {
         $this->slim->add(new Cache($config['cache']));
     }
 }
예제 #2
0
// Configure
ORM::configure('mysql:host=' . DBHOST . ';dbname=' . DBNAME);
ORM::configure('username', DBUSER);
ORM::configure('password', DBPASS);
ORM::configure('logging', true);
// 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()
예제 #3
0
파일: SlimTest.php 프로젝트: rs3d/Slimplr
 /**
  * Test add middleware
  *
  * This asserts that middleware are queued and called
  * in sequence. This also asserts that the environment
  * variables are passed by reference.
  */
 public function testAddMiddleware()
 {
     $this->expectOutputString('FooHello');
     $s = new Slim();
     $s->add(new CustomMiddleware());
     //<-- See top of this file for class definition
     $s->get('/bar', function () {
         echo 'Foo';
     });
     $s->run();
     $this->assertEquals('Hello', $s->response()->header('X-Slim-Test'));
 }
예제 #4
0
 /**
  * Test parses request body based on media-type only, disregarding
  * any extra content-type header parameters
  */
 public function testParsesRequestBodyWithMediaType()
 {
     Slim_Environment::mock(array('REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/json; charset=ISO-8859-4', 'CONENT_LENGTH' => 13, 'slim.input' => '{"foo":"bar"}'));
     $s = new Slim();
     $s->add(new Slim_Middleware_ContentTypes());
     $s->run();
     $body = $s->request()->getBody();
     $this->assertTrue(is_array($body));
     $this->assertEquals('bar', $body['foo']);
 }
예제 #5
0
// https://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout/blob/master/index.php
require "libs/autoloader.php";
//Autoload para as classes próprias
require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
    return function () use($app) {
        if (!isset($_SESSION['dehbora']['user'])) {
            $_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Você precisa se logar.');
            $app->redirect(URL_BASE . '/inicial');
        }
    };
};
$app->hook('slim.before.dispatch', function () use($app) {
    $user = null;
    if (isset($_SESSION['dehbora']['user'])) {
        $user = $_SESSION['dehbora']['user'];
    }
    $app->view()->setData('user', $user);
예제 #6
0
 /**
  * Test add middleware that does not implement Slim_Middleware_Interface
  */
 public function testAddMiddlewareWithoutInterface()
 {
     $this->setExpectedException('InvalidArgumentException');
     $s = new Slim();
     $s->add('CustomMiddlewareWithoutInterface');
 }
예제 #7
0
파일: index.php 프로젝트: stojg/puny
// get the configuration
require 'config.php';
// use composer autoloader
require 'vendor/autoload.php';
puny\Puny::start_session(7200);
/**
 * Get a new shiny Slim application
 * 
 * @var Slim
 */
$app = new Slim(array('templates.path' => TEMPLATE_PATH));
/**
 * Add a middleware to all routes. Adding commonly accessed variables to the
 * view.
 */
$app->add(new puny\helpers\ViewHelper());
/** 
 * This is a Slim middleware route that prevents non logged in visitors to
 * access that route
 */
$locked = function () use($app) {
    return function () use($app) {
        if (!puny\User::is_logged_in()) {
            $app->redirect($app->urlFor('login'));
        }
    };
};
/**
 * This is the index page
 */
$app->get('/', function () use($app) {
예제 #8
0
<?php

require 'Slim/Slim.php';
require 'Slim/Views/TwigView.php';
require 'lib/idiorm.php';
require 'config.php';
$pdf_enable = file_exists($WKHTMLTOPDF_BIN_PATH) ? TRUE : FALSE;
define('PROJECT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('WKHTMLTOPDF_BIN_PATH', $WKHTMLTOPDF_BIN_PATH);
define('PDF_ENABLE', $pdf_enable);
define('SECURITY_LEVEL', $SECURITY_LEVEL);
define('SYSTEM_ADMIN', serialize($SYSTEM_ADMIN));
define('QUOTATION_ADMIN', serialize($QUOTATION_ADMIN));
define('COOKIE_NAME', $COOKIE_NAME);
ORM::configure("mysql:dbname={$DB_NAME};host={$DB_HOST}");
ORM::configure('username', $DB_USER);
ORM::configure('password', $DB_PASS);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ORM::configure('id_column_overrides', array('customer' => 'customer_id', 'quotation' => 'quotation_id', 'option' => 'option_id', 'account' => 'acc_name'));
$slim_settings = array('mode' => 'production', 'debug' => false, 'log.enabled' => false, 'view' => new TwigView('./lib/Twig', './tpl_cache'), 'templates.path' => './tpl');
$app = new Slim($slim_settings);
$app->add(new Slim_Middleware_SessionCookie(array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => COOKIE_NAME, 'secret' => $COOKIES_SECRET_KEY, 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC)));
require 'app.php';
$app->run();