Proyectos de Subversion LeadersLinked - Services

Rev

Rev 122 | Rev 154 | 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
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Plugin;
6
 
7
use Laminas\Mvc\Controller\Plugin\AbstractPlugin;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Authentication\AuthenticationService;
10
use LeadersLinked\Model\Device;
11
use LeadersLinked\Mapper\DeviceMapper;
12
use LeadersLinked\Model\UserType;
13
use LeadersLinked\Mapper\NetworkMapper;
14
 
15
 
16
class CurrentNetworkPlugin extends AbstractPlugin
17
{
18
 
19
    /**
20
     *
21
     * @var boolean
22
     */
23
    protected $hasNetwork;
24
 
25
 
26
 
27
    /**
28
     *
29
     * @return \LeadersLinked\Model\Network
30
     */
31
    protected $network;
32
 
33
 
34
    /**
35
     *
36
     * @var string
37
     */
38
    protected $hostname;
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     */
44
    public function __construct($adapter)
45
    {
46
 
47
        $this->hasNetwork = false;
48
 
18 efrain 49
        $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
20 efrain 50
 
18 efrain 51
        if(empty($hostname)) {
52
            $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
21 efrain 53
 
18 efrain 54
        }
9 efrain 55
 
18 efrain 56
        $hostname = trim(str_replace(['https://', 'http://'], '', $hostname));
43 efrain 57
 
25 efrain 58
 
18 efrain 59
        $parts = explode('/', $hostname);
60
        $hostname = $parts > 1 ? $parts[0] : $hostname;
17 efrain 61
 
153 efrain 62
       // $hostname = 'dev-spa.leaderslinked.com';
122 efrain 63
 
71 efrain 64
        //$hostname = 'dev.leaderslinked.com';
119 efrain 65
        //$hostname = 'leaderslinked.example.com';
48 efrain 66
 
46 efrain 67
       // error_log('hostname :  '  . $hostname .  ' session ID : ' . session_id() . ' request URI : ' . $_SERVER['REQUEST_URI']);
20 efrain 68
 
1 efrain 69
        $networkMapper = NetworkMapper::getInstance($adapter);
70
        $this->network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
71
 
72
        if($this->network) {
73
 
74
            $this->hostname = $this->network->main_hostname == $hostname ?  $this->network->main_hostname : $this->network->alternative_hostname;
75
            $this->hasNetwork = true;
76
        }
77
    }
78
 
79
    /**
80
     *
81
     * @return \LeadersLinked\Model\Network
82
     */
83
    public function getNetwork()
84
    {
85
        if($this->hasNetwork) {
86
            return $this->network;
87
        } else {
88
            return null;
89
        }
90
    }
91
 
92
    /**
93
     *
94
     * @return int
95
     */
96
    public function getNetworkId()
97
    {
98
        if($this->hasNetwork) {
99
           return $this->network->id;
100
 
101
        } else {
102
            return 0;
103
        }
104
    }
105
 
106
 
107
    /**
108
     *
109
     * @return boolean
110
     */
111
    public function hasNetwork()
112
    {
113
        return $this->hasNetwork;
114
    }
115
 
116
 
117
    public function getHostname() : string
118
    {
119
        return  $this->hostname;
120
    }
121
 
122
 
123
 
124
}