bakaphp /
phalcon-api
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | namespace Gewaer\Providers; |
||
| 4 | |||
| 5 | use function Gewaer\Core\envValue; |
||
| 6 | use Phalcon\Di\ServiceProviderInterface; |
||
| 7 | use Phalcon\DiInterface; |
||
| 8 | use Memcached; |
||
| 9 | use Phalcon\Session\Adapter\Libmemcached; |
||
| 10 | |||
| 11 | class SessionProvider implements ServiceProviderInterface |
||
| 12 | {
|
||
| 13 | /** |
||
| 14 | * @param DiInterface $container |
||
| 15 | */ |
||
| 16 | public function register(DiInterface $container) |
||
| 17 | {
|
||
| 18 | $container->setShared( |
||
| 19 | 'session', |
||
| 20 | function () {
|
||
| 21 | $backOptions = [ |
||
| 22 | 'servers' => [ |
||
| 23 | 0 => [ |
||
| 24 | 'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
|
||
| 25 | 'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
|
||
| 26 | 'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
|
||
| 27 | ], |
||
| 28 | ], |
||
| 29 | 'client' => [ |
||
| 30 | Memcached::OPT_HASH => Memcached::HASH_MD5, |
||
| 31 | Memcached::OPT_PREFIX_KEY => 'bakasession-', |
||
| 32 | ], |
||
| 33 | 'lifetime' => 8600, |
||
| 34 | 'prefix' => $prefix . '-', |
||
| 35 | 'persistent' => false |
||
| 36 | ]; |
||
| 37 | |||
| 38 | $memcache = new Libmemcached($backOptions); |
||
| 39 | |||
| 40 | $memcache->start(); |
||
| 41 | |||
| 42 | return $memcache; |
||
| 43 | } |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |