Advertisement
gustavosg85

Module.php scape

Aug 4th, 2015
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Zend Framework (http://framework.zend.com/)
  4.  *
  5.  * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
  6.  * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7.  * @license   http://framework.zend.com/license/new-bsd New BSD License
  8.  */
  9.  
  10. namespace Application;
  11.  
  12. use Zend\Mvc\ModuleRouteListener;
  13. use Zend\Mvc\MvcEvent;
  14. use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
  15. use Zend\ModuleManager\Feature\ConfigProviderInterface;
  16. use Zend\ModuleManager\Feature\ServiceProviderInterface;
  17. use Zend\Validator\AbstractValidator;
  18.  
  19. class Module implements AutoloaderProviderInterface, ConfigProviderInterface , ServiceProviderInterface
  20. {
  21.     public function onBootstrap(MvcEvent $e)
  22.     {
  23.         // Configuração de Internacionalização
  24.  
  25.         $app = $e->getApplication();
  26.  
  27.         $eventManager        = $app->getEventManager();
  28.  
  29.         $eventManager->attach('dispatch',
  30.  
  31.             function($e){
  32.                 $routeMatch = $e->getRouteMatch();
  33.  
  34.                 if ($routeMatch->getParam('lang') != '')
  35.                 {
  36.                     $this->serviceManager = $e->getApplication()->getServiceManager();
  37.                     $translator = $this->serviceManager->get('translator');
  38.                     $translator->setLocale($routeMatch->getParam('lang'));
  39.  
  40.                    
  41.                     // $translator->addTranslationFile('phpArray', __DIR__.'/../../vendor/zendframework/zend-i18n-resources/languages/en/Zend_Validate.php', 'default', 'en_US');
  42.                     $translator->addTranslationFile('phpArray', __DIR__.'/../../vendor/zendframework/zend-i18n-resources/languages/pt_BR/Zend_Validate.php', 'default', 'pt_BR');
  43.  
  44.                     AbstractValidator::setDefaultTranslator($translator);
  45.                 }
  46.             }, 100
  47.             );
  48.        
  49.         $moduleRouteListener = new ModuleRouteListener();
  50.         $moduleRouteListener->attach($eventManager);
  51.     }
  52.  
  53.     public function getConfig()
  54.     {
  55.         return include __DIR__ . '/config/module.config.php';
  56.     }
  57.  
  58.     public function getServiceConfig()
  59.     {
  60.         // return array(
  61.         //     'controllers' => array(
  62.         //         'factories' => array(
  63.         //             'Application\Controllers\Correspondencias' => function($sm)
  64.         //             {
  65.         //                 var_dump($sm);
  66.         //                 $translator = $sm->getServiceLocator()->get('translator');
  67.         //                 $controller = new Application\Controller\CorrespondenciasController($translator);
  68.         //             }
  69.         //             )
  70.         //         )
  71.         //     );
  72.     }
  73.  
  74.     public function getAutoloaderConfig()
  75.     {
  76.         return array(
  77.             'Zend\Loader\StandardAutoloader' => array(
  78.                 'namespaces' => array(
  79.                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
  80.                     ),
  81.                 ),
  82.             );
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement