Example #1
0
function initialize()
{
    $app = new \Slim\Slim(array('mode' => 'production'));
    // Only invoked if mode is "production"
    $app->configureMode('production', function () use($app) {
        $app->config(array('log.enable' => false, 'debug' => false, 'config.path' => '../config/prod/'));
    });
    // Only invoked if mode is "development"
    $app->configureMode('development', function () use($app) {
        $app->config(array('log.enable' => false, 'debug' => true, 'config.path' => '../config/dev/'));
    });
}
Example #2
0
/**
 * create slim app
 */
function create_app($name)
{
    $app = new \Slim\Slim(array('templates.path' => ROOT . 'templates/', 'cookies.lifetime' => '2 days', 'cookies.secret_key' => 'livehubsecretkey'));
    $app->configureMode('development', function () use($app) {
        $app->config(array('debug' => true, 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'cookies.lifetime' => '2 days', 'cookies.secret_key' => 'livehubsecretkey'));
    });
    $app->configureMode('production', function () use($app) {
        $app - config(array('log.level' => \Slim\Log::ERROR, 'cookies.lifetime' => '2 days', 'cookies.encrypt' => true, 'cookies.secret_key' => 'livehubsecretkey'));
    });
    $app->container->singleton('log', function () use($name) {
        $log = new \Monolog\Logger($name);
        $log->pushHandler(new \Monolog\Handler\StreamHandler(ROOT . "logs/{$name}.log", \Monolog\Logger::DEBUG));
        return $log;
    });
    $app->view(new \Slim\Views\Twig());
    $app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
    $app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
    $app->setName($name);
    return $app;
}
Example #3
0
<?php

include __DIR__ . '/../common.php';
// define the base directory of the current application
define('APP_ENV', APP_ENV_DEVELOPMENT);
define('APP_DIR', BASE_DIR . '/apps/sample');
$app = new Slim\Slim(array('mode' => APP_ENV));
// load configuration files
$app->configureMode(APP_ENV, function () use($app) {
    $config = (include APP_DIR . '/etc/' . APP_ENV . '.php');
    $app->config($config);
});
// initialize the routers
$routers = glob(APP_DIR . '/routers/*.router.php');
foreach ($routers as $route) {
    include $route;
}
unset($route, $routers);
$app->run();
Example #4
0
            'cipher_mode' => MCRYPT_MODE_CBC
        )));
*/
/*
 * SET some globally available view data
 */
