/**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     // Create a new Database connection
     $database = new Capsule();
     $database->addConnection(array('driver' => 'mysql', 'host' => $app->config('database.host'), 'database' => $app->config('database.database'), 'username' => $app->config('database.user'), 'password' => $app->config('database.password'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci'));
     // Makes the new "capsule" the global static instance.
     $database->setAsGlobal();
     // Boots Eloquent to be used by Sentry.
     $database->bootEloquent();
     $app['sentry'] = $app->share(function ($app) {
         $hasher = new \Cartalyst\Sentry\Hashing\NativeHasher();
         $userProvider = new \Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
         $groupProvider = new \Cartalyst\Sentry\Groups\Eloquent\Provider();
         $throttleProvider = new \Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
         $session = new SymfonySentrySession($app['session']);
         $cookie = new \Cartalyst\Sentry\Cookies\NativeCookie(array());
         $sentry = new \Cartalyst\Sentry\Sentry($userProvider, $groupProvider, $throttleProvider, $session, $cookie);
         Sentry::setupDatabaseResolver($app['db']);
         $throttleProvider->disable();
         return $sentry;
     });
 }
示例#2
0
 function getApp()
 {
     if (isset($this->_app)) {
         return $this->_app;
     }
     // Initialize out Silex app and let's do it
     $app = new \Silex\Application();
     if ($this->getConfig('twig.debug')) {
         $app['debug'] = $this->getConfig('twig.debug');
     }
     // Register our session provider
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->before(function ($request) use($app) {
         $app['session']->start();
     });
     $app['url'] = $this->getConfig('application.url');
     $app['uploadPath'] = $this->getConfig('upload.path');
     $app['confAirport'] = $this->getConfig('application.airport');
     $app['arrival'] = $this->getConfig('application.arrival');
     $app['departure'] = $this->getConfig('application.departure');
     // Register the Twig provider and lazy-load the global values
     $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => APP_DIR . $this->getConfig('twig.template_dir')));
     $that = $this;
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($that) {
         $twig->addGlobal('site', array('url' => $that->getConfig('application.url'), 'title' => $that->getConfig('application.title'), 'email' => $that->getConfig('application.email'), 'eventurl' => $that->getConfig('application.eventurl'), 'enddate' => $that->getConfig('application.enddate')));
         return $twig;
     }));
     // Register our use of the Form Service Provider
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Silex\Provider\ValidatorServiceProvider());
     $app->register(new \Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array()));
     $app['db'] = $this->getDb();
     $app['spot'] = $this->getSpot();
     $app['purifier'] = $this->getPurifier();
     // We're using Sentry, so make it available to app
     $app['sentry'] = $app->share(function () use($app) {
         $hasher = new \Cartalyst\Sentry\Hashing\NativeHasher();
         $userProvider = new \Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
         $groupProvider = new \Cartalyst\Sentry\Groups\Eloquent\Provider();
         $throttleProvider = new \Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
         $session = new \OpenCFP\SymfonySentrySession($app['session']);
         $cookie = new \Cartalyst\Sentry\Cookies\NativeCookie(array());
         $sentry = new \Cartalyst\Sentry\Sentry($userProvider, $groupProvider, $throttleProvider, $session, $cookie);
         \Cartalyst\Sentry\Facades\Native\Sentry::setupDatabaseResolver($app['db']);
         $throttleProvider->disable();
         return $sentry;
     });
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
         $twig->addGlobal('user', $app['sentry']->getUser());
         return $twig;
     }));
     // Configure our flash messages functionality
     $app->before(function () use($app) {
         $flash = $app['session']->get('flash');
         $app['session']->set('flash', null);
         if (!empty($flash)) {
             $app['twig']->addGlobal('flash', $flash);
         }
     });
     // Add current page global
     $app->before(function (Request $request) use($app) {
         $app['twig']->addGlobal('current_page', $request->getRequestUri());
     });
     // Define error template paths
     if (!$app['debug']) {
         $app->error(function (\Exception $e, $code) use($app) {
             switch ($code) {
                 case 401:
                     $message = $app['twig']->render('error/401.twig');
                     break;
                 case 403:
                     $message = $app['twig']->render('error/403.twig');
                     break;
                 case 404:
                     $message = $app['twig']->render('error/404.twig');
                     break;
                 default:
                     $message = $app['twig']->render('error/500.twig');
             }
             return new Response($message, $code);
         });
     }
     $app = $this->defineRoutes($app);
     // Add the starting date for submissions
     $app['cfpdate'] = $this->getConfig('application.cfpdate');
     return $app;
 }