-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLoader.php
More file actions
120 lines (97 loc) · 3.44 KB
/
Loader.php
File metadata and controls
120 lines (97 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Reactorcoder\Symfony2NodesocketBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Reactorcoder\Symfony2NodesocketBundle\Library\php\NodeSocket as NodeSocket;
use Reactorcoder\Symfony2NodesocketBundle\DependencyInjection as DependecyInjection;
use Symfony\Component\DependencyInjection\Container;
class Loader
{
protected $configuration, $nodesocket, $_userSid;
public function __construct($container, $config)
{
if (!is_array($config))
{
trigger_error("No configuration in config.yml. Please check your configuration and add 'reactorcoder_symfony2_nodesocket' config declarations");
}
$this->configuration = $config;
$request = $container->get('request');
$this->nodesocket = new Nodesocket;
$this->checkConfiguration($config, $request);
return $this->nodesocket->init($this->configuration);
}
private function checkConfiguration($config, $request)
{
if (is_null($config['host']))
{
$this->configuration['host'] = $request->getHost();
}
if (is_null($config['port']))
{
$this->configuration['port'] = (int)3001;
}
if (is_null($config['origin']))
{
$this->configuration['origin'] = $this->configuration['host'].':*';
}
else
{
$this->nodesocket->host = $this->configuration['host'];
$this->nodesocket->origin = null;
$this->configuration['origin'] = $this->nodesocket->getOrigin();
}
if (is_null($config['allowedServers']))
{
$this->configuration['allowedServers'] = '127.0.0.1:*';
}
else
{
$this->configuration['allowedServers'] = $this->nodesocket->getOrigin();
}
if (is_null($config['checkClientOrigin']))
{
$this->configuration['checkClientOrigin'] = true;
}
else
{
$this->configuration['checkClientOrigin'] = $this->nodesocket->getOrigin();
}
if (is_null($config['sessionVarName']))
{
$this->configuration['sessionVarName'] = (string)'PHPSESSID';
}
else
{
$this->configuration['sessionVarName'] = (string)$this->nodesocket->sessionVarName;
}
if (is_null($config['sessionVarName']))
{
$this->configuration['pidFile'] = 'socket-transport.pid';
}
else
{
$this->configuration['pidFile'] = $this->nodesocket->pidFile;
}
if (!is_array($config['allowedServers']))
{
$this->configuration['allowedServers'] = array('127.0.0.1');
}
else
{
$this->nodesocket->allowedServerAddresses = $config['allowedServers'];
$this->configuration['allowedServers'] = $this->nodesocket->getAllowedServersAddresses();
}
$this->_userSid = $request->cookies->get($this->configuration['sessionVarName']);
$this->nodesocket->_userSid = $this->_userSid;
}
public function setRequest($request)
{
}
public function getFrameFactory()
{
return $this->nodesocket->getFrameFactory();
}
public function setUser($sid)
{
$this->_userSid = (int)$sid;
}
}