Rev 6803 | 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_HOST']) ? '' : $_SERVER['HTTP_HOST'];
//$hostname = str_replace('www.', '', $hostname);
$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;
}
}