$resourceUri = $_SERVER['REQUEST_URI'];
$rootUri = $app->request()->getRootUri();
$assetUri = $rootUri;
$app->view()->appendData(array('app' => $app, 'rootUri' => $rootUri, 'assetUri' => $assetUri, 'resourceUri' => $resourceUri));
foreach (glob(ROOT . '/app/controllers/*.php') as $router) {
    include $router;
}
// Disable fluid mode in production environment
$app->configureMode(SLIM_MODE_PRO, function () use($app) {
    // note, transactions will be auto-committed in fluid mode
    R::freeze(true);
});
/*
|--------------------------------------------------------------------------
| Configure Twig
|--------------------------------------------------------------------------
|
| The application uses Twig as its template engine. This script configures 
| the template paths and adds some extensions.
|
*/
$view = $app->view();
$view->parserOptions = array('debug' => true, 'cache' => ROOT . '/app/storage/cache/twig', 'auto_reload' => true);
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
/*
|--------------------------------------------------------------------------
Example #5
0
<?php

require 'vendor/autoload.php';
$app = new \Slim\Slim(array('mode' => 'development'));
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => false, 'config.path' => 'config/prod/'));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true, 'config.path' => 'config/dev/'));
});
// Define mysql connector
$app->container->singleton('mysql', function () {
    $app = \Slim\Slim::getInstance();
    $config = parse_ini_file(getAppConfigFile('mysql.ini'));
    $pdo = new PDO("mysql:host=" . $config['db.hostname'] . ";dbname=" . $config['db.schema'], $config['db.user'], $config['db.password']);
    // set the character set to utf8 to ensure proper json encoding
    $pdo->exec("SET NAMES 'utf8'");
    return $pdo;
});
$app->container->singleton('log', function () {
    $app = \Slim\Slim::getInstance();
    Logger::configure(getAppConfigFile('log4php-config.xml'));
    return Logger::getLogger('default');
});
// FIXME: Implement separation of view and data
// TODO: move index.html into the /views directory and
// point the templates to /views
$view = $app->view();
$view->setTemplatesDirectory('./');
    $app->log->debug('REQUEST : ' . var_export($_REQUEST, true));
    // Sono stati messi nel log dal logger
    // $app->log->debug('URI : '.$srcUri);
    // $app->log->debug('URL : '.$srcUrl);
    $app->log->debug('Params : ' . $srcParam);
    $req->isAjax() ? $app->log->debug('Ajax attivo') : $app->log->debug('Ajax non attivo');
});
$app->hook('slim.after.dispatch', function () use($app) {
    $status = $app->response->getStatus();
    $app->log->debug('terminato con stato [' . $status . ']');
});
// $log = $app->getLog();
// $view = $app->view();
$app->configureMode('development', function () use($app, $config) {
    $app->config(array('debug' => true));
    $connection_name = 'testing';
    include '../app/app.php';
});
$app->configureMode('production', function () use($app, $config) {
    $app->config(array('debug' => false));
    $connection_name = 'default';
    include '../app/app.php';
});
$app->get('/', function () use($app, $config) {
    if ($config['maintenance']) {
        $app->render('home/maintenance.php', array());
    } else {
        $app->render('home/index.php', array());
    }
});
$app->get('/setup', function () use($app, $config) {
Example #7
0
//http://docs.slimframework.com/routing/helpers/
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
// Set the current mode
$app = new \Slim\Slim($config);
$db = Lib\Db\Wrapper\MySql::getInstance();
//var_dump($db->test());
var_dump($db->fetchAll("SELECT * from test"));
var_dump($db->fetchOne("SELECT val FROM test where id = ?", array(1)));
$res = $db->query("INSERT INTO test (val) VALUES(?)", array(uniqid()));
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enabled' => true, 'debug' => true));
});
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enabled' => false, 'debug' => false));
});
/*
* Suppose you wanted to authenticate the current user against a given role 
* for a specific route. You could use some closure magic like this:
* 
* $authenticateForRole = function ( $role = 'member' ) {
       return function () use ( $role ) {
           $user = User::fetchFromDatabaseSomehow();
           if ( $user->belongsToRole($role) === false ) {
               $app = \Slim\Slim::getInstance();
               $app->flash('error', 'Login required');
Example #8
0
require '../vendor/autoload.php';
// Initialize Slim (the router/micro framework used).
$app = new \Slim\Slim();
// and define the engine used for the view @see http://twig.sensiolabs.org
$app->view = new \Slim\Views\Twig();
$app->view->setTemplatesDirectory("../Mini/view");
/******************************************* THE CONFIGS *******************************************************/
// Configs for mode "development" (Slim's default), see the GitHub readme for details on setting the environment
$app->configureMode('development', function () use($app) {
    // pre-application hook, performs stuff before real action happens @see http://docs.slimframework.com/#Hooks
    $app->hook('slim.before', function () use($app) {
        // SASS-to-CSS compiler @see https://github.com/panique/php-sass
        SassCompiler::run("scss/", "css/");
        // CSS minifier @see https://github.com/matthiasmullie/minify
        $minifier = new MatthiasMullie\Minify\CSS('css/style.css');
        $minifier->minify('css/style.css');
        // JS minifier @see https://github.com/matthiasmullie/minify
        // DON'T overwrite your real .js files, always save into a different file
        //$minifier = new MatthiasMullie\Minify\JS('js/application.js');
        //$minifier->minify('js/application.minified.js');
    });
    // Set the configs for development environment
    $app->config(array('debug' => true, 'database' => array('db_host' => 'localhost', 'db_port' => '', 'db_name' => 'scdm', 'db_user' => 'root', 'db_pass' => '')));
});
// Configs for mode "production"
$app->configureMode('production', function () use($app) {
    // Set the configs for production environment
    $app->config(array('debug' => false, 'database' => array('db_host' => '', 'db_port' => '', 'db_name' => '', 'db_user' => '', 'db_pass' => '')));
});
/************************************* Load Organization Defaults ***********************************************/
$organization_defaults = array('address1' => '92 High St', 'address2' => null, 'city' => 'Winter Haven', 'state' => 'FL', 'zipcode' => '33880');
/******************************************** THE MODELS ********************************************************/
Example #9
0
ORM::configure('mysql:host=localhost;dbname=dbNameHere;charset=utf8');
ORM::configure('username', 'dbUserName');
ORM::configure('password', 'dbPassword');
*/
// Auto Loaders
include_once '../private/autoloaders/autoloader main.php';
// LESS Compiler
include_once "../private/includes/less.inc.php";
/* Use for when in a sub-folder
define('BASE_PATH', '/subDirectory/directory/');*/
// Start Slim's Instance & Twig View
$app = new \Slim\Slim(array('mode' => 'development', 'view' => new \Slim\Views\Twig(), 'templates.path' => '../private/templates/'));
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true));
    /// Moved to top to catch any bugs above this for now.
    //define('DEBUGGING', true);
    //ini_set("display_errors", 1);
    //error_reporting(E_ALL);
});
// Set Global View Data
$view = $app->view();
$app->view->getInstance()->addFilter(new Twig_SimpleFilter('debug', 'debug'));
$view->setData(array('loggedIn' => UserSession::isLoggedIn(), 'siteName' => 'Lite Stack PHP', 'siteShort' => 'LS'));
//endregion </Init>
//region	<Middleware>
$authCheck = function () use($app) {
    if (!UserSession::isLoggedIn()) {
        $app->flash('error', "You must be logged in to access this page");
        $app->redirect('/');
    }
};
Example #10
0
    $mode = $_SERVER['MODE'];
} else {
    if (file_exists(__DIR__ . '/env.live')) {
        $mode = 'live';
    } elseif (file_exists(__DIR__ . '/env.local')) {
        $mode = 'local';
    }
}
$logWriter = null;
$app = new \Slim\Slim(array('templates.path' => __DIR__ . '/views/', 'mode' => $mode));
$env = $app->environment();
$app->configureMode('live', function () use($app, $env) {
    $env['URLBASE'] = 'http://nesbot.com';
    $env['URLIMG'] = '/img/';
    $env['URLFULLIMG'] = $env['URLBASE'] . $env['URLIMG'];
    $env['URLCSS'] = '/css/';
    $env['URLJS'] = '/js/';
    $env['GATRACKER'] = 'UA-5684902-5';
    $app->config('debug', false);
    $logWriter = new \Slim\Extras\Log\DateTimeFileWriter(array('path' => __DIR__ . '/../logs'));
});
$app->configureMode('local', function () use($app, $env) {
    $env['URLBASE'] = 'http://127.0.0.1';
    $env['URLIMG'] = '/img/';
    $env['URLFULLIMG'] = $env['URLBASE'] . $env['URLIMG'];
    $env['URLCSS'] = '/css/';
    $env['URLJS'] = '/js/';
    //$env['GATRACKER'] = '';
    $app->config('debug', true);
    $out = array();
    exec(sprintf("php %s/bundle.php", __DIR__), $out);
    if (count($out) > 1) {
Example #11
0
<?php

require 'sub_modules/slimphp/Slim/Slim.php';
require 'lib/oblivious.php';
error_reporting(E_ALL);
$oblivious_settings = array('app_name' => 'haze', 'mode' => 'development', 'meta_tags' => array('isinvite', 'nickname', 'syntaxcoloring'));
$oblivious = new \Oblivious\Oblivious(array($oblivious_settings));
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(array('cookies.encrypt' => true, 'mode' => 'development', 'templates.path' => './html/oblivious'));
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app, $oblivious) {
    $app->config(array('log.enable' => true, 'debug' => true));
});
//We can inject the $app variable into the callback function with the use keyword:
$app->get('/', function () use($app, $oblivious) {
    $view_data = array('js_path' => '/html/oblivious/js/home.js', 'nav_breadcrumb' => '', 'path_from_index' => '/html/oblivious/', 'nav_path' => '/');
    $app->render('html_top.php', $view_data);
    $app->render('oblivious.php', $view_data);
    $app->render('html_bottom.php', $view_data);
});
$app->get('/view/add/', function () use($app, $oblivious) {
    $view_data = array('js_path' => '/html/oblivious/js/add.js', 'nav_breadcrumb' => ':add', 'path_from_index' => '/html/oblivious/', 'nav_path' => '/');
    $app->render('html_top.php', $view_data);
    $app->render('add-entry.php', $view_data);
    $app->render('html_bottom.php', $view_data);
});
$app->get('/view/settings/', function () use($app, $oblivious) {
    $view_data = array('js_path' => '/html/oblivious/js/settings.js', 'nav_breadcrumb' => ':settings', 'path_from_index' => '/html/oblivious/', 'nav_path' => '/');
    $app->render('html_top.php', $view_data);
    $app->render('settings.php', $view_data);
    $app->render('html_bottom.php', $view_data);
Example #12
0
		//error_log($mensaje,3,$pathLogFile);

	}*/
//funcion se usa para obtener el tiempo de respuesta en segundo
/*function microtimeFloat(){
		list($usec, $sec) = explode(" ", microtime());
    	return ((float)$usec + (float)$sec);
	}*/
function customLogFile($message)
{
    $path = $_SERVER["DOCUMENT_ROOT"];
    ///var/www/html/ageacifras/home/www
    $path = $path . "/service/logs/log.log";
    $message = $message . "\n";
    error_log($message, 3, $path);
}
$pathLog = './logs';
checkLogFolder($pathLog);
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(array('mode' => 'produccion'));
$app->configureMode('produccion', function () use($app, $pathLog) {
    $app->config(array('log.enabled' => true, 'DEBUG' => false, 'cookies.lifetime' => '+1 days', 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(array('path' => $pathLog)), 'log.level' => \Slim\Log::ERROR, 'image.repo' => 'files/', 'image.repo.url' => 'service/files/'));
});
$app->configureMode('development', function () use($app, $pathLog) {
    $app->config(array('log.enable' => true, 'DEBUG' => TRUE, 'cookies.lifetime' => '+1 days', 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(array('path' => $pathLog)), 'log.level' => \Slim\Log::ERROR, 'image.repo' => 'files/', 'image.repo.url' => '../agea-cifras-service/files/'));
});
require_once 'middleware/config.error.php';
require_once 'middleware/config.di.php';
require_once 'middleware/config.rest.php';
require 'middleware/core/connect.php';
$app->add(new AppMiddleware());
Example #13
0
$app = new \Slim\Slim();
// and define the engine used for the view @see http://twig.sensiolabs.org
$app->view = new \Slim\Views\Twig();
$app->view->setTemplatesDirectory("../Onboard/view");
/******************************************* THE CONFIGS *******************************************************/
// Configs for mode "development" (Slim's default), see the GitHub readme for details on setting the environment
$app->configureMode('development', function () use($app) {
    // pre-application hook, performs stuff before real action happens @see http://docs.slimframework.com/#Hooks
    $app->hook('slim.before', function () use($app) {
        // SASS-to-CSS compiler @see https://github.com/panique/php-sass
        SassCompiler::run("scss/", "css/");
        // CSS minifier @see https://github.com/matthiasmullie/minify
        $minifier = new MatthiasMullie\Minify\CSS('css/style.css');
        $minifier->minify('css/style.css');
        // JS minifier @see https://github.com/matthiasmullie/minify
        // DON'T overwrite your real .js files, always save into a different file
        $minifier = new MatthiasMullie\Minify\JS('js/index-page.js');
        $minifier->minify('js/index-page.minified.js');
        $minifier = new MatthiasMullie\Minify\JS('js/search-properties.js');
        $minifier->minify('js/search-properties.minified.js');
    });
    // Set the configs for development environment
    // Get Onboard Property API Key here, https://developer.onboard-apis.com/
    $app->config(array('debug' => true, 'obpropapi' => array('api_url' => 'https://search.onboard-apis.com/propertyapi/v1.0.0/', 'api_key' => 'Insert Your Onboard Property API Key')));
});
/******************************************** THE MODEL ********************************************************/
// Initialize the model, pass the api configs. $model can now perform all methods from Onboard\model\model.php
$model = new \Onboard\Model\Model($app->config('obpropapi'));
/************************************ THE ROUTES / CONTROLLERS *************************************************/
// GET request on homepage, simply show the view template index.twig
$app->get('/', function () use($app) {
Example #14
0
<?php

session_start();
use Illuminate\Database\Capsule\Manager as Captule;
require 'vendor/autoload.php';
require 'config/database.php';
require 'middleware/auth.php';
$app = new \Slim\Slim(['view' => new \Slim\Views\Twig(), 'mode' => 'development']);
$app->add(new \Slim\Middleware\SessionCookie(['secret' => 'myappsecret']));
$app->configureMode('test', function () use($app) {
    $app->config(['log.enable' => false, 'debug' => true]);
});
$app->configureMode('development', function () use($app) {
    $app->config(['log.enable' => false, 'debug' => true]);
});
$app->configureMode('production', function () use($app) {
    $app->config(['log.enable' => false, 'debug' => false]);
    $app->error(function () use($app) {
        $app->render('errors/500.twig', [], 500);
        # TODO: Implement error logging and admin notification
    });
});
$app->db = function () {
    return new Captule();
};
$view = $app->view();
$view->setTemplatesDirectory('app/views');
$view->parserExtensions = [new \Slim\Views\TwigExtension()];
require 'routes.php';
Example #15
0
 * Register illuminate/database to the application
 */
$app->db = function () {
    return new \Illuminate\Database\Capsule\Manager();
};
/**
 * Register slim view
 */
$view = $app->view();
$view->setTemplatesDirectory(__DIR__ . '/../resources/views');
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
$view->parserOptions = array('debug' => true, 'cache' => dirname(__FILE__) . '/cache');
/**
 * Register Slim Extras CsrfMiddleWare Gaurd
 */
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
/**
 * Register Slim SessionCookie
 */
$app->add(new \Slim\Middleware\SessionCookie());
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true));
    // Register flip/whoops error handler
    $app->config('whoops.editor', 'sublime');
    $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
});
Example #16
0
require '../app/src/View/Filters.php';
require '../app/src/View/Functions.php';
$config = array();
$configFile = realpath(__DIR__ . '/../config/config.php');
if (is_readable($configFile)) {
    include $configFile;
} else {
    include realpath(__DIR__ . '/../config/config.php.dist');
}
// Wrap the Config Data with the Application Config object
$config['slim']['custom'] = new \Application\Config($config['slim']['custom']);
// initialize Slim
$app = new \Slim\Slim(array_merge($config['slim'], array('view' => new \Slim\Views\Twig())));
$app->configureMode('development', function () use($app) {
    error_reporting(-1);
    ini_set('display_errors', 1);
    ini_set('html_errors', 1);
    ini_set('display_startup_errors', 1);
});
// Pass the current mode to the template, so we can choose to show
// certain things only if the app is in live/development mode
$app->view()->appendData(array('slim_mode' => $config['slim']['mode']));
// Other variables needed by the main layout.html.twig template
$app->view()->appendData(array('google_analytics_id' => $config['slim']['custom']['googleAnalyticsId'], 'user' => isset($_SESSION['user']) ? $_SESSION['user'] : false));
// set Twig base folder, view folder and initialize Joindin filters
$app->view()->parserDirectory = realpath(__DIR__ . '/../vendor/Twig/lib/Twig');
$app->view()->setTemplatesDirectory('../app/templates');
View\Filters\initialize($app->view()->getEnvironment(), $app);
View\Functions\initialize($app->view()->getEnvironment(), $app);
if (isset($config['slim']['twig']['cache'])) {
    $app->view()->getEnvironment()->setCache($config['slim']['twig']['cache']);
} else {
Example #17
0
<?php

use Noodlehaus\Config;
require ROOT_PATH . '/vendor/autoload.php';
session_start();
session_cache_limiter(false);
ini_set('display_errors', 'On');
date_default_timezone_set('Asia/Jakarta');
// Instantiate the app
$app = new \Slim\Slim(array('mode' => 'development', 'debug' => true, 'templates.path' => ROOT_PATH . '/src', 'view' => new \Slim\Views\Twig()));
// Configuration application mode
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(ROOT_PATH . "/app/config/{$app->mode}.php");
});
// Initial authentication
$app->auth = false;
// Set up dependencies
require ROOT_PATH . '/app/services/dependencies.php';
// Register middleware
require ROOT_PATH . '/app/services/middleware.php';
// Set up database
require ROOT_PATH . '/app/services/database.php';
// Filter routes
require ROOT_PATH . '/app/services/filter.php';
// Helpers class and function
require ROOT_PATH . '/src/Helpers/Helper.php';
// Register routes
require ROOT_PATH . '/app/routes.php';
Example #18
0
require_once 'login_middleware.php';
require_once 'caching_middleware.php';
require_once 'mailer.php';
require_once 'metadata_epub.php';
use dflydev\markdown\MarkdownExtraParser;
# Allowed languages, i.e. languages with translations
$allowedLangs = array('de', 'en', 'fr', 'it', 'nl', 'gl');
# Fallback language if the browser prefers other than the allowed languages
$fallbackLang = 'en';
# Application Name
$appname = 'BicBucStriim';
# App version
$appversion = '1.3.4';
# Init app and routes
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig(), 'mode' => 'production'));
$app->configureMode('production', 'confprod');
$app->configureMode('development', 'confdev');
$app->configureMode('debug', 'confdebug');
/**
 * Configure app for production
 */
