Guest User

Untitled

a guest
Nov 20th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. use ZendSessionStorageSessionArrayStorage;
  2. use ZendSessionValidatorRemoteAddr;
  3. use ZendSessionValidatorHttpUserAgent;
  4.  
  5. return [
  6. 'config' => [
  7. 'driver' => 'mongodb',
  8. 'host' => '127.0.0.1',
  9. 'port' => 27017,
  10. 'username' => 'test',
  11. 'password' => 'test',
  12. 'dbname' => 'test',
  13. 'connection_string'=> sprintf('mongodb://%s:%d/%s','127.0.0.1','27017','test')
  14. ],
  15.  
  16. // Session configuration.
  17. 'session_config' => [
  18. // Session cookie will expire in 1 hour.
  19. 'cookie_lifetime' => 60*60*1,
  20. // Session data will be stored on server maximum for 30 days.
  21. 'gc_maxlifetime' => 60*60*24*30,
  22. ],
  23. // Session manager configuration.
  24. 'session_manager' => [
  25. // Session validators (used for security).
  26. 'validators' => [
  27. RemoteAddr::class,
  28. HttpUserAgent::class,
  29. ]
  30. ],
  31. // Session storage configuration.
  32. 'session_storage' => [
  33. 'type' => SessionArrayStorage::class
  34. ],
  35.  
  36. <?php
  37. namespace ApplicationController;
  38. use InteropContainerContainerInterface;
  39. use ZendServiceManagerFactoryFactoryInterface;
  40. use ApplicationServiceAuthManager;
  41. /**
  42. * This is the factory for UserController. Its purpose is to instantiate the
  43. * controller.
  44. */
  45. class UserControllerFactory implements FactoryInterface{
  46. public function __invoke(ContainerInterface $container, $requestedName, array $options = null){
  47. $config = $container->get('config');
  48. $db_config = $config['config'];
  49. $authManager = $container->get(AuthManager::class);
  50. $authService = $container->get(ZendAuthenticationAuthenticationService::class);
  51. return new UserController($db_config, $authManager, $authService);
  52. }
  53. }
  54.  
  55. <?php
  56. namespace ApplicationController;
  57. use ZendMvcControllerAbstractActionController;
  58. use ZendViewModelJsonModel;
  59. use ZendViewModelViewModel;
  60. use ZendCryptPasswordBcrypt;
  61.  
  62. class UserController extends AbstractActionController{
  63. private $db;
  64. private $authManager;
  65. private $authService;
  66. /**
  67. * Constructor.
  68. */
  69. public function __construct($config, $authManager, $authService){
  70. $this->connect($config);
  71. $this->authManager = $authManager;
  72. $this->authService = $authService;
  73. }
  74. /**
  75. * Connection.
  76. */
  77. private function connect($config){
  78. try{
  79. if ( !class_exists('Mongo')){
  80. echo ("The MongoDB PECL extension has not been installed or enabled");
  81. return false;
  82. }
  83. $connection= new MongoClient($config['connection_string'],
  84. array('username'=>$config['username'],'password'=>$config['password']));
  85. return $this->db = $connection->selectDB($config['dbname']);
  86. }catch(Exception $e) {
  87. return false;
  88. }
  89. }
  90. }
Add Comment
Please, Sign In to add comment