public function testMessageIsTranslated() { $translator = $this->getMockBuilder('\\Symfony\\Component\\Translation\\Translator')->disableOriginalConstructor()->getMock(); $translator->expects($this->at(0))->method('addResource')->with('xliff', vfsStream::url('root/Core/Resources/translations/dictionary.xliff')); $dirs = array('Core' => array('Resources' => array('translations' => array('dictionary.xliff' => 'some translations'))), 'Blocks' => array('Resources' => array('translations' => array('dictionary.xliff' => 'some translations')))); $root = vfsStream::setup('root', null, $dirs); $folders = array(vfsStream::url('root/Core/Resources/translations'), vfsStream::url('root/Blocks/Resources/translations')); $loader = new TranslationLoader(); $loader->registerResources($translator, $folders); }
private function registerProviders() { AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', $this->app["red_kite_cms.root_dir"] . '/vendor/jms/serializer/src'); $app = $this->app; $this->app['security.firewalls'] = array('backend' => array('pattern' => '^/backend', 'form' => array('login_path' => '/login', 'check_path' => '/backend/login_check'), 'logout' => array('logout_path' => '/backend/logout', 'target_url' => '/login'), 'users' => $this->app->share(function () use($app) { return new UserProvider($app["red_kite_cms.configuration_handler"]); }))); // TODO setup roles dinamically $app['security.access_rules'] = array(array('^.*$', 'ROLE_USER')); $this->app->register(new UrlGeneratorServiceProvider()); $this->app->register(new SecurityServiceProvider()); $this->app->register(new SessionServiceProvider()); $this->app->boot(); $this->app->register(new TranslationServiceProvider(), array('locale_fallbacks' => array('en'))); $this->app->register(new FormServiceProvider()); $this->registerTwig(); $frameworkAbsoluteDir = $this->frameworkAbsoluteDir; $this->app['translator'] = $this->app->share($this->app->extend('translator', function ($translator, $app) use($frameworkAbsoluteDir) { $resources = array($app["red_kite_cms.root_dir"] . '/' . $frameworkAbsoluteDir . '/plugins/RedKiteCms/Core/RedKiteCms/Resources/translations', $app["red_kite_cms.root_dir"] . '/' . $frameworkAbsoluteDir . '/plugins/RedKiteCms/Block/*/Resources/translations'); // This is a workaround required because Symfony2 Finder throws an exception when a folder does not exist, so the // path for custom bundles cannot be added arbitrarily. // This code looks for at least once "translations" folder for custom plugins and when it finds one, it adds the // path to find translations for custom plugins foreach ($app["red_kite_cms.plugin_manager"]->getBlockPlugins() as $plugin) { if ($plugin->isCore()) { continue; } if ($plugin->isTranslated()) { $resources[] = $app["red_kite_cms.root_dir"] . '/app/plugins/RedKiteCms/Block/*/Resources/translations'; break; } } $translationLoader = new TranslationLoader(); $translationLoader->registerResources($translator, $resources); $translator->addLoader('xliff', $translationLoader); return $translator; })); $logFileName = $this->siteName; if ($this->app["debug"]) { $logFileName .= '_dev'; } $logPath = sprintf('%s/%s.log', $this->app["red_kite_cms.configuration_handler"]->logDir(), $logFileName); $level = $this->app["debug"] ? Logger::DEBUG : Logger::CRITICAL; $app->register(new MonologServiceProvider(), array('monolog.name' => 'RedKiteCms', 'monolog.logfile' => $logPath, 'monolog.level' => $level)); $app['router'] = Routing::create($this->app["red_kite_cms.configuration_handler"], $this->app["debug"])->getRouter(); $generator = new ChainUrlGenerator(array($this->app['url_generator'], $this->app['router'])); $generator->setContext($this->app['request_context']); $this->app['url_generator'] = $generator; }