Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use ZendSessionStorageSessionArrayStorage;
- use ZendSessionValidatorRemoteAddr;
- use ZendSessionValidatorHttpUserAgent;
- return [
- 'config' => [
- 'driver' => 'mongodb',
- 'host' => '127.0.0.1',
- 'port' => 27017,
- 'username' => 'test',
- 'password' => 'test',
- 'dbname' => 'test',
- 'connection_string'=> sprintf('mongodb://%s:%d/%s','127.0.0.1','27017','test')
- ],
- // Session configuration.
- 'session_config' => [
- // Session cookie will expire in 1 hour.
- 'cookie_lifetime' => 60*60*1,
- // Session data will be stored on server maximum for 30 days.
- 'gc_maxlifetime' => 60*60*24*30,
- ],
- // Session manager configuration.
- 'session_manager' => [
- // Session validators (used for security).
- 'validators' => [
- RemoteAddr::class,
- HttpUserAgent::class,
- ]
- ],
- // Session storage configuration.
- 'session_storage' => [
- 'type' => SessionArrayStorage::class
- ],
- <?php
- namespace ApplicationController;
- use InteropContainerContainerInterface;
- use ZendServiceManagerFactoryFactoryInterface;
- use ApplicationServiceAuthManager;
- /**
- * This is the factory for UserController. Its purpose is to instantiate the
- * controller.
- */
- class UserControllerFactory implements FactoryInterface{
- public function __invoke(ContainerInterface $container, $requestedName, array $options = null){
- $config = $container->get('config');
- $db_config = $config['config'];
- $authManager = $container->get(AuthManager::class);
- $authService = $container->get(ZendAuthenticationAuthenticationService::class);
- return new UserController($db_config, $authManager, $authService);
- }
- }
- <?php
- namespace ApplicationController;
- use ZendMvcControllerAbstractActionController;
- use ZendViewModelJsonModel;
- use ZendViewModelViewModel;
- use ZendCryptPasswordBcrypt;
- class UserController extends AbstractActionController{
- private $db;
- private $authManager;
- private $authService;
- /**
- * Constructor.
- */
- public function __construct($config, $authManager, $authService){
- $this->connect($config);
- $this->authManager = $authManager;
- $this->authService = $authService;
- }
- /**
- * Connection.
- */
- private function connect($config){
- try{
- if ( !class_exists('Mongo')){
- echo ("The MongoDB PECL extension has not been installed or enabled");
- return false;
- }
- $connection= new MongoClient($config['connection_string'],
- array('username'=>$config['username'],'password'=>$config['password']));
- return $this->db = $connection->selectDB($config['dbname']);
- }catch(Exception $e) {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment