Ejemplo n.º 1
0
 /** @override */
 public static function init($em, $reader)
 {
     // http://www.w3schools.com/tags/ref_language_codes.asp
     static::$listener = $listener = new \Gedmo\Translatable\TranslatableListener();
     // Current translation locale should be set from session or hook later into the listener
     // Most importantly, before the entity manager is flushed
     $lang = \Config::get('language', 'en');
     $default = \Config::get('language_fallback', $lang);
     if (is_array($default)) {
         $default = $default[0];
     }
     $listener->setTranslatableLocale($lang);
     $listener->setDefaultLocale($default);
     $listener->setAnnotationReader($reader);
     $listener->setTranslationFallback(true);
     $em->getEventManager()->addEventSubscriber($listener);
 }
Ejemplo n.º 2
0
 public function onBootstrap(Event $e)
 {
     $application = $e->getApplication();
     $eventManager = $application->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'setApplicationSection'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'setLayout'), 31);
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'setLayout'), 31);
     $app = $e->getParam('application');
     $sm = $app->getServiceManager();
     $evm = $sm->get('doctrine.eventmanager.orm_default');
     $config = $sm->get('Config');
     $tablePrefix = isset($config['doctrine']['connection']['orm_default']['params']['table_prefix']) ? $config['doctrine']['connection']['orm_default']['params']['table_prefix'] : FALSE;
     if ($tablePrefix) {
         $tablePrefix = new \Dxapp\Doctrine\Extension\TablePrefix($tablePrefix);
         $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
     }
     $cache = $sm->get('doctrine.cache.memcache');
     $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
     $cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
     $em = $sm->get('doctrine.entitymanager.orm_default');
     \Doctrine\DBAL\Types\Type::overrideType('datetime', 'Dxapp\\Doctrine\\Types\\UTCDatetimeType');
     //		$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('Datetime', 'datetime');
     $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
     $sluggableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($sluggableListener);
     $treeListener = new \Gedmo\Tree\TreeListener();
     $treeListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($treeListener);
     $timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
     $timestampableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($timestampableListener);
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     $translatableListener->setAnnotationReader($cachedAnnotationReader);
     $translatableListener->setTranslatableLocale('en');
     $translatableListener->setDefaultLocale('en');
     $evm->addEventSubscriber($translatableListener);
 }
