Rev 46 | Rev 119 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Plugin;
use Laminas\Mvc\Controller\Plugin\AbstractPlugin;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Authentication\AuthenticationService;
use LeadersLinked\Model\Device;
use LeadersLinked\Mapper\DeviceMapper;
use LeadersLinked\Model\UserType;
use LeadersLinked\Mapper\NetworkMapper;
class CurrentNetworkPlugin extends AbstractPlugin
{
/**
*
* @var boolean
*/
protected $hasNetwork;
/**
*
* @return \LeadersLinked\Model\Network
*/
protected $network;
/**
*
* @var string
*/
protected $hostname;
/**
*
* @param AdapterInterface $adapter
*/
public function __construct($adapter)
{
$this->hasNetwork = false;
$hostname = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
if(empty($hostname)) {
$hostname = empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST'];
}
$hostname = trim(str_replace(['https://', 'http://'], '', $hostname));
$parts = explode('/', $hostname);
$hostname = $parts > 1 ? $parts[0] : $hostname;
$hostname = 'dev.leaderslinked.com';
// error_log('hostname : ' . $hostname . ' session ID : ' . session_id() . ' request URI : ' . $_SERVER['REQUEST_URI']);
$networkMapper = NetworkMapper::getInstance($adapter);
$this->network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
if($this->network) {
$this->hostname = $this->network->main_hostname == $hostname ? $this->network->main_hostname : $this->network->alternative_hostname;
$this->hasNetwork = true;
}
}
/**
*
* @return \LeadersLinked\Model\Network
*/
public function getNetwork()
{
if($this->hasNetwork) {
return $this->network;
} else {
return null;
}
}
/**
*
* @return int
*/
public function getNetworkId()
{
if($this->hasNetwork) {
return $this->network->id;
} else {
return 0;
}
}
/**
*
* @return boolean
*/
public function hasNetwork()
{
return $this->hasNetwork;
}
public function getHostname() : string
{
return $this->hostname;
}
}