function confprod()
{
    global $app, $appname, $appversion;
    $app->config(array('debug' => false, 'cookies.lifetime' => '1 day', 'cookies.secret_key' => 'b4924c3579e2850a6fad8597da7ad24bf43ab78e'));
    $app->getLog()->setEnabled(true);
    $app->getLog()->setLevel(\Slim\Log::WARN);
    $app->getLog()->info($appname . ' ' . $appversion . ': Running in production mode.');
}
/**
 * Configure app for development
Example #19
0
File: index.php Project: guhya/Slim
$twig = $app->view->getEnvironment();
//Try to guess the browser, if it's mobile browser, adjust some bootstrap css accordingly
$twig->addGlobal("isMobile", $util->isProbablyMobile());
$twig->addGlobal("WEB_ROOT", "/public");
$twig->addGlobal("IMG_ERROR", "/img/noimage.jpg");
$twig->addGlobal("FACEBOOK_ID", FACEBOOK_ID);
//#################################################### THE MAILER ####################################################
//Swift_MailTransport
//->setUsername("")->setPassword("");
$transport = Swift_SmtpTransport::newInstance("", 25);
$mailer = Swift_Mailer::newInstance($transport);
//#################################################### APP VARIABLE ####################################################
$app->GLOBAL = "global value";
/******************************************* THE CONFIGS *******************************************************/
$app->configureMode("development", function () use($app) {
    $app->config(array("debug" => true));
});
$app->configureMode("production", function () use($app) {
    $app->config(array("debug" => false));
});
/******************************************** THE HOOKS ********************************************************/
$app->hook("slim.before.router", function () use($app, $twig, $util) {
    //Initial attempt to determine what menu is being requested, can be overwritten in each router
    $menu = explode("/", $app->request->getResourceUri())[1];
    $twig->addGlobal("menu", $menu);
    //Intercept session and tell view whether the user is logged in or not
    if (isset($_SESSION["user"])) {
        $twig->addGlobal("userSession", $_SESSION["user"]);
    } else {
        $twig->addGlobal("userSession", "");
    }
Example #20
0
<?php

/*
* (Slim) Application Config
*/
$app = new \Slim\Slim(array('templates.path' => 'templates', 'mode' => 'development', 'theme' => 'default'));
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
    R::freeze(TRUE);
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => true));
    //R::debug(true);
    R::freeze(true);
});
// Create monolog logger and store logger in container as singleton
// (Singleton resources retrieve the same log resource definition each time)
/*$app->container->singleton('log', function () {
    $log = new \Monolog\Logger('slim-skeleton');
    $log->pushHandler(new \Monolog\Handler\StreamHandler('logs/app.log', \Monolog\Logger::DEBUG));
    return $log;
});
*/
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
/*[Default Time Zone]*/
date_default_timezone_set('Asia/Dhaka');
$trdate = date("Y-m-d H:i:s", time());
Example #21
0
File: init.php Project: buisoft/wob
<?php