Ejemplo n.º 3
0
// loggable, not used in example
//$loggableListener = new Gedmo\Loggable\LoggableListener;
//$loggableListener->setAnnotationReader($cachedAnnotationReader);
//$loggableListener->setUsername('admin');
//$evm->addEventSubscriber($loggableListener);
// timestampable
$timestampableListener = new Gedmo\Timestampable\TimestampableListener();
$timestampableListener->setAnnotationReader($cachedAnnotationReader);
$evm->addEventSubscriber($timestampableListener);
// blameable
$blameableListener = new \Gedmo\Blameable\BlameableListener();
$blameableListener->setAnnotationReader($cachedAnnotationReader);
$blameableListener->setUserValue('MyUsername');
// determine from your environment
$evm->addEventSubscriber($blameableListener);
// translatable
$translatableListener = new Gedmo\Translatable\TranslatableListener();
// current translation locale should be set from session or hook later into the listener
// most important, before entity manager is flushed
$translatableListener->setTranslatableLocale('en');
$translatableListener->setDefaultLocale('en');
$translatableListener->setAnnotationReader($cachedAnnotationReader);
$evm->addEventSubscriber($translatableListener);
// sortable, not used in example
//$sortableListener = new Gedmo\Sortable\SortableListener;
//$sortableListener->setAnnotationReader($cachedAnnotationReader);
//$evm->addEventSubscriber($sortableListener);
// mysql set names UTF-8 if required
$evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
// Finally, create entity manager
return Doctrine\ORM\EntityManager::create($connection, $config, $evm);
Ejemplo n.º 4
0
 public function onBootstrap(EventInterface $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $config = $e->getApplication()->getServiceManager()->get('config');
     $translator = $serviceManager->get('translator');
     // Gestion de la locale
     if (PHP_SAPI !== 'cli') {
         //translator
         // Gestion locale pour le back
         if ($serviceManager->get('router')->match($serviceManager->get('request')) && strpos($serviceManager->get('router')->match($serviceManager->get('request'))->getMatchedRouteName(), 'admin') !== false) {
             if ($e->getRequest()->getCookie() && $e->getRequest()->getCookie()->offsetExists('pg_locale_back')) {
                 $locale = $e->getRequest()->getCookie()->offsetGet('pg_locale_back');
             }
         }
         if (empty($locale)) {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
             } else {
                 $locale = 'fr_FR';
             }
         }
         $translator->setLocale($locale);
         // plugins
         $translate = $serviceManager->get('viewhelpermanager')->get('translate');
         $translate->getTranslator()->setLocale($locale);
         $options = $serviceManager->get('playgroundcore_module_options');
         $options->setLocale($locale);
     }
     // positionnement de la langue pour les traductions de date avec strftime
     setlocale(LC_TIME, "fr_FR", 'fr_FR.utf8', 'fra');
     AbstractValidator::setDefaultTranslator($translator, 'playgroundcore');
     /*
      * Entity translation based on Doctrine Gedmo library
      */
     $doctrine = $serviceManager->get('doctrine.entitymanager.orm_default');
     $evm = $doctrine->getEventManager();
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     // TODO : Set the Default locale to be taken from config
     $translatableListener->setDefaultLocale('fr_FR');
     // If no translation is found, fallback to entity data
     $translatableListener->setTranslationFallback(true);
     // set Locale
     if (!empty($locale)) {
         $translatableListener->setTranslatableLocale($locale);
     }
     $evm->addEventSubscriber($translatableListener);
     /**
      * Adding a Filter to slugify a string (make it URL compliiant)
      */
     $filterChain = new \Zend\Filter\FilterChain();
     $filterChain->getPluginManager()->setInvokableClass('slugify', 'PlaygroundCore\\Filter\\Slugify');
     $filterChain->attach(new Filter\Slugify());
     // Start the session container
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     /**
      * Optional: If you later want to use namespaces, you can already store the
      * Manager in the shared (static) Container (=namespace) field
      */
     \Zend\Session\Container::setDefaultManager($sessionManager);
     // Google Analytics : When the render event is triggered, we invoke the view helper to
     // render the javascript code.
     $e->getApplication()->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function (\Zend\Mvc\MvcEvent $e) use($serviceManager) {
         $view = $serviceManager->get('ViewHelperManager');
         $plugin = $view->get('googleAnalytics');
         $plugin();
         $pluginOG = $view->get('facebookOpengraph');
         $pluginOG();
     });
     if (PHP_SAPI !== 'cli') {
         $session = new Container('facebook');
         $fb = $e->getRequest()->getPost()->get('signed_request');
         if ($fb) {
             list($encoded_sig, $payload) = explode('.', $fb, 2);
             $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
             $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
             $session->offsetSet('signed_request', $data);
             // This fix exists only for safari on Windows : we need to redirect the user to the page outside of iframe
             // for the cookie to be accepted. Core just adds a 'redir_fb_page_id' var to alert controllers
             // that they need to send the user back to FB...
             if (!count($_COOKIE) > 0 && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')) {
                 echo '<script type="text/javascript">' . 'window.top.location.href = window.location.href+"?redir_fb_page_id=' . $data["page"]["id"] . '";' . '</script>';
             }
             // This fix exists only for IE6+, when this app is embedded into an iFrame : The P3P policy has to be set.
             $response = $e->getResponse();
             if ($response instanceof \Zend\Http\Response && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strpos($_SERVER['HTTP_USER_AGENT'], 'rv:11.'))) {
                 $response->getHeaders()->addHeaderLine('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Gets the 'stof_doctrine_extensions.listener.translatable' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * This service is private.
  * If you want to be able to request this service from the container directly,
  * make it public, otherwise you might end up with broken code.
  *
  * @return \Gedmo\Translatable\TranslatableListener A Gedmo\Translatable\TranslatableListener instance
  */
 protected function getStofDoctrineExtensions_Listener_TranslatableService()
 {
     $this->services['stof_doctrine_extensions.listener.translatable'] = $instance = new \Gedmo\Translatable\TranslatableListener();
     $instance->setAnnotationReader($this->get('annotation_reader'));
     $instance->setDefaultLocale('en');
     $instance->setTranslatableLocale('en');
     $instance->setTranslationFallback(false);
     $instance->setPersistDefaultLocaleTranslation(false);
     $instance->setSkipOnLoad(false);
     return $instance;
 }
Ejemplo n.º 6
0
 /**
  * @return $this
  * @throws \Exception
  */
 public function setUpTranslateable()
 {
     $defaultLocale = $this->locale->getDefaultLocale();
     if ($defaultLocale === null) {
         throw new \Exception('Default locale not found! Fraym is not correctly installed, please reinstall Fraym.');
     }
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     $translatableListener->setDefaultLocale($defaultLocale->locale);
     $translatableListener->setAnnotationReader($this->cachedAnnotationReader);
     $translatableListener->setTranslationFallback(true);
     $translatableListener->setPersistDefaultLocaleTranslation(true);
     $this->eventManager->addEventSubscriber($translatableListener);
     return $this;
 }
Ejemplo n.º 7
0
 protected function registerI18n()
 {
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     $translatableListener->setDefaultLocale($this->config['general.default_language']);
     $translatableListener->setAnnotationReader($this->cachedAnnotationReader);
     $this->eventManager->addEventSubscriber($translatableListener);
 }