Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/library/ViewHelper/ServerUrl.php

57 lines
1.1 KiB
PHP

<?php
namespace Httpcb\ViewHelper;
/**
* Class ServerUrl
*
* @package ViewHelper
*/
class ServerUrl extends AbstractHelper
{
protected $_request;
public function getScheme()
{
return $this->_getRequest()->getScheme();
}
public function getHost()
{
return $this->_getRequest()->getHttpHost();
}
public function getPort()
{
return $this->_getRequest()->getPort();
}
public function serverUrl()
{
$port = $this->getPort();
$scheme = $this->getScheme();
// remove port if it's the default port.
if (($scheme == 'http' && $port == 80)
|| ($scheme == 'https' && $port == 443)) {
$port = null;
}
$url = $scheme . '://' . $this->getHost();
if ($port !== null) {
$url .= ':' . $port;
}
return $url;
}
/**
* @return \Phalcon\Http\RequestInterface
*/
protected function _getRequest()
{
if ($this->_request === null) {
$this->_request = $this->getDI()->getRequest();
}
return $this->_request;
}
}