Beispiel #1
0
 public static function handle(Exception $e)
 {
     if ($e instanceof Flingable) {
         try {
             $e->run();
             $e->next();
             exit;
             // No more exceptions, we are done.
         } catch (Flingable $e) {
             self::handle($e);
         } catch (Exception $e) {
             $loader = new Twig_Loader_Filesystem(APP_ROOT . '/resources/views');
             $twig = new Twig_Environment($loader);
             echo $twig->render('error.twig', ['message' => Cow::say($e->getMessage())]);
             die;
         }
     }
 }
Beispiel #2
0
<?php

require '../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Our web handlers
$app->get('/cowsay', function () use($app) {
    $app['monolog']->addDebug('cowsay');
    return "<pre>" . \Cowsayphp\Cow::say("Cool beans") . "</pre>";
});
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(), array('pdo.dsn' => 'pgsql:dbname=' . ltrim($dbopts["path"], '/') . ';host=' . $dbopts["host"], 'pdo.port' => $dbopts["port"], 'pdo.username' => $dbopts["user"], 'pdo.password' => $dbopts["pass"]));
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(), array('pdo.dsn' => 'pgsql:dbname=' . ltrim($dbopts["path"], '/') . ';host=' . $dbopts["host"], 'pdo.port' => $dbopts["port"], 'pdo.username' => $dbopts["user"], 'pdo.password' => $dbopts["pass"]));
$app->get('/db/', function () use($app) {
    $st = $app['pdo']->prepare('SELECT name FROM test_table');
    $st->execute();
    $names = array();
    while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
        $app['monolog']->addDebug('Row ' . $row['name']);
        $names[] = $row;
    }
    return $app['twig']->render('database.twig', array('names' => $names));
});
$app->run();