Beispiel #1
0
Datei: App.php Projekt: bd808/SAL
 /**
  * Apply settings to the Slim application.
  *
  * @param \Slim\Slim $slim Application
  */
 protected function configureSlim(\Slim\Slim $slim)
 {
     $slim->config(['parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/')]);
     $slim->configureMode('production', function () use($slim) {
         $slim->config(['debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')]);
         // Install a custom error handler
         $slim->error(function (\Exception $e) use($slim) {
             $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8);
             $slim->log->critical($e->getMessage(), ['exception' => $e, 'errorId' => $errorId]);
             $slim->view->set('errorId', $errorId);
             $slim->render('error.html');
         });
     });
     $slim->configureMode('development', function () use($slim) {
         $slim->config(['debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false]);
     });
 }
Beispiel #2
0
 /**
  * Apply settings to the Slim application.
  *
  * @param \Slim\Slim $slim Application
  */
 protected function configureSlim(\Slim\Slim $slim)
 {
     $slim->config(array('parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/'), 'es.user' => Config::getStr('ES_USER', ''), 'es.password' => Config::getStr('ES_PASSWORD', ''), 'can.edit' => Config::getBool('CAN_EDIT', false), 'can.vote' => Config::getBool('CAN_VOTE', false), 'oauth.enable' => Config::getBool('USE_OAUTH', false), 'oauth.consumer_token' => Config::getStr('OAUTH_CONSUMER_TOKEN', ''), 'oauth.secret_token' => Config::getStr('OAUTH_SECRET_TOKEN', ''), 'oauth.endpoint' => Config::getStr('OAUTH_ENDPOINT', ''), 'oauth.redir' => Config::getStr('OAUTH_REDIR', ''), 'oauth.callback' => Config::getStr('OAUTH_CALLBACK', '')));
     $slim->configureMode('production', function () use($slim) {
         $slim->config(array('debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')));
         // Install a custom error handler
         $slim->error(function (\Exception $e) use($slim) {
             $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8);
             $slim->log->critical($e->getMessage(), array('exception' => $e, 'errorId' => $errorId));
             $slim->view->set('errorId', $errorId);
             $slim->render('error.html');
         });
     });
     $slim->configureMode('development', function () use($slim) {
         $slim->config(array('debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false));
     });
 }
Beispiel #3
0
 public static function configureModes(Slim $app, array $modeConfigs)
 {
     foreach ($modeConfigs as $mode => $config) {
         $app->configureMode($mode, function () use($app, $config) {
             $app->config($config);
         });
     }
 }
Beispiel #4
0
 protected function configureApp(Slim $app, Container $c)
 {
     // Add Middleware
     $app->add($c['profileMiddleware']);
     $app->add($c['navigationMiddleware']);
     $app->add($c['authenticationMiddleware']);
     $app->add($c['sessionCookieMiddleware']);
     // Prepare view
     $app->view($c['twig']);
     $app->view->parserOptions = $this['config']['twig'];
     $app->view->parserExtensions = array($c['slimTwigExtension'], $c['twigExtensionDebug']);
     $config = $this['config'];
     // Dev mode settings
     $app->configureMode('development', function () use($app, $config) {
         $app->config(array('log.enabled' => true, 'log.level' => Log::DEBUG));
         $config['twig']['debug'] = true;
     });
 }
Beispiel #5
0
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
use Myproject\User\User;
use Myproject\Helpers\Hash;
use Myproject\Validation\Validator;
use Myproject\Middleware\BeforeMiddleware;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define(INC_ROOT, dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
require 'database.php';
require 'routes.php';
$app->auth = false;
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user);
});
$view = $app->view;
$view->parserOptions = ['debug' => $app->config->get('twig.debug')];
use OpenTok\OpenTok;
use OpenTok\Role;
use werx\Config\Providers\ArrayProvider;
use werx\Config\Container;
/* ------------------------------------------------------------------------------------------------
 * Slim Application Initialization
 * -----------------------------------------------------------------------------------------------*/
$app = new Slim(array('log.enabled' => true));
/* ------------------------------------------------------------------------------------------------
 * Configuration
 * -----------------------------------------------------------------------------------------------*/
$provider = new ArrayProvider('../config');
$config = new Container($provider);
// Environment Selection
$app->configureMode('development', function () use($config) {
    $config->setEnvironment('development');
});
$config->load(array('opentok'), true);
// Constants
define('NAME_MAX_LENGTH', '100');
/* ------------------------------------------------------------------------------------------------
 * OpenTok Initialization
 * -----------------------------------------------------------------------------------------------*/
$opentok = new OpenTok($config->opentok('key'), $config->opentok('secret'));
/* ------------------------------------------------------------------------------------------------
 * Routing
 * -----------------------------------------------------------------------------------------------*/
// Presence configuration
//
// Response: (JSON encoded)
// *  `apiKey`: The presence session API Key
Beispiel #7
0
<?php

/**
 * app/bootstrap.php
 *
 * @author Zangue <*****@*****.**>
 */
use Slim\Slim;
use Noodlehaus\Config;
//session_cache_limiter(false);
//session_start();
ini_set('display_errors', 'On');
// Require all PHP dependencies using the composer autoloader
require ROOT . DS . 'vendor' . DS . 'autoload.php';
require ROOT . DS . CORE_DIR . DS . 'Router.php';
require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'Model.php';
require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'ErrorModel.php';
require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'Controller.php';
require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'ErrorController.php';
require ROOT . DS . CORE_DIR . DS . 'View' . DS . 'View.php';
require APP_DIR . DS . 'Controller' . DS . 'AppController.php';
require APP_DIR . DS . 'Model' . DS . 'AppModel.php';
// Instantiate a new Slim Application
$app = new Slim(['mode' => 'development', 'templates.path' => VIEW_ROOT]);
// Some more things can be done here. Eg, add a custom middleware
// $app->add(new MyMiddleware());
// Load configuration
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(APP_DIR . DS . "Config" . DS . "{$app->mode}.php");
});
Beispiel #8
0
// use CRB\Cert\Cert;
use CRB\Mail\Mailer;
use CRB\Helpers\Hash;
use CRB\Validation\Validator;
use CRB\Middleware\BeforeMiddleware;
use CRB\Middleware\CsrfMiddleware;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $mode = preg_replace('/\\s+/', '', $app->mode);
    $app->config = Config::load(INC_ROOT . "/app/config/{$mode}.php");
});
require 'database.php';
require 'filters.php';
require 'routes.php';
$app->auth = false;
$app->container->set('user', function () {
    return new User();
});
// $app->container->set('cert', function() {
//   return new Cert;
// });
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
// You can add an environment variable to your local php.ini call APPLICATION_ENV and set it to 'dev'.  This allows you to have the settings of the system change from Dev to Stage or Production based on if it's on your local machine or on a server.  This is helpful when you don't want to remember to turn debugging on and off in your app, and you have database settings that change depending on if it's on the server or not.
//$appMode = getenv("APPLICATION_ENV");
$appMode = "dev";
if ($appMode !== 'dev') {
    $appMode = 'prod';
}
// This logger will write a file for each day of logs.
$logHandlers = array(new \Monolog\Handler\StreamHandler('./logs/' . date('Y-m-d') . '.log'));
if ($appMode !== 'dev') {
    //$logHandlers[]= new \Monolog\Handler\LogglyHandler('loggly api key');
}
$logger = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array('handlers' => $logHandlers, 'processors' => array(new \Monolog\Processor\WebProcessor($_SERVER))));
$app = new Slim(array('mode' => $appMode, 'log.writer' => $logger, 'templates.path' => './views'));
// Only invoked if mode is "prod"
$app->configureMode('prod', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
});
// Only invoked if mode is "dev"
$app->configureMode('dev', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => true));
});
$config = Config::getInstance();
$config->setMode($appMode === 'dev' ? Config::DEVELOPMENT : Config::STAGING);
$app->contentType('application/json');
//$app->add(new OAuthVerifyMiddleware());
include 'routes/user.php';
/// ------------------------- ///
/// --- Utility Functions --- ///
/// ------------------------- ///
/**
 * Returns a formatted response to the requesting client.
Beispiel #10
0
use alexander\Helpers\Hash;
use alexander\Validation\Validator;
use alexander\Middleware\BeforeMiddleware;
use alexander\Middleware\CsrfMiddleware;
use alexander\Mail\Mailer;
session_cache_limiter(false);
session_start();
// only for tutorial
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/" . substr($app->mode, 0, strlen($app->mode) - 1) . ".php");
});
require 'database.php';
require 'filters.php';
require 'routes.php';
$app->auth = false;
// $user = new \alexander\user\user;
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user, $app->hash, $app->auth);
});
Beispiel #11
0
$app->setName('Holidays');
$app->container->singleton('db', function () {
    $database = new PDO("sqlite:" . APP_PATH . "../databases/database.sqlite");
    checkAndInitDatabase($database);
    return $database;
});
$app->container->singleton('periods', function () use($app) {
    return new Periods($app->db);
});
$app->container->singleton('allowances', function () use($app) {
    return new Allowances($app->db);
});
$view = $app->view();
$app->configureMode('production', function () use($app, $view) {
    (new Bootstrap($app, new PdoAdapter($app->db, 'users', 'user', 'hash', new PasswordValidator()), new acl()))->bootstrap();
    $app->config(array('log.enable' => true, 'templates.path' => '../templates', 'debug' => false));
    $view->parserOptions = array('debug' => false, 'cache' => dirname(__FILE__) . '/../cache', 'auto_reload' => true);
    $view->parserExtensions = array(new TwigExtension());
});
$app->configureMode('development', function () use($app, $view) {
    (new Bootstrap($app, new DebugAdapter(), new acl()))->bootstrap();
    $app->authenticator->authenticate("admin", "admin");
    $app->config(array('log.enable' => false, 'templates.path' => '../templates', 'debug' => true));
    $view->parserOptions = array('debug' => true, 'cache' => false);
    $view->parserExtensions = array(new TwigExtension(), new Twig_Extension_Debug());
});
$app->hook('slim.before.router', function () use($app) {
    if ($app->auth->hasIdentity()) {
        $authData = $app->auth->getIdentity();
        $authData['department_name'] = getNameForID($app->db, $authData['department']);
        $app->view()->appendData(array('userInfo' => $authData));
    }
Beispiel #12
0
try {
    Config\Yaml::getInstance()->addFile($appRoot . '/src/xAPI/Config/Config.yml');
} catch (\Exception $e) {
    if (PHP_SAPI === 'cli' && (isset($argv[1]) && $argv[1] === 'setup:db' || isset($argv[0]) && !isset($argv[1]))) {
        // Database setup in progress, ignore exception
    } else {
        throw new \Exception('You must run the setup:db command using the X CLI tool!');
    }
}
// Use Mongo's native long int
ini_set('mongo.native_long', 1);
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app, $appRoot) {
    // Add config
    Config\Yaml::getInstance()->addFile($appRoot . '/src/xAPI/Config/Config.production.yml');
    // Set up logging
    $logger = new Logger\MonologWriter(['handlers' => [new StreamHandler($appRoot . '/storage/logs/production.' . date('Y-m-d') . '.log')]]);
    $app->config('log.writer', $logger);
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app, $appRoot) {
    // Add config
    Config\Yaml::getInstance()->addFile($appRoot . '/src/xAPI/Config/Config.development.yml');
    // Set up logging
    $logger = new Logger\MonologWriter(['handlers' => [new StreamHandler($appRoot . '/storage/logs/development.' . date('Y-m-d') . '.log')]]);
    $app->config('log.writer', $logger);
});
if (PHP_SAPI !== 'cli') {
    $app->url = Url::createFromServer($_SERVER);
}
// Error handling
Beispiel #13
0
$app = new Slim(require_once ROOT . '/app/config/app.php');
$app->setName('RedSlim');
/*
 * 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));
// include all controllers
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' => false, 'auto_reload' => true);
$view->parserExtensions = array(new TwigExtension());
/*
|--------------------------------------------------------------------------
Beispiel #14
0
use Slim\Slim;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
use Codecourse\User\User;
use Codecourse\Helpers\Hash;
use Codecourse\Validation\Validator;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
    // Pulls in the specific config we want to use from mode.php
});
require 'database.php';
require 'routes.php';
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user);
});
$view = $app->view();
$view->parserOptions = ['debug' => $app->config->get('twig.debug')];
$view->parserExtensions = [new TwigExtension()];
Beispiel #15
0
define("ASSETS_PATH", DOC_ROOT . "public/assets/");
define("IMAGE_PATH", ASSETS_PATH . "images/");
define("BANNER_PATH", ASSETS_PATH . "images/banners/");
require DOC_ROOT . 'vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(DOC_ROOT . 'mode.php'), 'view' => new Twig(), 'templates.path' => DOC_ROOT . 'app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$mode = $app->config('mode');
//development
if ($mode == "production") {
    $log = $app->getLog();
    $log->setEnabled(true);
    $log->setWriter(new LogWriter());
}
$app->configureMode($mode, function () use($app) {
    $app->config = Config::load(DOC_ROOT . "app/config/{$app->mode}.php");
});
$config = $app->config;
//$app->config('cookies.domain', $app->config->get('cookie.domain'));
$app->config(array('cookies.domain' => $config->get('cookie.domain'), 'cookies.httponly' => $config->get('cookie.httponly'), 'cookies.secret' => $config->get('cookie.secret')));
require 'database.php';
require 'filters.php';
require 'routes.php';
//echo $dbDriver = $config->get('db.host');
//$user = new  \Core\User\User;
//Make the user available everywhere
$app->container->set('user', function () {
    return new User();
});
$app->container->set('images', function () {
    return new Images();
Beispiel #16
0
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
ini_set('display_errors', 1);
error_reporting(E_ALL);
//Define Main Root
define("INC_ROOT", dirname(__DIR__));
//Define Globals
require_once INC_ROOT . "/app/config/globals.php";
//Database Info
require_once CONFIG_ROOT . "/db.php";
//Composer Autoloader
require_once INC_ROOT . "/vendor/autoload.php";
//Create Slim App
$app = new Slim(["debug" => true, "mode" => file_get_contents(INC_ROOT . "/app/mode.php"), "view" => new Twig(), "templates.path" => VIEWS_ROOT, "routes.case_sensitive" => false, "cookies.encrypt" => true, "cookies.secret_key" => "some_secret", "cookies.cipher" => MCRYPT_RIJNDAEL_256, "cookies.cipher_mode" => MCRYPT_MODE_CBC]);
//Hooks
$app->hook('slim.before', function () use($app) {
    $app->view()->appendData(array('siteUrl' => $app->config->get("template_data.url")));
});
//Set Configuration
$app->configureMode($app->config("mode"), function () use($app) {
    $app->config = Config::load(CONFIG_ROOT . "/{$app->config("mode")}.php");
});
//Include Routes
include ROUTES_ROOT . "/routes.php";
//Twig Configuration
$view = $app->view();
$view->parserOptions = ["debug" => $app->config->get("view.debug")];
$view->parserExtensions = [new TwigExtension()];
//Include Filters
require_once FILTERS_ROOT . "/filters.php";