Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | Rev 301 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 * Global Configuration Override
5
 *
6
 * You can use this file for overriding configuration values from modules, etc.
7
 * You would place values in here that are agnostic to the environment and not
8
 * sensitive to security.
9
 *
10
 * NOTE: In practice, this file will typically be INCLUDED in your source
11
 * control, so do not include passwords or other sensitive information in this
12
 * file.
13
 */
14
use Laminas\Session\Storage\SessionArrayStorage;
15
use Laminas\Session\Validator\RemoteAddr;
16
use Laminas\Session\Validator\HttpUserAgent;
17
use LeadersLinked\Handler\SessionHandler;
18
use Laminas\Session\Storage\SessionStorage;
19
use LeadersLinked\Cache\CacheImpl;
20
use LeadersLinked\Handler\SessionCacheHandler;
21
 
22
 
23
 
24
return [
25
    'session' => [
26
        'config' => [
27
            'class' => 'Laminas\Session\Config\SessionConfig',
28
            'options' => [
29
                'name'              => 'LeadersLinked',
30
                'use_cookies'       => true,
31
                'cookie_lifetime'   => 60*60*24*30,
32
                'gc_maxlifetime'    => 60*60*24,
232 efrain 33
                'cookie_httponly'   => true,
34
                'cookie_secure'     => true
1 efrain 35
            ],
36
        ],
37
        'storage' => SessionArrayStorage::class,
38
        'validators' => [
39
            RemoteAddr::class,
40
            HttpUserAgent::class,
41
        ],
42
    ],
43
    'service_manager' => [
44
 
45
        'factories' => [
46
            //'Laminas\Db\Adapter\Adapter'  => 'Laminas\Db\Adapter\AdapterServiceFactory',
47
 
48
            'leaders-linked-cache' => function ($sm) {
49
                $config = $sm->get('config');
50
 
51
                $cache = new CacheImpl($config);
52
                return $cache;
53
 
54
            },
55
 
56
            'leaders-linked-db' => function ($sm) {
57
                $config = $sm->get('config');
58
 
59
                $sandbox = $config['leaderslinked.runmode.sandbox'];
60
                if($sandbox) {
61
                    $host       = $config['leaderslinked.database.sandbox_host'];
62
                    $port       = $config['leaderslinked.database.sandbox_port'];
63
                    $dbname     = $config['leaderslinked.database.sandbox_dbname'];
64
                    $user       = $config['leaderslinked.database.sandbox_user'];
65
                    $password   = $config['leaderslinked.database.sandbox_password'];
66
                } else {
67
                    $host       = $config['leaderslinked.database.production_host'];
68
                    $port       = $config['leaderslinked.database.production_port'];
69
                    $dbname     = $config['leaderslinked.database.production_dbname'];
70
                    $user       = $config['leaderslinked.database.production_user'];
71
                    $password   = $config['leaderslinked.database.production_password'];
72
                }
73
 
74
 
75
                $adapter = new \Laminas\Db\Adapter\Adapter([
76
                    'driver'            => 'Pdo',
77
                    'dsn'               => 'mysql:dbname=' . $dbname . ';host=' . $host . ';port=' . $port,
78
                    'username'                  => $user,
79
                    'password'                  => $password,
80
                    'driver_options'    => [
81
                        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
82
                    ],
83
                ]);
84
 
85
            return $adapter;
86
 
87
            },
88
            'leaders-linked-log' => function($sm) {
89
                $formatter = new \Laminas\Log\Formatter\Base();
90
                $formatter->setDateTimeFormat('Y-m-d H:i:s');
91
 
92
                $mapping = array(
93
                    'timestamp'     => 'added_on',
94
                    'priority'      => 'priority_level',
95
                    'priorityName'  => 'priority_name',
96
                    'message'       => 'message',
97
                    'extra'       => [
98
                        'user_id'    => 'user_id',
99
                        'ip' => 'ip'
100
                    ]
101
                );
102
 
103
 
104
                $adapter = $sm->get('leaders-linked-db');
105
 
106
                $writer = new \Laminas\Log\Writer\Db($adapter, 'tbl_logs', $mapping);
107
                $writer->setFormatter($formatter);
108
 
109
                $logger = new \Laminas\Log\Logger();
110
                $logger->addWriter($writer);
111
 
112
 
113
 
114
                return $logger;
115
            },
116
 
117
            'leaders-linked-session' => function ($sm) {
118
                $config = $sm->get('config');
119
                if (isset($config['session'])) {
120
 
121
                    $session = $config['session'];
122
 
123
 
124
                    $sessionConfig = null;
125
                    if (isset($session['config'])) {
126
                        $class = isset($session['config']['class'])  ? $session['config']['class'] : 'Laminas\Session\Config\SessionConfig';
127
                        $options = isset($session['config']['options']) ? $session['config']['options'] : [];
128
 
129
 
130
                        $options['remember_me_seconds'] = 7200;  // 60 * 60 * 2seconds
131
                        $options['use_cookies'] = true;
132
                        $sessionConfig = new $class();
133
                        $sessionConfig->setOptions($options);
134
                    }
135
 
136
                    $sessionStorage = new SessionStorage();
137
                    if (isset($session['storage'])) {
138
                        $class = $session['storage'];
139
                        $sessionStorage = new $class();
140
                    }
141
 
142
 
143
 
144
 
145
 
146
                    $sessionManager = new \Laminas\Session\SessionManager();
147
                    $sessionManager->setConfig($sessionConfig);
148
                    $sessionManager->setStorage($sessionStorage);
149
 
150
                    if(!empty($config['leaderslinked.runmode.session_in_cache'])) {
151
                        $cache    = $sm->get('leaders-linked-cache');
152
                        $saveHandler= new SessionCacheHandler($cache);
153
                        $sessionManager->setSaveHandler($saveHandler);
154
                    }
155
 
156
 
157
                } else {
158
                    $sessionManager = new \Laminas\Session\SessionManager();
159
                }
160
 
161
                \Laminas\Session\Container::setDefaultManager($sessionManager);
162
                return $sessionManager;
163
            },
164
        ],
165
        'abstract_factories' => [
166
 
167
        ]
168
    ],
169
 
170
];