Esempio n. 1
0
 /**
  * Construct the translator.
  *
  * @param ServiceManager $sm Service manager.
  *
  * @return \Zend\I18n\Translator\TranslatorInterface
  */
 public static function getTranslator(ServiceManager $sm)
 {
     $factory = new \Zend\Mvc\Service\TranslatorServiceFactory();
     $translator = $factory->createService($sm);
     // Set up the ExtendedIni plugin:
     $config = $sm->get('VuFind\\Config')->get('config');
     $pathStack = [APPLICATION_PATH . '/languages', LOCAL_OVERRIDE_DIR . '/languages'];
     $fallbackLocales = $config->Site->language == 'en' ? 'en' : [$config->Site->language, 'en'];
     try {
         $pm = $translator->getPluginManager();
     } catch (\Zend\Mvc\Exception\BadMethodCallException $ex) {
         // If getPluginManager is missing, this means that the user has
         // disabled translation in module.config.php or PHP's intl extension
         // is missing. We can do no further configuration of the object.
         return $translator;
     }
     $pm->setService('extendedini', new \VuFind\I18n\Translator\Loader\ExtendedIni($pathStack, $fallbackLocales));
     // Set up language caching for better performance:
     try {
         $translator->setCache($sm->get('VuFind\\CacheManager')->getCache('language'));
     } catch (\Exception $e) {
         // Don't let a cache failure kill the whole application, but make
         // note of it:
         $logger = $sm->get('VuFind\\Logger');
         $logger->debug('Problem loading cache: ' . get_class($e) . ' exception: ' . $e->getMessage());
     }
     return $translator;
 }
Esempio n. 2
0
 /**
  * Get a service manager.
  *
  * @return \Zend\ServiceManager\ServiceManager
  */
 public function getServiceManager()
 {
     if (!$this->serviceManager) {
         $this->serviceManager = new \Zend\ServiceManager\ServiceManager();
         $optionsFactory = new \VuFind\Search\Options\PluginManager(new \Zend\ServiceManager\Config(['abstract_factories' => ['VuFind\\Search\\Options\\PluginFactory']]));
         $optionsFactory->setServiceLocator($this->serviceManager);
         $this->serviceManager->setService('VuFind\\SearchOptionsPluginManager', $optionsFactory);
         $paramsFactory = new \VuFind\Search\Params\PluginManager(new \Zend\ServiceManager\Config(['abstract_factories' => ['VuFind\\Search\\Params\\PluginFactory']]));
         $paramsFactory->setServiceLocator($this->serviceManager);
         $this->serviceManager->setService('VuFind\\SearchParamsPluginManager', $paramsFactory);
         $resultsFactory = new \VuFind\Search\Results\PluginManager(new \Zend\ServiceManager\Config(['abstract_factories' => ['VuFind\\Search\\Results\\PluginFactory']]));
         $resultsFactory->setServiceLocator($this->serviceManager);
         $this->serviceManager->setService('VuFind\\SearchResultsPluginManager', $resultsFactory);
         $recordDriverFactory = new \VuFind\RecordDriver\PluginManager(new \Zend\ServiceManager\Config(['abstract_factories' => ['VuFind\\RecordDriver\\PluginFactory']]));
         $this->serviceManager->setService('VuFind\\RecordDriverPluginManager', $recordDriverFactory);
         $this->serviceManager->setService('VuFind\\SearchSpecsReader', new \VuFind\Config\SearchSpecsReader());
         $this->serviceManager->setService('VuFind\\Logger', $this->getMock('VuFind\\Log\\Logger'));
         $this->serviceManager->setService('VuFind\\Http', new \VuFindHttp\HttpService());
         $this->setupSearchService();
         $cfg = new \Zend\ServiceManager\Config(['abstract_factories' => ['VuFind\\Config\\PluginFactory']]);
         $this->serviceManager->setService('VuFind\\Config', new \VuFind\Config\PluginManager($cfg));
         $this->serviceManager->setService('SharedEventManager', new \Zend\EventManager\SharedEventManager());
         $this->serviceManager->setService('VuFind\\RecordLoader', new \VuFind\Record\Loader($this->serviceManager->get('VuFind\\Search'), $this->serviceManager->get('VuFind\\RecordDriverPluginManager')));
         $this->serviceManager->setService('Config', []);
         $factory = new \Zend\Mvc\Service\TranslatorServiceFactory();
         $this->serviceManager->setService('VuFind\\Translator', $factory->createService($this->serviceManager));
     }
     return $this->serviceManager;
 }