public function register(SilexApplication $app) { $app['phraseanet.appbox'] = $app->share(function (SilexApplication $app) { return new \appbox($app); }); $app['firewall'] = $app->share(function (SilexApplication $app) { return new Firewall($app); }); $app['events-manager'] = $app->share(function (SilexApplication $app) { $events = new \eventsmanager_broker($app); $events->start(); return $events; }); $app['phraseanet.thumb-symlinker'] = $app->share(function (SilexApplication $app) { return SymLinker::create($app); }); $app['phraseanet.thumb-symlinker-encoder'] = $app->share(function (SilexApplication $app) { return SymLinkerEncoder::create($app); }); $app['acl'] = $app->share(function (SilexApplication $app) { return new ACLProvider($app); }); $app['phraseanet.metadata-reader'] = $app->share(function (SilexApplication $app) { $reader = new PhraseanetMetadataReader(); try { $reader->setPdfToText($app['xpdf.pdftotext']); } catch (BinaryNotFoundException $e) { } return $reader; }); $app['phraseanet.metadata-setter'] = $app->share(function () { return new PhraseanetMetadataSetter(); }); $app['phraseanet.user-query'] = function (SilexApplication $app) { return new \User_Query($app); }; $app['phraseanet.logger'] = $app->protect(function ($databox) use($app) { try { return \Session_Logger::load($app, $databox); } catch (\Exception_Session_LoggerNotFound $e) { return \Session_Logger::create($app, $databox, $app['browser']); } }); $app['date-formatter'] = $app->share(function (SilexApplication $app) { return new \phraseadate($app); }); }
public function __construct($environment = self::ENV_PROD) { parent::__construct(); error_reporting(-1); $this['root.path'] = realpath(__DIR__ . '/../../..'); $this->environment = $environment; mb_internal_encoding("UTF-8"); !defined('JETON_MAKE_SUBDEF') ? define('JETON_MAKE_SUBDEF', 0x1) : ''; !defined('JETON_WRITE_META_DOC') ? define('JETON_WRITE_META_DOC', 0x2) : ''; !defined('JETON_WRITE_META_SUBDEF') ? define('JETON_WRITE_META_SUBDEF', 0x4) : ''; !defined('JETON_WRITE_META') ? define('JETON_WRITE_META', 0x6) : ''; $this['charset'] = 'UTF-8'; $this['debug'] = $this->share(function (Application $app) { return Application::ENV_PROD !== $app->getEnvironment(); }); if ($this['debug'] === true) { ini_set('log_errors', 'on'); ini_set('error_log', $this['root.path'] . '/logs/php_error.log'); } $this->register(new BasketMiddlewareProvider()); $this->register(new ACLServiceProvider()); $this->register(new AuthenticationManagerServiceProvider()); $this->register(new BorderManagerServiceProvider()); $this->register(new BrowserServiceProvider()); $this->register(new ConfigurationServiceProvider()); $this->register(new ConfigurationTesterServiceProvider()); $this->register(new ConvertersServiceProvider()); $this->register(new RegistrationServiceProvider()); $this->register(new CacheServiceProvider()); $this->register(new CacheConnectionServiceProvider()); $this->register(new ImagineServiceProvider()); $this->register(new JMSSerializerServiceProvider()); $this->register(new FFMpegServiceProvider()); $this->register(new FeedServiceProvider()); $this->register(new FilesystemServiceProvider()); $this->register(new FtpServiceProvider()); $this->register(new GeonamesServiceProvider()); $this['geonames.server-uri'] = $this->share(function (Application $app) { return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'http://geonames.alchemyasp.com/'); }); $this->register(new MediaAlchemystServiceProvider()); $this['media-alchemyst.configuration'] = $this->share(function (Application $app) { $configuration = []; foreach (['swftools.pdf2swf.binaries' => 'pdf2swf_binary', 'swftools.swfrender.binaries' => 'swf_render_binary', 'swftools.swfextract.binaries' => 'swf_extract_binary', 'unoconv.binaries' => 'unoconv_binary', 'mp4box.binaries' => 'mp4box_binary', 'gs.binaries' => 'ghostscript_binary', 'ffmpeg.ffmpeg.binaries' => 'ffmpeg_binary', 'ffmpeg.ffprobe.binaries' => 'ffprobe_binary', 'ffmpeg.ffmpeg.timeout' => 'ffmpeg_timeout', 'ffmpeg.ffprobe.timeout' => 'ffprobe_timeout', 'gs.timeout' => 'gs_timeout', 'mp4box.timeout' => 'mp4box_timeout', 'swftools.timeout' => 'swftools_timeout', 'unoconv.timeout' => 'unoconv_timeout'] as $parameter => $key) { if ($this['conf']->has(['main', 'binaries', $key])) { $configuration[$parameter] = $this['conf']->get(['main', 'binaries', $key]); } } $imagineDriver = $app['conf']->get(['registry', 'executables', 'imagine-driver']); $configuration['ffmpeg.threads'] = $app['conf']->get(['registry', 'executables', 'ffmpeg-threads']); $configuration['imagine.driver'] = $imagineDriver ?: null; return $configuration; }); $this['media-alchemyst.logger'] = $this->share(function (Application $app) { return $app['monolog']; }); $this->register(new MediaVorusServiceProvider()); $this->register(new MonologServiceProvider()); $this['monolog.name'] = 'Phraseanet logger'; $this['monolog.handler'] = $this->share(function () { return new NullHandler(); }); $this['monolog'] = $this->share($this->extend('monolog', function (Logger $monolog) { $monolog->pushProcessor(new IntrospectionProcessor()); return $monolog; })); $this->register(new MP4BoxServiceProvider()); $this->register(new NotificationDelivererServiceProvider()); $this->register(new ORMServiceProvider()); $this->register(new ManipulatorServiceProvider()); $this->register(new InstallerServiceProvider()); $this->register(new PhraseanetServiceProvider()); $this->register(new PhraseaVersionServiceProvider()); $this->register(new PHPExiftoolServiceProvider()); $this->register(new ReCaptchaServiceProvider()); $this->register(new SubdefServiceProvider()); $this->register(new ZippyServiceProvider()); $this['recaptcha.public-key'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) { return $app['conf']->get(['registry', 'webservices', 'recaptcha-public-key']); } }); $this['recaptcha.private-key'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) { return $app['conf']->get(['registry', 'webservices', 'recaptcha-private-key']); } }); $this->register(new SearchEngineServiceProvider()); $this->register(new SessionHandlerServiceProvider()); $this->register(new SessionServiceProvider(), ['session.test' => $this->getEnvironment() === static::ENV_TEST]); $this['session.storage.test'] = $this->share(function ($app) { return new MockArraySessionStorage(); }); $this['session.storage.handler'] = $this->share(function ($app) { return $this['session.storage.handler.factory']->create($app['conf']); }); $this->register(new SerializerServiceProvider()); $this->register(new ServiceControllerServiceProvider()); $this->register(new SwiftmailerServiceProvider()); $this->register(new TasksServiceProvider()); $this->register(new TemporaryFilesystemServiceProvider()); $this->register(new TokensServiceProvider()); $this->register(new TwigServiceProvider(), ['twig.options' => ['cache' => $this['root.path'] . '/tmp/cache_twig/']]); $this->register(new TranslationServiceProvider(), ['locale_fallbacks' => ['fr'], 'translator.cache-options' => ['debug' => $this['debug'], 'cache_dir' => $this['root.path'] . '/tmp/translations']]); $this['translator'] = $this->share($this->extend('translator', function (CachedTranslator $translator, $app) { $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.fr.xlf', 'fr', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.fr.xlf', 'fr', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.en.xlf', 'en', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.en.xlf', 'en', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.de.xlf', 'de', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.de.xlf', 'de', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.nl.xlf', 'nl', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.nl.xlf', 'nl', 'validators'); return $translator; })); $this->register(new FormServiceProvider()); $this['form.type.extensions'] = $this->share($this->extend('form.type.extensions', function ($extensions) { $extensions[] = new HelpTypeExtension(); return $extensions; })); $this->setupTwig(); $this->register(new UnoconvServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->setupUrlGenerator(); $this->register(new UnicodeServiceProvider()); $this->register(new ValidatorServiceProvider()); $this->register(new XPDFServiceProvider()); $this->register(new FileServeServiceProvider()); $this->register(new ManipulatorServiceProvider()); $this->register(new PluginServiceProvider()); $this['phraseanet.exception_handler'] = $this->share(function ($app) { $handler = PhraseaExceptionHandler::register($app['debug']); $handler->setTranslator($app['translator']); return $handler; }); $this['swiftmailer.transport'] = $this->share(function ($app) { if ($app['conf']->get(['registry', 'email', 'smtp-enabled'])) { $transport = new \Swift_Transport_EsmtpTransport($app['swiftmailer.transport.buffer'], [$app['swiftmailer.transport.authhandler']], $app['swiftmailer.transport.eventdispatcher']); $encryption = null; if (in_array($app['conf']->get(['registry', 'email', 'smtp-secure-mode']), ['ssl', 'tls'])) { $encryption = $app['conf']->get(['registry', 'email', 'smtp-secure-mode']); } $options = $app['swiftmailer.options'] = array_replace(['host' => $app['conf']->get(['registry', 'email', 'smtp-host']), 'port' => $app['conf']->get(['registry', 'email', 'smtp-port']), 'username' => $app['conf']->get(['registry', 'email', 'smtp-user']), 'password' => $app['conf']->get(['registry', 'email', 'smtp-password']), 'encryption' => $encryption, 'auth_mode' => null], $app['swiftmailer.options']); $transport->setHost($options['host']); $transport->setPort($options['port']); // tls or ssl $transport->setEncryption($options['encryption']); if ($app['conf']->get(['registry', 'email', 'smtp-auth-enabled'])) { $transport->setUsername($options['username']); $transport->setPassword($options['password']); $transport->setAuthMode($options['auth_mode']); } } else { $transport = new \Swift_Transport_MailTransport(new \Swift_Transport_SimpleMailInvoker(), $app['swiftmailer.transport.eventdispatcher']); } return $transport; }); $this['imagine.factory'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'executables', 'imagine-driver']) != '') { return $app['conf']->get(['registry', 'executables', 'imagine-driver']); } if (class_exists('\\Gmagick')) { return 'gmagick'; } if (class_exists('\\Imagick')) { return 'imagick'; } if (extension_loaded('gd')) { return 'gd'; } throw new \RuntimeException('No Imagine driver available'); }); $app = $this; $this['phraseanet.logger'] = $this->protect(function ($databox) use($app) { try { return \Session_Logger::load($app, $databox); } catch (\Exception_Session_LoggerNotFound $e) { return \Session_Logger::create($app, $databox, $app['browser']); } }); $this['date-formatter'] = $this->share(function (Application $app) { return new \phraseadate($app); }); $this['xpdf.pdftotext'] = $this->share($this->extend('xpdf.pdftotext', function (PdfToText $pdftotext, Application $app) { if ($app['conf']->get(['registry', 'executables', 'pdf-max-pages'])) { $pdftotext->setPageQuantity($app['conf']->get(['registry', 'executables', 'pdf-max-pages'])); } return $pdftotext; })); $this['dispatcher'] = $this->share($this->extend('dispatcher', function ($dispatcher, Application $app) { $dispatcher->addListener(KernelEvents::REQUEST, [$app, 'initSession'], 254); $dispatcher->addListener(KernelEvents::RESPONSE, [$app, 'addUTF8Charset'], -128); $dispatcher->addSubscriber(new LogoutSubscriber()); $dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app)); $dispatcher->addSubscriber(new MaintenanceSubscriber($app)); $dispatcher->addSubscriber(new CookiesDisablerSubscriber($app)); return $dispatcher; })); $this['log.channels'] = ['monolog', 'task-manager.logger']; $this->register(new LocaleServiceProvider()); $this->mount('/include/minify/', new Minifier()); $this->mount('/permalink/', new Permalink()); $this->mount('/lightbox/', new Lightbox()); $app['plugins.directory'] = $app->share(function () { $dir = __DIR__ . '/../../../plugins'; if (is_dir($dir)) { return realpath($dir); } return $dir; }); }