Proyectos de Subversion LeadersLinked - Services

Rev

Rev 10 | Rev 15 | 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;
5 efrain 48
 
1 efrain 49
 
50
 
5 efrain 51
        //$hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
52
        $hostname = empty($_SERVER['HTTP_ORIGIN']) ?  '' : $_SERVER['HTTP_ORIGIN'];
9 efrain 53
 
11 efrain 54
        /*
10 efrain 55
        echo '<pre>';
56
        print_r($_SERVER);
57
        echo '</pre>';
58
        exit;
11 efrain 59
        */
9 efrain 60
 
10 efrain 61
 
8 efrain 62
        //$hostname = 'dev.leaderslinked.com';
5 efrain 63
        //$hostname = str_replace('www.', '', $hostname);
3 efrain 64
 
1 efrain 65
        $networkMapper = NetworkMapper::getInstance($adapter);
66
        $this->network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
67
 
68
 
69
        if($this->network) {
70
 
71
            $this->hostname = $this->network->main_hostname == $hostname ?  $this->network->main_hostname : $this->network->alternative_hostname;
72
            $this->hasNetwork = true;
73
        }
74
 
75
    }
76
 
77
 
78
 
79
 
80
    /**
81
     *
82
     * @return \LeadersLinked\Model\Network
83
     */
84
    public function getNetwork()
85
    {
86
 
87
        if($this->hasNetwork) {
88
            return $this->network;
89
        } else {
90
 
91
            return null;
92
        }
93
    }
94
 
95
 
96
    /**
97
     *
98
     * @return int
99
     */
100
    public function getNetworkId()
101
    {
102
        if($this->hasNetwork) {
103
           return $this->network->id;
104
 
105
        } else {
106
            return 0;
107
        }
108
    }
109
 
110
 
111
    /**
112
     *
113
     * @return boolean
114
     */
115
    public function hasNetwork()
116
    {
117
        return $this->hasNetwork;
118
    }
119
 
120
 
121
    public function getHostname() : string
122
    {
123
        return  $this->hostname;
124
    }
125
 
126
 
127
 
128
}