share(function ($app) { return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']); }); $app->before(function (Request $request) use ($app) { if (0 === strpos($request->getPathInfo(), '/setup')) { if (!$app['phraseanet.configuration-tester']->isBlank()) { return $app->redirectPath('homepage'); } } else { $app['firewall']->requireSetup(); } }); $app->before(function(Request $request) use ($app) { if ($request->cookies->has('persistent') && !$app['authentication']->isAuthenticated()) { if (false !== $session = $app['authentication.persistent-manager']->getSession($request->cookies->get('persistent'))) { $app['authentication']->refreshAccount($session); } } }); $app->bindRoutes(); if (PhraseaApplication::ENV_DEV === $app->getEnvironment()) { $app->register($p = new WebProfilerServiceProvider(), array( 'profiler.cache_dir' => $app['root.path'] . '/tmp/cache/profiler', )); $app->mount('/_profiler', $p); } $app['dispatcher'] = $app->share( $app->extend('dispatcher', function($dispatcher, PhraseaApplication $app){ $dispatcher->addSubscriber(new BridgeExceptionSubscriber($app)); $dispatcher->addSubscriber(new FirewallSubscriber()); $dispatcher->addSubscriber(new JsonRequestSubscriber()); $dispatcher->addSubscriber(new DebuggerSubscriber($app)); return $dispatcher; }) ); return $app; }, isset($environment) ? $environment : null);