Skip to content

Commit 12bd5e2

Browse files
author
johan
committed
init
0 parents  commit 12bd5e2

9 files changed

+220
-0
lines changed

LICENSE.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2013, Milq Media <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the Zf2LdapAuth nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Module.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the MQRedisSessionStorage Module (https://github.com/milqmedia/MQRedisSessionStorage.git)
5+
*
6+
* Copyright (c) 2013 Milq Media (https://github.com/milqmedia/MQRedisSessionStorage.git)
7+
*
8+
* For the full copyright and license information, please view
9+
* the file LICENSE.txt that was distributed with this source code.
10+
*/
11+
12+
namespace MQRedisSessionStorage;
13+
14+
class Module
15+
{
16+
17+
public function onBootstrap(\Zend\Mvc\MvcEvent $e)
18+
{
19+
$storage = $e->getApplication()->getServiceManager()->get('MQRedisSessionStorage\Storage\RedisStorage');
20+
$storage->setSessionStorage();
21+
}
22+
23+
public function getConfig()
24+
{
25+
return include __DIR__ . '/config/module.config.php';
26+
}
27+
28+
public function getAutoloaderConfig()
29+
{
30+
return array(
31+
'Zend\Loader\ClassMapAutoloader' => array(
32+
__DIR__ . '/autoload_classmap.php',
33+
),
34+
);
35+
}
36+
}

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MQRedisSessionStorage
2+
================
3+
4+
Zend Framework Module for storing sessions in Redis.
5+
6+
## Setup
7+
8+
1. Run `php composer.phar require milqmedia/mq-redis-session:1.*`
9+
2. Add `MQRedisSessionStorage` to the enabled modules list
10+
3. Copy `vendor/milqmedia/mq-redis-session/redissession.global.php.dist` to `config/autoload/redissession.global.php`
11+
4. Configure the session options in `config/autoload/redissession.global.php`

autoload_classmap.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Generated by ZF2's ./bin/classmap_generator.php
3+
return array(
4+
'MQRedisSessionStorage\Module' => __DIR__ . '/Module.php',
5+
'MQRedisSessionStorage\Factory\RedisStorageFactory' => __DIR__ . '/src/Factory/RedisStorageFactory.php',
6+
'MQRedisSessionStorage\Storage\RedisStorage' => __DIR__ . '/src/Storage/RedisStorage.php',
7+
);

composer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "milqmedia/mq-redis-session",
3+
"description": "Zend Framework 2 redis session storage",
4+
"type": "library",
5+
"keywords": ["redis","session","storage","zf2"],
6+
"homepage": "https://github.com/milqmedia/MQRedisSessionStorage",
7+
"license": "New BSD License",
8+
"authors": [
9+
{
10+
"name": "Johan Kuijt",
11+
"email": "[email protected]",
12+
"homepage": "http://www.milq.nl",
13+
"role": "Hasselhoffer"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.3.3",
18+
"zendframework/zendframework": "2.*"
19+
},
20+
"autoload": {
21+
"psr-0": {
22+
"MQRedisSessionStorage": "src/"
23+
},
24+
"classmap": [
25+
"Module.php"
26+
]
27+
}
28+
}

config/module.config.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* This file is part of the MQRedisSessionStorage Module (https://github.com/milqmedia/MQRedisSessionStorage.git)
4+
*
5+
* Copyright (c) 2013 Milq Media (https://github.com/milqmedia/MQRedisSessionStorage.git)
6+
*
7+
* For the full copyright and license information, please view
8+
* the file LICENSE.txt that was distributed with this source code.
9+
*/
10+
return array(
11+
'service_manager' => array(
12+
'factories' => array(
13+
'MQRedisSessionStorage\Storage\RedisStorage' => 'MQRedisSessionStorage\Factory\RedisStorageFactory',
14+
)
15+
),
16+
17+
);

config/redissession.global.php.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) 2013 Milq Media (https://github.com/milqmedia
5+
*
6+
* For the full copyright and license information, please view
7+
* the file LICENSE.txt that was distributed with this source code.
8+
*
9+
* @author Milq Media <[email protected]>
10+
*
11+
*
12+
*/
13+
return array(
14+
'mq-redis-session' => array (
15+
'adapter' => array (
16+
'name' => 'redis',
17+
'options' => array (
18+
'server' => [
19+
'host' => '127.0.0.1',
20+
'port' => 6379,
21+
]
22+
),
23+
),
24+
)
25+
);

src/Factory/RedisStorageFactory.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) 2013 Milq Media (https://github.com/milqmedia)
5+
*
6+
* For the full copyright and license information, please view
7+
* the file LICENSE.txt that was distributed with this source code.
8+
*
9+
* @author Milq Media <[email protected]>
10+
*
11+
*/
12+
13+
namespace MQRedisSessionStorage\Factory;
14+
15+
use Zend\ServiceManager\FactoryInterface;
16+
use Zend\ServiceManager\ServiceLocatorInterface;
17+
use MQRedisSessionStorage\Storage\RedisStorage;
18+
19+
class RedisStorageFactory implements FactoryInterface
20+
{
21+
public function createService(ServiceLocatorInterface $serviceLocator)
22+
{
23+
$conf = $serviceLocator->get('Config');
24+
$config = null;
25+
if (isset($conf['mq-redis-session'])) {
26+
$config = $conf['mq-redis-session'];
27+
}
28+
29+
return new RedisStorage($config);
30+
}
31+
}

src/Storage/RedisStorage.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) 2013 Milq Media (https://github.com/milqmedia)
5+
*
6+
* For the full copyright and license information, please view
7+
* the file LICENSE.txt that was distributed with this source code.
8+
*
9+
* @author Milq Media <[email protected]>
10+
*
11+
*/
12+
13+
namespace MQRedisSessionStorage\Storage;
14+
15+
use Zend\Session\Config\SessionConfig;
16+
use Zend\Session\SessionManager;
17+
use Zend\Session\Container;
18+
use Zend\Session\SaveHandler\Cache;
19+
use Zend\Cache\StorageFactory;
20+
21+
class RedisStorage
22+
{
23+
protected $redisConfig;
24+
25+
public function __construct($redisConfig)
26+
{
27+
$this->redisConfig = $redisConfig;
28+
}
29+
30+
public function setSessionStorage()
31+
{
32+
$cache = StorageFactory::factory($this->redisConfig);
33+
34+
$saveHandler = new Cache($cache);
35+
36+
$manager = new SessionManager();
37+
$manager->setSaveHandler($saveHandler);
38+
39+
$manager->start();
40+
}
41+
}

0 commit comments

Comments
 (0)