Example #1
0
require_once 'bootstrap.php';
define('APP_ROOT', __DIR__);
define('APP_PATH', __DIR__ . '/app/');
define('CONFIG_FILE', APP_PATH . 'config/config.yml');
define('PASSWD_DIR', APP_PATH . 'config/secure');
define('PASSWD_FILE', PASSWD_DIR . '/passwd');
define('VENDOR_PATH', __DIR__ . '/vendor');
define('BASE_URL', (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['BASE']);
define('WEB_URL', BASE_URL . '/web');
$app = new Silex\Application();
$app['template_url'] = WEB_URL;
if (is_readable(CONFIG_FILE)) {
    $app->register(new DerAlex\Silex\YamlConfigServiceProvider(CONFIG_FILE));
    $app['debug'] = $app['config']['debug'];
    Symfony\Component\Debug\ExceptionHandler::register(!$app['debug']);
    if (in_array($app['config']['timezone'], DateTimeZone::listIdentifiers())) {
        date_default_timezone_set($app['config']['timezone']);
    }
}
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views', 'twig.options' => array('debug' => $app['debug'])));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('admin' => array('pattern' => '^/logs', 'form' => array('login_path' => '/login', 'check_path' => '/logs/login_check'), 'users' => array('user' => array('ROLE_USER', is_file(PASSWD_FILE) ? file_get_contents(PASSWD_FILE) : null)), 'logout' => array('logout_path' => '/logs/logout')))));
$app['security.encoder.digest'] = $app->share(function ($app) {
    return new \Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder(10);
});
if (!is_file(PASSWD_FILE)) {
    $app->match('/', function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
        $error = "";
        if ($request->getMethod() == "POST") {
Example #2
0
<?php

$app = new Silex\Application();
$app['debug'] = DEBUG;
Symfony\Component\Debug\ErrorHandler::register();
if ('cli' !== php_sapi_name()) {
    Symfony\Component\Debug\ExceptionHandler::register();
}
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => APP_DIR . '/../logs/app.error.log', 'monolog.level' => Monolog\Logger::ERROR));
$templateDir = APP_DIR . VIEWS_LOCATION;
$templatePaths = array($templateDir, $templateDir . '/templates', $templateDir . '/pages', $templateDir . '/error-pages');
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => $templatePaths, 'twig.options' => array('cache' => APP_DIR . 'cache')));
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale_fallbacks' => array('en')));
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Aws\Silex\AwsServiceProvider(), array('aws.config' => array('key' => AWS_USER_ACCESS_KEY, 'secret' => AWS_USER_SECRET_KEY, 'region' => 'eu-west-1')));
$app['twig']->addGlobal('publicAssetsLocation', PUBLIC_ASSETS_LOCATION);
Example #3
0
function createResponseExc($e)
{
    $exc = new \Symfony\Component\Debug\ExceptionHandler();
    return $exc->createResponse($e);
}