session_cache_limiter(false);
session_start();
ob_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim\Slim(['mode' => file_get_contents(INC_ROOT . '/app/config/env/mode.php'), 'view' => new Slim\Views\Twig(), 'templates.path' => INC_ROOT . '/views/']);
$app->add(new BuiSoft\Middleware\BeforeMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Noodlehaus\Config::load(INC_ROOT . "/app/config/env/{$app->mode}.php");
});
require INC_ROOT . '/app/config/database.php';
require INC_ROOT . '/app/filters/authentication.php';
require INC_ROOT . '/app/config/api.php';
require INC_ROOT . '/app/config/routes.php';
require INC_ROOT . '/app/config/queue.php';
require INC_ROOT . '/app/config/session.php';
require INC_ROOT . '/app/config/cache.php';
require INC_ROOT . '/app/config/languages.php';
require INC_ROOT . '/app/config/app.php';
$view = $app->view();
$view->parserOptions = ['debug' => $app->config->get('twig.debug')];
$view->parserExtensions = [new Slim\Views\TwigExtension()];
Example #22
0
    require_once $configFile;
} else {
    exit("no file of configuration found, exit\n");
}
// Basic config for Slim Application
$config['app'] = array('db.dsn' => 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', 'db.username' => DB_USERNAME, 'db.password' => DB_PASSWORD, 'name' => 'Elearning', 'log.enabled' => true, 'log.level' => Slim\Log::INFO, 'mode' => $slim_mode == "default" ? 'production' : $slim_mode);
// Create application instance with config
$app = new Slim\Slim($config['app']);
// Add dependencies
$app->container->singleton('log', function () {
    $log = new \Monolog\Logger('el_api_logs');
    $log->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__FILE__) . '/share/logs/' . date('Y-m-d') . '.log'));
    return $log;
});
$app->container->singleton('dbHelperObject', function () {
    $dbHelperObject = new dbHelper(DBHELPER_MODE);
    return $dbHelperObject;
});
$log = $app->container['log'];
$dbHelperObject = $app->container['dbHelperObject'];
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => TRUE, 'log.level' => Slim\Log::WARN, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => true, 'log.level' => Slim\Log::DEBUG, 'log.writer' => $app->container['log'], 'debug' => true));
});
$app->add(new \Slim\Middleware\JwtAuthentication(["logger" => $log, "secret" => SECRETJWT, "rules" => [new \Slim\Middleware\JwtAuthentication\RequestPathRule(["path" => "/api/v1", "passthrough" => ["/api/v1/login", "/api/v1/signup", "/api/v1"]]), new \Slim\Middleware\JwtAuthentication\RequestMethodRule(["passthrough" => ["OPTIONS"]])], "callback" => function ($decoded, $app) {
    $app->jwt = $decoded;
}]));
Example #23
0
        $response_body_array['errors'][] = 65;
    }
    $result_65->free();
    if ($result_75->fetch_assoc()['@error_75']) {
        $response_body_array['errors'][] = 75;
    }
    $result_75->free();
    // return response
    echo prepare_response_body($response_body_array);
    return;
}
// create API
$app = new \Slim\Slim(array('mode' => 'development'));
$app->setName('See Time API');
$app->configureMode('development', function () use($app) {
    $app->config(array('debug' => true, 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG));
});
$app->configureMode('production', function () use($app) {
    $app->config(array('debug' => false, 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG));
});
$app->group('/users', function () use($app) {
    global $decode_body;
    $app->post('', $decode_body, function () {
        create_user();
    });
    $app->group('/:username', function () use($app) {
        global $check_token_exists;
        global $decode_body;
        $app->put('', $check_token_exists, $decode_body, function ($username) {
            change_pwd($username);
        });
Example #24
0
|--------------------------------------------------------------------------
| Initialize the database
|--------------------------------------------------------------------------
*/
ActiveRecord\Config::initialize(function ($cfg) use($app) {
    $dbconfig = $app->config('database');
    $cfg->set_model_directory(ROOT . '/app/models');
    // Loop through the connection settings  and create our connection strings
    $connections = array();
    foreach ($dbconfig['connections'] as $name => $settings) {
        $connection = sprintf('%s://%s:%s@%s/%s?charset=%s', $settings['driver'], $settings['user'], $settings['password'], $settings['host'], $settings['dbname'], $settings['encoding']);
        $connections[$name] = $connection;
    }
    $cfg->set_connections($connections);
    $app->configureMode('development', function () use($cfg) {
        $cfg->set_default_connection('development');
    });
    $app->configureMode('production', function () use($cfg) {
        $cfg->set_default_connection('production');
    });
});
/*
|--------------------------------------------------------------------------
| Create our 404 Not Found response
|--------------------------------------------------------------------------
|
| We do it here before we load the controllers in case a controller wants
| to specify a custom 404 Not Found response.
*/
$app->notFound(function () use($app) {
    $app->response->headers->set('Content-Type', 'application/json');
Example #25
0
$root_dir = dirname(__DIR__);
/**
 * Use Dotenv to set required environment variables and load .env file in root
 */
$dotenv = new Dotenv\Dotenv($root_dir);
if (file_exists($root_dir . '/.env')) {
    $dotenv->load();
    $dotenv->required(['SITE_URL']);
}
// Fetch the configuration settings
$config = (require_once 'config.php');
// Initialise the Slim framework
$app = new \Slim\Slim(array('mode' => getenv("ENVIRONMENT")));
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app, &$config) {
    $app->config(array('log.enable' => true, 'debug' => false));
    $config['debug_mode'] = false;
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app, &$config, $root_dir) {
    $app->config(array('log.enable' => false, 'debug' => true));
    $config['debug_mode'] = true;
    $config['debug_file'] = $root_dir . '/debug.log';
});
// Return an instance of HybridAuth
$app->container->singleton('hybridInstance', function () use($config) {
    $instance = new Hybrid_Auth($config);
    return $instance;
});
// Return an instance of NameParser
$app->container->singleton('parserInstance', function () {
    $instance = new Parser();
Example #26
0
 /**
  * app config
  * @return [type] [description]
  */
 public static function initialize()
 {
     $app = new \Slim\Slim();
     $logger = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array('handlers' => array(new \Monolog\Handler\StreamHandler('./logs/dev.log'))));
     $app->config(array('log.writer' => $logger, 'view' => new View(), 'mode' => 'development', 'templates.path' => './views', 'base.uri' => '/'));
     $app->session = function () {
         return new Session();
     };
     $app->cookie = function () {
         return new CookieJar();
     };
     $app->sessionDataStore = function () use($app) {
         return new SessionDataStore($app->session);
     };
     $app->nonce = function () use($app) {
         return new Nonce($app->session);
     };
     $app->handler = function () use($app) {
         return new Handler($app);
     };
     $app->doorman = function () use($app) {
         return new Doorman($app->db, $app->sessionDataStore, $app->cookie);
     };
     $app->container->singleton('db', function () use($app) {
         return new DB($app->config('db.dsn'), $app->config('db.user'), $app->config('db.password'));
     });
     $app->postman = function () {
         return new Postman();
     };
     $app->lang = function () use($app) {
         $get = $app->request->get();
         if (isset($get['lang'])) {
             $app->session->set('app.language', $get['lang']);
         }
     };
     $app->allowedFileTypes = function () {
         return array('image/png', 'image/gif', 'image/jpg');
     };
     $app->defaultViewInfo = function () {
         return array('meta.properties' => array('' => '', '' => '', '' => ''), 'styles' => array('' => '', '' => '', '' => ''), 'scripts' => array('' => '', '' => '', '' => ''), 'layout.data' => array('' => '', '' => '', '' => ''));
     };
     $app->defaultRoles = function () {
         $roles = array('admin');
     };
     $app->configureMode('production', function () use($app) {
         $credentials = json_decode(file_get_contents('db.json'), true);
         $app->config('db.dsn', $credentials['dsn']);
         $app->config('db.user', $credentials['user']);
         $app->config('db.password', $credentials['password']);
     });
     $app->configureMode('development', function () use($app) {
         $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
         $app->add(new \Slim\Middleware\DebugBar());
         $app->config('db.dsn', 'mysql:dbname=maltz-novo;host=localhost');
         $app->config('db.user', 'root');
         $app->config('db.password', 'root');
         $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'debug' => true, 'per_page' => 12));
         $app->session->set('user.id', 1);
     });
     $controllers = array('Maltz\\Package\\Sys\\Ctrl\\Sys', 'Maltz\\Package\\Calendar\\Ctrl\\Upload', 'Maltz\\Package\\Content\\Ctrl\\Content', 'Maltz\\Package\\Calendar\\Ctrl\\Calendar', 'Maltz\\Package\\GeoLocation\\Ctrl\\GeoLocation', 'Maltz\\Package\\Store\\Ctrl\\Store', 'Maltz\\Package\\Project\\Ctrl\\Project', 'Maltz\\Package\\SiteBuilding\\Ctrl\\SiteBuilding', 'Maltz\\Package\\Radar\\Ctrl\\Radar', 'Maltz\\Package\\Secult\\Ctrl\\Secult', 'Maltz\\Package\\Portfolio\\Ctrl\\Portfolio');
     foreach ($controllers as $controller) {
         $ctrl = new $controller();
         $app = $ctrl->route($app);
     }
     return $app;
 }
Example #27
0
        if (file_exists($file)) {
            return include $file;
        }
        return array();
    }
}
/**
 * Prepare app
 */
$app = new \Slim\Slim(_loadConfig('app/general'));
// $app->setName('Slim Framework Quickstart');
/**
 * Only invoked if mode is "production"
 */
$app->configureMode('production', function () use($app) {
    $app->config(_loadConfig('app/production'));
});
/**
 * Only invoked if mode is "development"
 */
$app->configureMode('development', function () use($app) {
    $app->config(_loadConfig('app/development'));
});
/**
 * Create monolog logger and store logger in container as singleton
 * (Singleton resources retrieve the same log resource definition each time)
 * @todo set custom error handler
 */
$app->container->singleton('log', function () use($app) {
    $logpath = APPPATH . 'logs/' . date('Y/m');
    $logfile = $logpath . '/' . date('d') . '.log';
Example #28
0
<?php

use lib\Config;
defined('APP_WEB_ROOT_PATH') or define('APP_WEB_ROOT_PATH', __DIR__);
defined('APP_ROOT_PATH') or define('APP_ROOT_PATH', dirname(__DIR__));
require implode(DIRECTORY_SEPARATOR, [APP_ROOT_PATH, 'vendor', 'autoload.php']);
//require(implode(DIRECTORY_SEPARATOR, [APP_ROOT_PATH, 'vendor', 'slim', 'slim', 'Slim', 'Slim.php']));
//\Slim\Slim::registerAutoloader();
require implode(DIRECTORY_SEPARATOR, [APP_ROOT_PATH, 'src', 'config', 'config.php']);
$app = new \Slim\Slim(Config::$confArray['init']);
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(Config::$confArray['production']);
});
//// Only invoked if mode is "development"
//$app->configureMode('development', function () use ($app) {
//$app->config(\lib\Config::$confArray['development']);
//});
// Automatically load router files
$routers = glob(APP_ROOT_PATH . '/src/router/*.php');
foreach ($routers as $router) {
    require $router;
}
$app->run();
Example #29
0
 /**
  * Test mode configuration when not callable
  */
 public function testModeConfigurationWhenNotCallable()
 {
     $flag = 0;
     $s = new \Slim\Slim(array('mode' => 'production'));
     $s->configureMode('production', 'foo');
     $this->assertEquals(0, $flag);
 }
Example #30
0
error_reporting(E_ALL);
ini_set("display_errors", 1);
require '../vendor/autoload.php';
$slim = new \Slim\Slim();
$slim->view = new \Slim\Views\Twig();
$slim->view->setTemplatesDirectory("../jrods/view");
/* CONFIGS 
*******************************************************/
require '../jrods/etc/db_config.php';
$slim->configureMode('development', function () use($slim) {
    $slim->hook('slim.before', function () use($slim) {
        // SASS-to-CSS compiler @see https://github.com/panique/php-sass
        //SassCompiler::run("scss/", "css/");
        // CSS minifier @see https://github.com/matthiasmullie/minify
        //$minifier = new MatthiasMullie\Minify\CSS('css/style.css');
        //$minifier->minify('css/style.css');
        // JS minifier @see https://github.com/matthiasmullie/minify
        // DON'T overwrite your real .js files, always save into a different file
        //$minifier = new MatthiasMullie\Minify\JS('js/application.js');
        //$minifier->minify('js/application.minified.js');
    });
    $slim->config(['debug' => true, 'database' => ['db_host' => DB_HOST, 'db_port' => DB_PORT, 'db_name' => DB_NAME, 'db_user' => DB_USER, 'db_pass' => DB_PASS]]);
});
/* THE MODEL 
*******************************************************/
$db = \jrods\lib\DB::createDB($slim->config('database'));
$model = new \jrods\Model\Model($db);
$user = new \jrods\lib\User($db);
/* THE ROUTES / CONTROLLERS 
*******************************************************/
// Index
$slim->get('/', function () use($slim, $model) {