More params and returns to PHP 7.3+

This commit is contained in:
djmaze 2020-03-16 13:08:53 +01:00
parent 3d246ae842
commit 26c38b3ec9
95 changed files with 1028 additions and 4865 deletions

View file

@ -22,9 +22,6 @@ abstract class Collection
*/
protected $aItems;
/**
* @access protected
*/
protected function __construct()
{
$this->aItems = array();
@ -32,9 +29,8 @@ abstract class Collection
/**
* @param mixed $mItem
* @param bool $bToTop = false
*/
public function Add($mItem, $bToTop = false) : self
public function Add($mItem, bool $bToTop = false) : self
{
if ($bToTop)
{
@ -49,10 +45,9 @@ abstract class Collection
}
/**
* @param array $aItems
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function AddArray($aItems) : self
public function AddArray(array $aItems) : self
{
if (!\is_array($aItems))
{
@ -72,10 +67,7 @@ abstract class Collection
$this->aItems = array();
}
/**
* @return array
*/
public function CloneAsArray()
public function CloneAsArray() : array
{
return $this->aItems;
}
@ -85,10 +77,7 @@ abstract class Collection
return \count($this->aItems);
}
/**
* @return array
*/
public function &GetAsArray()
public function &GetAsArray() : array
{
return $this->aItems;
}
@ -112,9 +101,8 @@ abstract class Collection
/**
* @param mixed $mCallback
* @return array
*/
public function FilterList($mCallback)
public function FilterList($mCallback) : array
{
$aResult = array();
if (\is_callable($mCallback))
@ -149,7 +137,7 @@ abstract class Collection
* @return mixed | null
* @return mixed
*/
public function &GetByIndex($iIndex)
public function &GetByIndex(int $iIndex)
{
$mResult = null;
if (\key_exists($iIndex, $this->aItems))
@ -161,10 +149,9 @@ abstract class Collection
}
/**
* @param array $aItems
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetAsArray($aItems)
public function SetAsArray(array $aItems)
{
if (!\is_array($aItems))
{

View file

@ -17,14 +17,8 @@ namespace MailSo\Base;
*/
class Crypt
{
/**
*
* @param string $sString
* @param string $sKey
*
* @return string
*/
public static function XxteaEncrypt($sString, $sKey)
public static function XxteaEncrypt(string $sString, string $sKey) : string
{
if (0 === \strlen($sString))
{
@ -67,13 +61,7 @@ class Crypt
return self::long2str($aV, false);
}
/**
* @param string $sEncriptedString
* @param string $sKey
*
* @return string
*/
public static function XxteaDecrypt($sEncriptedString, $sKey)
public static function XxteaDecrypt(string $sEncriptedString, string $sKey) : string
{
if (0 === \strlen($sEncriptedString))
{
@ -118,13 +106,7 @@ class Crypt
return self::long2str($aV, true);
}
/**
* @param array $aV
* @param array $aW
*
* @return string
*/
private static function long2str($aV, $aW)
private static function long2str(array $aV, array $aW) : string
{
$iLen = \count($aV);
$iN = ($iLen - 1) << 2;
@ -152,13 +134,7 @@ class Crypt
}
}
/**
* @param string $sS
* @param string $sW
*
* @return array
*/
private static function str2long($sS, $sW)
private static function str2long(string $sS, string $sW) : array
{
$aV = \unpack('V*', $sS . \str_repeat("\0", (4 - \strlen($sS) % 4) & 3));
$aV = \array_values($aV);
@ -169,12 +145,7 @@ class Crypt
return $aV;
}
/**
* @param int $iN
*
* @return int
*/
private static function int32($iN)
private static function int32(int $iN) : int
{
while ($iN >= 2147483648)
{

View file

@ -15,21 +15,12 @@ namespace MailSo\Base;
* @category MailSo
* @package Base
*/
class DateTimeHelper
abstract class DateTimeHelper
{
/**
* @access private
*/
private function __construct()
{
}
/**
* @staticvar \DateTimeZone $oDateTimeZone
*
* @return \DateTimeZone
*/
public static function GetUtcTimeZoneObject()
public static function GetUtcTimeZoneObject() : \DateTimeZone
{
static $oDateTimeZone = null;
if (null === $oDateTimeZone)
@ -42,12 +33,8 @@ class DateTimeHelper
/**
* Parse date string formated as "Thu, 10 Jun 2010 08:58:33 -0700 (PDT)"
* RFC2822
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseRFC2822DateString($sDateTime)
public static function ParseRFC2822DateString(string $sDateTime) : int
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
@ -63,12 +50,8 @@ class DateTimeHelper
/**
* Parse date string formated as "10-Jan-2012 01:58:17 -0800"
* IMAP INTERNALDATE Format
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseInternalDateString($sDateTime)
public static function ParseInternalDateString(string $sDateTime) : int
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
@ -87,12 +70,8 @@ class DateTimeHelper
/**
* Parse date string formated as "2011-06-14 23:59:59 +0400"
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseDateStringType1($sDateTime)
public static function ParseDateStringType1(string $sDateTime) : int
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
@ -106,12 +85,8 @@ class DateTimeHelper
/**
* Parse date string formated as "2015-05-08T14:32:18.483-07:00"
*
* @param string $sDateTime
*
* @return int
*/
public static function TryToParseSpecEtagFormat($sDateTime)
public static function TryToParseSpecEtagFormat(string $sDateTime) : int
{
$sDateTime = \trim(\preg_replace('/ \([a-zA-Z0-9]+\)$/', '', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/(:[\d]{2})\.[\d]{3}/', '$1', \trim($sDateTime)));
@ -121,12 +96,7 @@ class DateTimeHelper
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
}
/**
* @param string $sTime
*
* @return int
*/
public static function TimeToSec($sTime)
public static function TimeToSec(string $sTime) : int
{
$iMod = 1;
$sTime = \trim($sTime);

View file

@ -15,23 +15,11 @@ namespace MailSo\Base;
* @category MailSo
* @package Base
*/
class HtmlUtils
abstract class HtmlUtils
{
static $KOS = '@@_KOS_@@';
/**
* @access private
*/
private function __construct()
{
}
/**
* @param \DOMElement $oElement
*
* @return array
*/
public static function GetElementAttributesAsArray($oElement)
public static function GetElementAttributesAsArray(?\DOMElement $oElement) : array
{
$aResult = array();
if ($oElement)
@ -52,12 +40,7 @@ class HtmlUtils
return $aResult;
}
/**
* @param string $sText
*
* @return \DOMDocument|bool
*/
public static function GetDomFromText($sText)
public static function GetDomFromText(string $sText) : \DOMDocument
{
$bState = true;
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('libxml_use_internal_errors'))
@ -92,10 +75,7 @@ class HtmlUtils
return $oDom;
}
/**
* @return \DOMDocument
*/
private static function createDOMDocument()
private static function createDOMDocument() : \DOMDocument
{
$oDoc = new \DOMDocument('1.0', 'UTF-8');
$oDoc->encoding = 'UTF-8';
@ -106,12 +86,7 @@ class HtmlUtils
return $oDoc;
}
/**
* @param \DOMDocument|\DOMElement $oElem
*
* @return string
*/
private static function domToString($oElem, $oDom = null)
private static function domToString(\DOMNode $oElem, ?\DOMDocument $oDom = null) : string
{
$sResult = '';
if ($oElem instanceof \DOMDocument)
@ -142,13 +117,7 @@ class HtmlUtils
return \trim($sResult);
}
/**
* @param \DOMDocument $oDom
* @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
public static function GetTextFromDom_($oDom, $bWrapByFakeHtmlAndBodyDiv = true)
public static function GetTextFromDom_(\DOMDocument $oDom, bool $bWrapByFakeHtmlAndBodyDiv = true) : string
{
$sResult = '';
@ -201,13 +170,7 @@ class HtmlUtils
return $sResult;
}
/**
* @param \DOMDocument $oDom
* @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
public static function GetTextFromDom($oDom, $bWrapByFakeHtmlAndBodyDiv = true)
public static function GetTextFromDom(\DOMDocument $oDom, bool $bWrapByFakeHtmlAndBodyDiv = true)
{
$sResult = '';
@ -251,14 +214,7 @@ class HtmlUtils
return $sResult;
}
/**
* @param string $sHtml
* @param string $sHtmlAttrs = ''
* @param string $sBodyAttrs = ''
*
* @return string
*/
public static function ClearBodyAndHtmlTag($sHtml, &$sHtmlAttrs = '', &$sBodyAttrs = '')
public static function ClearBodyAndHtmlTag(string $sHtml, string &$sHtmlAttrs = '', string &$sBodyAttrs = '') : string
{
$aMatch = array();
if (\preg_match('/<html([^>]+)>/im', $sHtml, $aMatch) && !empty($aMatch[1]))
@ -291,13 +247,7 @@ class HtmlUtils
return $sHtml;
}
/**
* @param string $sHtml
* @param bool $bClearEmpty = true
*
* @return string
*/
public static function FixSchemas($sHtml, $bClearEmpty = true)
public static function FixSchemas(string $sHtml, bool $bClearEmpty = true) : string
{
if ($bClearEmpty)
{
@ -310,12 +260,7 @@ class HtmlUtils
return $sHtml;
}
/**
* @param string $sHtml
*
* @return string
*/
public static function ClearFastTags($sHtml)
public static function ClearFastTags(string $sHtml) : string
{
return \preg_replace(array(
'/<p[^>]*><\/p>/i',
@ -354,9 +299,8 @@ class HtmlUtils
/**
* @param mixed $oDom
* @param bool $bClearStyleAndHead = true
*/
public static function ClearTags(&$oDom, $bClearStyleAndHead = true)
public static function ClearTags(&$oDom, bool $bClearStyleAndHead = true)
{
$aRemoveTags = array(
'svg', 'link', 'base', 'meta', 'title', 'x-script', 'script', 'bgsound', 'keygen', 'source',
@ -402,8 +346,8 @@ class HtmlUtils
/*
// public static function ClearStyleUrlValueParserHelper($oUrlValue, $oRule, $oRuleSet,
// $oElem = null,
// &$bHasExternals = false, &$aFoundCIDs = array(),
// $aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(),
// &$bHasExternals = false, array &$aFoundCIDs = array(),
// $aContentLocationUrls = array(), array &$aFoundedContentLocationUrls = array(),
// $bDoNotReplaceExternalUrl = false, $fAdditionalExternalFilter = null
// )
// {
@ -496,9 +440,9 @@ class HtmlUtils
// }
// }
//
// public static function ClearStyleSmart($sStyle, $oElement = null,
// &$bHasExternals = false, &$aFoundCIDs = array(),
// $aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(),
// public static function ClearStyleSmart(string $sStyle, $oElement = null,
// &$bHasExternals = false, array &$aFoundCIDs = array(),
// $aContentLocationUrls = array(), array &$aFoundedContentLocationUrls = array(),
// $bDoNotReplaceExternalUrl = false, $fAdditionalExternalFilter = null,
// $sSelectorPrefix = '')
// {
@ -527,7 +471,7 @@ class HtmlUtils
// $oCssParser = new \Sabberworm\CSS\Parser($sStyle, $oSettings);
// $oCss = $oCssParser->parse();
// }
// catch (\Exception $oEception)
// catch (\Throwable $oEception)
// {
// unset($oEception);
// $mResult = false;
@ -611,7 +555,7 @@ class HtmlUtils
// {
// $mResult = $oCss->render(\Sabberworm\CSS\OutputFormat::createCompact());
// }
// catch (\Exception $oEception)
// catch (\Throwable $oEception)
// {
// unset($oEception);
// $mResult = false;
@ -623,20 +567,10 @@ class HtmlUtils
*/
/**
*
* @param string $sStyle
* @param \DOMElement $oElement
* @param bool $bHasExternals
* @param array $aFoundCIDs
* @param array $aContentLocationUrls
* @param array $aFoundedContentLocationUrls
* @param bool $bDoNotReplaceExternalUrl = false
* @param callback|null $fAdditionalExternalFilter = null
*
* @return string
*/
public static function ClearStyle($sStyle, $oElement, &$bHasExternals, &$aFoundCIDs,
$aContentLocationUrls, &$aFoundedContentLocationUrls, $bDoNotReplaceExternalUrl = false, $fAdditionalExternalFilter = null)
public static function ClearStyle(string $sStyle, \DOMElement $oElement, bool &$bHasExternals, array &$aFoundCIDs,
array $aContentLocationUrls, array &$aFoundedContentLocationUrls, bool $bDoNotReplaceExternalUrl = false, $fAdditionalExternalFilter = null)
{
$sStyle = \trim($sStyle);
$aOutStyles = array();
@ -762,10 +696,7 @@ class HtmlUtils
return \implode(';', $aOutStyles);
}
/**
* @param \DOMDocument $oDom
*/
public static function FindLinksInDOM(&$oDom)
public static function FindLinksInDOM(\DOMDocument $oDom)
{
$aNodes = $oDom->getElementsByTagName('*');
foreach ($aNodes as /* @var $oElement \DOMElement */ $oElement)
@ -854,15 +785,7 @@ class HtmlUtils
unset($aNodes);
}
/**
* @param string $sHtml
* @param bool $bDoNotReplaceExternalUrl = false
* @param bool $bFindLinksInHtml = false
* @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
public static function ClearHtmlSimple($sHtml, $bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false, $bWrapByFakeHtmlAndBodyDiv = true)
public static function ClearHtmlSimple(string $sHtml, bool $bDoNotReplaceExternalUrl = false, bool $bFindLinksInHtml = false, bool $bWrapByFakeHtmlAndBodyDiv = true) : string
{
$bHasExternals = false;
$aFoundCIDs = array();
@ -879,25 +802,14 @@ class HtmlUtils
}
/**
* @param string $sHtml
* @param bool $bHasExternals = false
* @param array $aFoundCIDs = array()
* @param array $aContentLocationUrls = array()
* @param array $aFoundedContentLocationUrls = array()
* @param bool $bDoNotReplaceExternalUrl = false
* @param bool $bFindLinksInHtml = false
* @param callback|null $fAdditionalExternalFilter = null
* @param callback|null $fAdditionalDomReader = null
* @param bool $bTryToDetectHiddenImages = false
* @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
public static function ClearHtml($sHtml, &$bHasExternals = false, &$aFoundCIDs = array(),
$aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(),
$bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false,
public static function ClearHtml(string $sHtml, bool &$bHasExternals = false, array &$aFoundCIDs = array(),
array $aContentLocationUrls = array(), array &$aFoundedContentLocationUrls = array(),
bool $bDoNotReplaceExternalUrl = false, bool $bFindLinksInHtml = false,
$fAdditionalExternalFilter = null, $fAdditionalDomReader = false,
$bTryToDetectHiddenImages = false, $bWrapByFakeHtmlAndBodyDiv = true)
bool $bTryToDetectHiddenImages = false, bool $bWrapByFakeHtmlAndBodyDiv = true)
{
$sResult = '';
@ -1264,15 +1176,7 @@ class HtmlUtils
return $sResult;
}
/**
* @param string $sHtml
* @param array $aFoundCids = array()
* @param array|null $mFoundDataURL = null
* @param array $aFoundedContentLocationUrls = array()
*
* @return string
*/
public static function BuildHtml($sHtml, &$aFoundCids = array(), &$mFoundDataURL = null, &$aFoundedContentLocationUrls = array())
public static function BuildHtml(string $sHtml, array &$aFoundCids = array(), &$mFoundDataURL = null, array &$aFoundedContentLocationUrls = array()) : string
{
$oDom = \MailSo\Base\HtmlUtils::GetDomFromText($sHtml);
@ -1407,13 +1311,7 @@ class HtmlUtils
'<body>'.$sResult.'</body></html>';
}
/**
* @param string $sText
* @param bool $bLinksWithTargetBlank = true
*
* @return string
*/
public static function ConvertPlainToHtml($sText, $bLinksWithTargetBlank = true)
public static function ConvertPlainToHtml(string $sText, bool $bLinksWithTargetBlank = true) : string
{
$sText = \trim($sText);
if (0 === \strlen($sText))
@ -1495,12 +1393,7 @@ class HtmlUtils
return $sText;
}
/**
* @param string $sText
*
* @return string
*/
public static function ConvertHtmlToPlain($sText)
public static function ConvertHtmlToPlain(string $sText) : string
{
$sText = \trim(\stripslashes($sText));
$sText = \MailSo\Base\Utils::StripSpaces($sText);

View file

@ -30,20 +30,15 @@ class Http
$this->bIsMagicQuotesOn = (bool) @\ini_get('magic_quotes_gpc');
}
/**
* @return \MailSo\Base\Http
*/
public static function NewInstance()
public static function NewInstance() : self
{
return new self();
}
/**
* @staticvar \MailSo\Base\Http $oInstance;
*
* @return \MailSo\Base\Http
*/
public static function SingletonInstance()
public static function SingletonInstance() : self
{
static $oInstance = null;
if (null === $oInstance)
@ -54,185 +49,124 @@ class Http
return $oInstance;
}
/**
* @param string $sKey
*
* @return bool
*/
public function HasQuery($sKey)
public function HasQuery(string $sKey) : bool
{
return isset($_GET[$sKey]);
}
/**
* @param string $sKey
* @param mixed $mDefault = null
* @param bool $bClearPercZeroZero = true
*
* @return mixed
*/
public function GetQuery($sKey, $mDefault = null, $bClearPercZeroZero = true)
public function GetQuery(string $sKey, $mDefault = null, bool $bClearPercZeroZero = true)
{
return isset($_GET[$sKey]) ? \MailSo\Base\Utils::StripSlashesValue($_GET[$sKey], $bClearPercZeroZero) : $mDefault;
}
/**
* @return array|null
*/
public function GetQueryAsArray()
public function GetQueryAsArray() : ?array
{
return isset($_GET) && \is_array($_GET) ? \MailSo\Base\Utils::StripSlashesValue($_GET, true) : null;
}
/**
* @param string $sKey
*
* @return bool
*/
public function HasPost($sKey)
public function HasPost(string $sKey) : bool
{
return isset($_POST[$sKey]);
}
/**
* @param string $sKey
* @param mixed $mDefault = null
* @param bool $bClearPercZeroZero = false
*
* @return mixed
*/
public function GetPost($sKey, $mDefault = null, $bClearPercZeroZero = false)
public function GetPost(string $sKey, $mDefault = null, bool $bClearPercZeroZero = false)
{
return isset($_POST[$sKey]) ? \MailSo\Base\Utils::StripSlashesValue($_POST[$sKey], $bClearPercZeroZero) : $mDefault;
}
/**
* @return array|null
*/
public function GetPostAsArray()
public function GetPostAsArray() : ?array
{
return isset($_POST) && \is_array($_POST) ? \MailSo\Base\Utils::StripSlashesValue($_POST, false) : null;
}
/**
* @param string $sKey
*
* @return bool
*/
public function HasRequest($sKey)
public function HasRequest(string $sKey) : bool
{
return isset($_REQUEST[$sKey]);
}
/**
* @param string $sKey
* @param mixed $mDefault = null
*
* @return mixed
*/
public function GetRequest($sKey, $mDefault = null)
public function GetRequest(string $sKey, $mDefault = null)
{
return isset($_REQUEST[$sKey]) ? \MailSo\Base\Utils::StripSlashesValue($_REQUEST[$sKey]) : $mDefault;
}
/**
* @param string $sKey
*
* @return bool
*/
public function HasServer($sKey)
public function HasServer(string $sKey) : bool
{
return isset($_SERVER[$sKey]);
}
/**
* @param string $sKey
* @param mixed $mDefault = null
*
* @return mixed
*/
public function GetServer($sKey, $mDefault = null)
public function GetServer(string $sKey, $mDefault = null)
{
return isset($_SERVER[$sKey]) ? $_SERVER[$sKey] : $mDefault;
}
/**
* @param string $sKey
*
* @return bool
*/
public function HasEnv($sKey)
public function HasEnv(string $sKey) : bool
{
return isset($_ENV[$sKey]);
}
/**
* @param string $sKey
* @param mixed $mDefault = null
*
* @return mixed
*/
public function GetEnv($sKey, $mDefault = null)
public function GetEnv(string $sKey, $mDefault = null)
{
return isset($_ENV[$sKey]) ? $_ENV[$sKey] : $mDefault;
}
/**
* @return string
*/
public function ServerProtocol()
public function ServerProtocol() : string
{
return $this->GetServer('SERVER_PROTOCOL', 'HTTP/1.0');
}
/**
* @return string
*/
public function GetMethod()
public function GetMethod() : string
{
return $this->GetServer('REQUEST_METHOD', '');
}
/**
* @return bool
*/
public function IsPost()
public function IsPost() : bool
{
return ('POST' === $this->GetMethod());
}
/**
* @return bool
*/
public function IsGet()
public function IsGet() : bool
{
return ('GET' === $this->GetMethod());
}
/**
* @return string
*/
public function GetQueryString()
public function GetQueryString() : string
{
return $this->GetServer('QUERY_STRING', '');
}
/**
* @return bool
*/
public function CheckLocalhost($sServer)
public function CheckLocalhost(string $sServer) : bool
{
return \in_array(\strtolower(\trim($sServer)), array(
'localhost', '127.0.0.1', '::1', '::1/128', '0:0:0:0:0:0:0:1'
));
}
/**
* @param string $sValueToCheck = ''
*
* @return bool
*/
public function IsLocalhost($sValueToCheck = '')
public function IsLocalhost(string $sValueToCheck = '') : bool
{
if (empty($sValueToCheck))
{
@ -242,10 +176,7 @@ class Http
return $this->CheckLocalhost($sValueToCheck);
}
/**
* @return string
*/
public function GetRawBody()
public function GetRawBody() : string
{
static $sRawBody = null;
if (null === $sRawBody)
@ -256,12 +187,7 @@ class Http
return $sRawBody;
}
/**
* @param string $sHeader
*
* @return string
*/
public function GetHeader($sHeader)
public function GetHeader(string $sHeader) : string
{
$sServerKey = 'HTTP_'.\strtoupper(\str_replace('-', '_', $sHeader));
$sResultHeader = $this->GetServer($sServerKey, '');
@ -279,22 +205,12 @@ class Http
return $sResultHeader;
}
/**
* @param bool $bCheckProxy = true
*
* @return string
*/
public function GetScheme($bCheckProxy = true)
public function GetScheme(bool $bCheckProxy = true) : string
{
return $this->IsSecure($bCheckProxy) ? 'https' : 'http';
}
/**
* @param bool $bCheckProxy = true
*
* @return bool
*/
public function IsSecure($bCheckProxy = true)
public function IsSecure(bool $bCheckProxy = true) : bool
{
$sHttps = \strtolower($this->GetServer('HTTPS', ''));
if ('on' === $sHttps || ('' === $sHttps && '443' === (string) $this->GetServer('SERVER_PORT', '')))
@ -313,14 +229,7 @@ class Http
return false;
}
/**
* @param bool $bWithRemoteUserData = false
* @param bool $bWithoutWWW = true
* @param bool $bWithoutPort = false
*
* @return string
*/
public function GetHost($bWithRemoteUserData = false, $bWithoutWWW = true, $bWithoutPort = false)
public function GetHost(bool $bWithRemoteUserData = false, bool $bWithoutWWW = true, bool $bWithoutPort = false) : string
{
$sHost = $this->GetServer('HTTP_HOST', '');
if (0 === \strlen($sHost))
@ -350,12 +259,7 @@ class Http
return $sHost;
}
/**
* @param bool $bCheckProxy = false
*
* @return string
*/
public function GetClientIp($bCheckProxy = false)
public function GetClientIp(bool $bCheckProxy = false) : string
{
$sIp = '';
if ($bCheckProxy && null !== $this->GetServer('HTTP_CLIENT_IP', null))
@ -374,20 +278,8 @@ class Http
return $sIp;
}
/**
* @param string $sUrl
* @param array $aPost = array()
* @param string $sCustomUserAgent = 'MailSo Http User Agent (v1)'
* @param int $iCode = 0
* @param \MailSo\Log\Logger $oLogger = null
* @param int $iTimeout = 20
* @param string $sProxy = ''
* @param string $sProxyAuth = ''
*
* @return string|bool
*/
public function SendPostRequest($sUrl, $aPost = array(), $sCustomUserAgent = 'MailSo Http User Agent (v1)', &$iCode = 0,
$oLogger = null, $iTimeout = 20, $sProxy = '', $sProxyAuth = '')
public function SendPostRequest(string $sUrl, array $aPost = array(), string $sCustomUserAgent = 'MailSo Http User Agent (v1)', int &$iCode = 0,
?\MailSo\Log\Logger $oLogger = null, int $iTimeout = 20, string $sProxy = '', string $sProxyAuth = '') : string
{
$aOptions = array(
CURLOPT_URL => $sUrl,
@ -444,14 +336,7 @@ class Http
return $mResult;
}
/**
* @param string $sUrl
* @param array $aOptions
* @param \MailSo\Log\Logger $oLogger = null
*
* @return string
*/
static public function DetectAndHackFollowLocationUrl($sUrl, &$aOptions, $oLogger = null)
static public function DetectAndHackFollowLocationUrl(string $sUrl, array &$aOptions, ?\MailSo\Log\Logger $oLogger = null) : string
{
$sSafeMode = \strtolower(\trim(@\ini_get('safe_mode')));
$bSafeMode = 'on' === $sSafeMode || '1' === $sSafeMode;
@ -535,22 +420,10 @@ class Http
}
/**
* @param string $sUrl
* @param resource $rFile
* @param string $sCustomUserAgent = 'MailSo Http User Agent (v1)'
* @param string $sContentType = ''
* @param int $iCode = 0
* @param \MailSo\Log\Logger $oLogger = null
* @param int $iTimeout = 10
* @param string $sProxy = ''
* @param string $sProxyAuth = ''
* @param array $aHttpHeaders = array()
* @param bool $bFollowLocation = true
*
* @return bool
*/
public function SaveUrlToFile($sUrl, $rFile, $sCustomUserAgent = 'MailSo Http User Agent (v1)', &$sContentType = '', &$iCode = 0,
$oLogger = null, $iTimeout = 10, $sProxy = '', $sProxyAuth = '', $aHttpHeaders = array(), $bFollowLocation = true)
public function SaveUrlToFile(string $sUrl, $rFile, string $sCustomUserAgent = 'MailSo Http User Agent (v1)', string &$sContentType = '', int &$iCode = 0,
?\MailSo\Log\Logger $oLogger = null, int $iTimeout = 10, string $sProxy = '', string $sProxyAuth = '', array $aHttpHeaders = array(), bool $bFollowLocation = true) : bool
{
if (null === $sCustomUserAgent)
{
@ -613,7 +486,7 @@ class Http
// }
}
\MailSo\Base\Http::DetectAndHackFollowLocationUrl($sUrl, $aOptions, $oLogger);
static::DetectAndHackFollowLocationUrl($sUrl, $aOptions, $oLogger);
$oCurl = \curl_init();
\curl_setopt_array($oCurl, $aOptions);
@ -640,22 +513,8 @@ class Http
return $bResult;
}
/**
* @param string $sUrl
* @param string $sCustomUserAgent = 'MailSo Http User Agent (v1)'
* @param string $sContentType = ''
* @param int $iCode = 0
* @param \MailSo\Log\Logger $oLogger = null
* @param int $iTimeout = 10
* @param string $sProxy = ''
* @param string $sProxyAuth = ''
* @param array $aHttpHeaders = array()
* @param bool $bFollowLocation = true
*
* @return string|bool
*/
public function GetUrlAsString($sUrl, $sCustomUserAgent = 'MailSo Http User Agent (v1)', &$sContentType = '', &$iCode = 0,
$oLogger = null, $iTimeout = 10, $sProxy = '', $sProxyAuth = '', $aHttpHeaders = array(), $bFollowLocation = true)
public function GetUrlAsString(string $sUrl, string $sCustomUserAgent = 'MailSo Http User Agent (v1)', string &$sContentType = '', int &$iCode = 0,
?\MailSo\Log\Logger $oLogger = null, int $iTimeout = 10, string $sProxy = '', string $sProxyAuth = '', array $aHttpHeaders = array(), bool $bFollowLocation = true) : string
{
$rMemFile = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
if ($this->SaveUrlToFile($sUrl, $rMemFile, $sCustomUserAgent, $sContentType, $iCode, $oLogger, $iTimeout, $sProxy, $sProxyAuth, $aHttpHeaders, $bFollowLocation) && \is_resource($rMemFile))
@ -667,14 +526,7 @@ class Http
return false;
}
/**
* @param int $iExpireTime
* @param bool $bSetCacheHeader = true
* @param string $sEtag = ''
*
* @return bool
*/
public function ServerNotModifiedCache($iExpireTime, $bSetCacheHeader = true, $sEtag = '')
public function ServerNotModifiedCache(int $iExpireTime, bool $bSetCacheHeader = true, string $sEtag = '') : bool
{
$bResult = false;
if (0 < $iExpireTime)
@ -725,11 +577,8 @@ class Http
/**
* @staticvar boolean $bCache
* @param string $sEtag
* @param int $iLastModified
* @param int $iExpires
*/
public function ServerUseCache($sEtag, $iLastModified, $iExpires)
public function ServerUseCache(string $sEtag, int $iLastModified, int $iExpires)
{
static $bCache = false;
if (false === $bCache)
@ -742,10 +591,7 @@ class Http
}
}
/**
* @param int $iStatus
*/
public function StatusHeader($iStatus, $sCustomStatusText = '') : void
public function StatusHeader(int $iStatus, string $sCustomStatusText = '') : void
{
$iStatus = (int) $iStatus;
if (99 < $iStatus)
@ -771,27 +617,18 @@ class Http
}
}
/**
* @return string
*/
public function GetPath()
public function GetPath() : string
{
$sUrl = \ltrim(\substr($this->GetServer('SCRIPT_NAME', ''), 0, \strrpos($this->GetServer('SCRIPT_NAME', ''), '/')), '/');
return '' === $sUrl ? '/' : '/'.$sUrl.'/';
}
/**
* @return string
*/
public function GetUrl()
{
return $this->GetServer('REQUEST_URI', '');
}
/**
* @return string
*/
public function GetFullUrl()
public function GetFullUrl() : string
{
return $this->GetScheme().'://'.$this->GetHost(true, false).$this->GetPath();
}

View file

@ -53,9 +53,6 @@ class LinkFinder
*/
private $iOptimizationLimit;
/**
* @access private
*/
private function __construct()
{
$this->iHtmlSpecialCharsFlags = (\defined('ENT_QUOTES') && \defined('ENT_SUBSTITUTE') && \defined('ENT_HTML401'))
@ -71,18 +68,12 @@ class LinkFinder
$this->Clear();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public static function NewInstance()
public static function NewInstance() : self
{
return new self();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public function Clear()
public function Clear() : self
{
$this->aPrepearPlainStringUrls = array();
$this->fLinkWrapper = null;
@ -92,12 +83,7 @@ class LinkFinder
return $this;
}
/**
* @param string $sText
*
* @return \MailSo\Base\LinkFinder
*/
public function Text($sText)
public function Text(string $sText) : self
{
$this->sText = $sText;
@ -106,10 +92,8 @@ class LinkFinder
/**
* @param mixed $fLinkWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function LinkWrapper($fLinkWrapper)
public function LinkWrapper($fLinkWrapper) : self
{
$this->fLinkWrapper = $fLinkWrapper;
@ -118,22 +102,15 @@ class LinkFinder
/**
* @param mixed $fMailWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function MailWrapper($fMailWrapper)
public function MailWrapper($fMailWrapper) : self
{
$this->fMailWrapper = $fMailWrapper;
return $this;
}
/**
* @param bool $bAddTargetBlank = false
*
* @return \MailSo\Base\LinkFinder
*/
public function UseDefaultWrappers($bAddTargetBlank = false)
public function UseDefaultWrappers(bool $bAddTargetBlank = false) : self
{
$this->fLinkWrapper = function ($sLink) use ($bAddTargetBlank) {
@ -153,12 +130,7 @@ class LinkFinder
return $this;
}
/**
* @param bool $bUseHtmlSpecialChars = true
*
* @return string
*/
public function CompileText($bUseHtmlSpecialChars = true)
public function CompileText(bool $bUseHtmlSpecialChars = true) : string
{
$sText = \substr($this->sText, 0, $this->iOptimizationLimit);
$sSubText = \substr($this->sText, $this->iOptimizationLimit);
@ -189,8 +161,8 @@ class LinkFinder
if (0 < \count($this->aPrepearPlainStringUrls))
{
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sResult = \preg_replace_callback('/'.\preg_quote(\MailSo\Base\LinkFinder::OPEN_LINK, '/').
'([\d]+)'.\preg_quote(\MailSo\Base\LinkFinder::CLOSE_LINK, '/').'/',
$sResult = \preg_replace_callback('/'.\preg_quote(static::OPEN_LINK, '/').
'([\d]+)'.\preg_quote(static::CLOSE_LINK, '/').'/',
function ($aMatches) use ($aPrepearPlainStringUrls) {
$iIndex = (int) $aMatches[1];
return isset($aPrepearPlainStringUrls[$iIndex]) ? $aPrepearPlainStringUrls[$iIndex] : '';
@ -203,12 +175,9 @@ class LinkFinder
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findLinks($sText, $fWrapper)
private function findLinks(string $sText, $fWrapper) : string
{
$sPattern = '/([\W]|^)((?:https?:\/\/)|(?:svn:\/\/)|(?:git:\/\/)|(?:s?ftps?:\/\/)|(?:www\.))'.
'((\S+?)(\\/)?)((?:&gt;)?|[^\w\=\\/;\(\)\[\]]*?)(?=<|\s|$)/imu';
@ -236,9 +205,9 @@ class LinkFinder
{
$aPrepearPlainStringUrls[] = \stripslashes($sLinkWithWrap);
return $aMatch[1].
\MailSo\Base\LinkFinder::OPEN_LINK.
static::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK.
static::CLOSE_LINK.
$aMatch[6];
}
@ -258,12 +227,9 @@ class LinkFinder
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findMails($sText, $fWrapper)
private function findMails(string $sText, $fWrapper) : string
{
$sPattern = '/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/';
@ -276,9 +242,9 @@ class LinkFinder
if (\is_string($sMailWithWrap) && 0 < \strlen($sMailWithWrap))
{
$aPrepearPlainStringUrls[] = \stripslashes($sMailWithWrap);
return \MailSo\Base\LinkFinder::OPEN_LINK.
return static::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK;
static::CLOSE_LINK;
}
return $aMatch[1];
@ -295,4 +261,4 @@ class LinkFinder
return $sText;
}
}
}

View file

@ -59,11 +59,7 @@ class Loader
}
}
/**
* @param string $sName
* @param int $iIncSize = 1
*/
public static function IncStatistic($sName, $iIncSize = 1) : void
public static function IncStatistic(string $sName, int $iIncSize = 1) : void
{
if (self::$StoreStatistic)
{
@ -73,10 +69,9 @@ class Loader
}
/**
* @param string $sName
* @param mixed $mValue
*/
public static function SetStatistic($sName, $mValue) : void
public static function SetStatistic(string $sName, $mValue) : void
{
if (self::$StoreStatistic)
{
@ -85,19 +80,14 @@ class Loader
}
/**
* @param string $sName
*
* @return mixed
*/
public static function GetStatistic($sName)
public static function GetStatistic(string $sName)
{
return self::$StoreStatistic && isset(self::$aSetStatistic[$sName]) ? self::$aSetStatistic[$sName] : null;
}
/**
* @return array|null
*/
public static function Statistic()
public static function Statistic() : ?array
{
$aResult = null;
if (self::$StoreStatistic)

View file

@ -15,20 +15,13 @@ namespace MailSo\Base;
* @category MailSo
* @package Base
*/
class ResourceRegistry
abstract class ResourceRegistry
{
/**
* @var array
*/
public static $Resources = array();
/**
* @access private
*/
private function __construct()
{
}
/**
* @staticvar bool $bInited
*/
@ -39,30 +32,28 @@ class ResourceRegistry
{
$bInited = true;
\register_shutdown_function(function () {
if (\is_array(\MailSo\Base\ResourceRegistry::$Resources))
if (\is_array(static::$Resources))
{
foreach (\array_keys(\MailSo\Base\ResourceRegistry::$Resources) as $sKey)
foreach (\array_keys(static::$Resources) as $sKey)
{
if (\is_resource(\MailSo\Base\ResourceRegistry::$Resources[$sKey]))
if (\is_resource(static::$Resources[$sKey]))
{
\MailSo\Base\Loader::IncStatistic('CloseMemoryResource');
\fclose(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
\fclose(static::$Resources[$sKey]);
}
\MailSo\Base\ResourceRegistry::$Resources[$sKey] = null;
static::$Resources[$sKey] = null;
}
}
\MailSo\Base\ResourceRegistry::$Resources = array();
static::$Resources = array();
});
}
}
/**
* @param int $iMemoryMaxInMb = 5
*
* @return resource | bool
*/
public static function CreateMemoryResource($iMemoryMaxInMb = 5)
public static function CreateMemoryResource(int $iMemoryMaxInMb = 5)
{
self::regResourcesShutdownFunc();
@ -70,7 +61,7 @@ class ResourceRegistry
if (\is_resource($oResult))
{
\MailSo\Base\Loader::IncStatistic('CreateMemoryResource');
\MailSo\Base\ResourceRegistry::$Resources[(string) $oResult] = $oResult;
static::$Resources[(string) $oResult] = $oResult;
return $oResult;
}
@ -78,11 +69,9 @@ class ResourceRegistry
}
/**
* @param string $sString
*
* @return resource | bool
*/
public static function CreateMemoryResourceFromString($sString)
public static function CreateMemoryResourceFromString(string $sString)
{
$oResult = self::CreateMemoryResource();
if (\is_resource($oResult))
@ -102,11 +91,11 @@ class ResourceRegistry
if (\is_resource($rResource))
{
$sKey = (string) $rResource;
if (isset(\MailSo\Base\ResourceRegistry::$Resources[$sKey]))
if (isset(static::$Resources[$sKey]))
{
\fclose(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
\MailSo\Base\ResourceRegistry::$Resources[$sKey] = null;
unset(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
\fclose(static::$Resources[$sKey]);
static::$Resources[$sKey] = null;
unset(static::$Resources[$sKey]);
\MailSo\Base\Loader::IncStatistic('CloseMemoryResource');
}

View file

@ -68,13 +68,7 @@ class Binary
*/
private $sReadEndBuffer;
/**
* @param string $sContentTransferEncoding
* @param bool $bDecode = true
*
* @return string
*/
public static function GetInlineDecodeOrEncodeFunctionName($sContentTransferEncoding, $bDecode = true)
public static function GetInlineDecodeOrEncodeFunctionName(string $sContentTransferEncoding, bool $bDecode = true) : string
{
$sFunctionName = '';
switch (strtolower($sContentTransferEncoding))
@ -92,25 +86,13 @@ class Binary
return $sFunctionName;
}
/**
* @param string $sBodyString
* @param string $sEndBuffer
*
* @return string
*/
public static function InlineNullDecode($sBodyString, &$sEndBuffer)
public static function InlineNullDecode(string $sBodyString, string &$sEndBuffer) : string
{
$sEndBuffer = '';
return $sBodyString;
}
/**
* @param string $sBaseString
* @param string $sEndBuffer
*
* @return string
*/
public static function InlineBase64Decode($sBaseString, &$sEndBuffer)
public static function InlineBase64Decode(string $sBaseString, string &$sEndBuffer) : string
{
$sEndBuffer = '';
$sBaseString = str_replace(array("\r", "\n", "\t"), '', $sBaseString);
@ -124,13 +106,7 @@ class Binary
return \MailSo\Base\Utils::Base64Decode($sBaseString);
}
/**
* @param string $sQuotedPrintableString
* @param string $sEndBuffer
*
* @return string
*/
public static function InlineQuotedPrintableDecode($sQuotedPrintableString, &$sEndBuffer)
public static function InlineQuotedPrintableDecode(string $sQuotedPrintableString, string &$sEndBuffer) : string
{
$sEndBuffer = '';
$sQuotedPrintableLen = strlen($sQuotedPrintableString);
@ -143,13 +119,7 @@ class Binary
return quoted_printable_decode($sQuotedPrintableString);
}
/**
* @param string $sEncodedString
* @param string $sEndBuffer
*
* @return string
*/
public static function InlineConvertDecode($sEncodedString, &$sEndBuffer, $sFromEncoding, $sToEncoding)
public static function InlineConvertDecode(string $sEncodedString, string &$sEndBuffer, string $sFromEncoding, string $sToEncoding) : string
{
$sEndBuffer = '';
$sQuotedPrintableLen = strlen($sEncodedString);
@ -164,10 +134,8 @@ class Binary
/**
* @param resource $rStream
*
* @return bool
*/
public static function IsStreamRemembed($rStream)
public static function IsStreamRemembed($rStream) : bool
{
foreach (self::$aRememberStreams as $rRem)
{
@ -193,14 +161,11 @@ class Binary
/**
* @param resource $rStream
* @param string $sUtilsDecodeOrEncodeFunctionName = null
* @param string $sFromEncoding = null
* @param string $sToEncoding = null
*
* @return resource|bool
*/
public static function CreateStream($rStream,
$sUtilsDecodeOrEncodeFunctionName = null, $sFromEncoding = null, $sToEncoding = null)
string $sUtilsDecodeOrEncodeFunctionName = null, string $sFromEncoding = null, string $sToEncoding = null)
{
if (!in_array(self::STREAM_NAME, stream_get_wrappers()))
{
@ -242,12 +207,7 @@ class Binary
return \fopen(self::STREAM_NAME.'://'.$sHashName, 'rb');
}
/**
* @param string $sPath
*
* @return bool
*/
public function stream_open($sPath)
public function stream_open(string $sPath) : bool
{
$this->iPos = 0;
$this->sBuffer = '';
@ -281,12 +241,7 @@ class Binary
return $bResult;
}
/**
* @param int $iCount
*
* @return string
*/
public function stream_read($iCount)
public function stream_read(int $iCount) : string
{
$sReturn = '';
$sFunctionName = $this->sFunctionName;
@ -354,35 +309,22 @@ class Binary
return false;
}
/**
* @return int
*/
public function stream_write()
public function stream_write() : int
{
return 0;
}
/**
* @return int
*/
public function stream_tell()
public function stream_tell() : int
{
return $this->iPos;
}
/**
* @return bool
*/
public function stream_eof()
public function stream_eof() : bool
{
return 0 === strlen($this->sBuffer) && feof($this->rStream);
}
/**
*
* @return array
*/
public function stream_stat()
public function stream_stat() : array
{
return array(
'dev' => 2,
@ -401,10 +343,7 @@ class Binary
);
}
/**
* @return bool
*/
public function stream_seek()
public function stream_seek() : bool
{
return false;
}

View file

@ -45,11 +45,10 @@ class Literal
/**
* @param resource $rStream
* @param int $iLiteralLen
*
* @return resource|bool
*/
public static function CreateStream($rStream, $iLiteralLen)
public static function CreateStream($rStream, int $iLiteralLen)
{
if (!in_array(self::STREAM_NAME, stream_get_wrappers()))
{
@ -65,12 +64,7 @@ class Literal
return fopen(self::STREAM_NAME.'://'.$sHashName, 'rb');
}
/**
* @param string $sPath
*
* @return bool
*/
public function stream_open($sPath)
public function stream_open(string $sPath) : bool
{
$this->iPos = 0;
$this->iSize = 0;
@ -98,12 +92,7 @@ class Literal
return $bResult;
}
/**
* @param int $iCount
*
* @return string
*/
public function stream_read($iCount)
public function stream_read(int $iCount) : string
{
$sResult = false;
if ($this->iSize < $this->iPos + $iCount)
@ -138,34 +127,22 @@ class Literal
return $sResult;
}
/**
* @return int
*/
public function stream_write()
public function stream_write() : int
{
return 0;
}
/**
* @return int
*/
public function stream_tell()
public function stream_tell() : int
{
return $this->iPos;
}
/**
* @return bool
*/
public function stream_eof()
public function stream_eof() : bool
{
return $this->iPos >= $this->iSize;
}
/**
* @return array
*/
public function stream_stat()
public function stream_stat() : array
{
return array(
'dev' => 2,
@ -184,10 +161,7 @@ class Literal
);
}
/**
* @return bool
*/
public function stream_seek()
public function stream_seek() : bool
{
return false;
}

View file

@ -54,11 +54,9 @@ class SubStreams
private $iPos;
/**
* @param array $aSubStreams
*
* @return resource|bool
*/
public static function CreateStream($aSubStreams)
public static function CreateStream(array $aSubStreams)
{
if (!\in_array(self::STREAM_NAME, \stream_get_wrappers()))
{
@ -91,12 +89,7 @@ class SubStreams
return $nNull;
}
/**
* @param string $sPath
*
* @return bool
*/
public function stream_open($sPath)
public function stream_open(string $sPath) : bool
{
$this->aSubStreams = array();
@ -125,12 +118,7 @@ class SubStreams
return $bResult;
}
/**
* @param int $iCount
*
* @return string
*/
public function stream_read($iCount)
public function stream_read(int $iCount) : string
{
$sReturn = '';
$mCurrentPart = null;
@ -194,34 +182,22 @@ class SubStreams
return false;
}
/**
* @return int
*/
public function stream_write()
public function stream_write() : int
{
return 0;
}
/**
* @return int
*/
public function stream_tell()
public function stream_tell() : int
{
return $this->iPos;
}
/**
* @return bool
*/
public function stream_eof()
public function stream_eof() : bool
{
return $this->bIsEnd;
}
/**
* @return array
*/
public function stream_stat()
public function stream_stat() : array
{
return array(
'dev' => 2,
@ -240,10 +216,7 @@ class SubStreams
);
}
/**
* @return bool
*/
public function stream_seek()
public function stream_seek() : bool
{
return false;
}

View file

@ -42,12 +42,9 @@ class TempFile
}
/**
* @param string $sHash
* @param string $sFileName
*
* @return resource|bool
*/
public static function CreateStream($sHash, &$sFileName = '')
public static function CreateStream(string $sHash, string &$sFileName = '')
{
self::Reg();
@ -55,12 +52,7 @@ class TempFile
return fopen($sFileName, 'r+b');
}
/**
* @param string $sPath
*
* @return bool
*/
public function stream_open($sPath)
public function stream_open(string $sPath) : bool
{
$bResult = false;
$aPath = parse_url($sPath);
@ -91,73 +83,42 @@ class TempFile
return $bResult;
}
/**
* @return bool
*/
public function stream_close()
public function stream_close() : bool
{
return true;
}
/**
* @return bool
*/
public function stream_flush()
public function stream_flush() : bool
{
return fflush($this->rSream);
}
/**
* @param int $iLen
*
* @return string
*/
public function stream_read($iLen)
public function stream_read(int $iLen) : string
{
return fread($this->rSream, $iLen);
}
/**
* @param string $sInputString
*
* @return int
*/
public function stream_write($sInputString)
public function stream_write(string $sInputString) : int
{
return fwrite($this->rSream, $sInputString);
}
/**
* @return int
*/
public function stream_tell()
public function stream_tell() : int
{
return ftell($this->rSream);
}
/**
* @return bool
*/
public function stream_eof()
public function stream_eof() : bool
{
return feof($this->rSream);
}
/**
* @return array
*/
public function stream_stat()
public function stream_stat() : array
{
return fstat($this->rSream);
}
/**
* @param int $iOffset
* @param int $iWhence = SEEK_SET
*
* @return int
*/
public function stream_seek($iOffset, $iWhence = SEEK_SET)
public function stream_seek(int $iOffset, int $iWhence = SEEK_SET) : int
{
return fseek($this->rSream, $iOffset, $iWhence);
}

View file

@ -34,11 +34,10 @@ class Test
private $rReadSream;
/**
* @param string $sRawResponse
*
* @return resource|bool
*/
public static function CreateStream($sRawResponse)
public static function CreateStream(string $sRawResponse)
{
if (!in_array(self::STREAM_NAME, stream_get_wrappers()))
{
@ -58,12 +57,7 @@ class Test
return fopen(self::STREAM_NAME.'://'.$sHashName, 'r+b');
}
/**
* @param string $sPath
*
* @return bool
*/
public function stream_open($sPath)
public function stream_open(string $sPath) : bool
{
$bResult = false;
$aPath = parse_url($sPath);
@ -84,54 +78,32 @@ class Test
return $bResult;
}
/**
* @param int $iCount
*
* @return string
*/
public function stream_read($iCount)
public function stream_read(int $iCount) : string
{
return fread($this->rReadSream, $iCount);
}
/**
* @param string $sInputString
*
* @return int
*/
public function stream_write($sInputString)
public function stream_write(string $sInputString) : int
{
return strlen($sInputString);
}
/**
* @return int
*/
public function stream_tell()
public function stream_tell() : int
{
return ftell($this->rReadSream);
}
/**
* @return bool
*/
public function stream_eof()
public function stream_eof() : bool
{
return feof($this->rReadSream);
}
/**
* @return array
*/
public function stream_stat()
public function stream_stat() : array
{
return fstat($this->rReadSream);
}
/**
* @return bool
*/
public function stream_seek()
public function stream_seek() : bool
{
return false;
}

View file

@ -114,10 +114,7 @@ END;
'.949' => 'euc-kr',
);
/**
* @return string
*/
public static function DetectSystemCharset()
public static function DetectSystemCharset() : string
{
$sResult = '';
$sLocale = @\setlocale(LC_ALL, '');
@ -136,10 +133,7 @@ END;
return $sResult;
}
/**
* @return string
*/
public static function ConvertSystemString($sSrt)
public static function ConvertSystemString(string $sSrt) : string
{
$sSrt = \trim($sSrt);
if (!empty($sSrt) && !static::IsUtf8($sSrt))
@ -159,13 +153,7 @@ END;
return $sSrt;
}
/**
* @param string $sEncoding
* @param bool $bAsciAsUtf8 = false
*
* @return string
*/
public static function NormalizeCharset($sEncoding, $bAsciAsUtf8 = false)
public static function NormalizeCharset(string $sEncoding, bool $bAsciAsUtf8 = false) : string
{
$sEncoding = \strtolower($sEncoding);
@ -214,13 +202,7 @@ END;
return $sEncoding;
}
/**
* @param string $sCharset
* @param string $sValue
*
* @return string
*/
public static function NormalizeCharsetByValue($sCharset, $sValue)
public static function NormalizeCharsetByValue(string $sCharset, string $sValue) : string
{
$sCharset = static::NormalizeCharset($sCharset);
@ -236,12 +218,9 @@ END;
}
/**
* @param string $sFilePath
* @param function $fFileExistsCallback = null
*
* @return string
*/
public static function SmartFileExists($sFilePath, $fFileExistsCallback = null)
public static function SmartFileExists(string $sFilePath, $fFileExistsCallback = null) : string
{
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
if (!$fFileExistsCallback)
@ -285,26 +264,14 @@ END;
return $sFilePath;
}
/**
* @param string $sCharset
*
* @return bool
*/
public static function ValidateCharsetName($sCharset)
public static function ValidateCharsetName(string $sCharset) : bool
{
$sCharset = \strtolower(static::NormalizeCharset($sCharset));
return 0 < \strlen($sCharset) && (\in_array($sCharset, array(\MailSo\Base\Enumerations\Charset::UTF_7_IMAP)) ||
\in_array($sCharset, static::$SuppostedCharsets));
}
/**
* @param string $sInputString
* @param string $sInputFromEncoding
* @param string $sInputToEncoding
*
* @return string|bool
*/
public static function MbConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
public static function MbConvertEncoding(string $sInputString, string $sInputFromEncoding, string $sInputToEncoding) : string
{
static $sMbstringSubCh = null;
if (null === $sMbstringSubCh)
@ -319,14 +286,7 @@ END;
return $sResult;
}
/**
* @param string $sInputString
* @param string $sInputFromEncoding
* @param string $sInputToEncoding
*
* @return string
*/
public static function ConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
public static function ConvertEncoding(string $sInputString, string $sInputFromEncoding, string $sInputToEncoding) : string
{
$sResult = $sInputString;
@ -403,12 +363,7 @@ END;
return $sResult;
}
/**
* @param string $sValue
*
* @return bool
*/
public static function IsAscii($sValue)
public static function IsAscii(string $sValue) : bool
{
if ('' === \trim($sValue))
{
@ -418,32 +373,17 @@ END;
return !\preg_match('/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/', $sValue);
}
/**
* @param string $sValue
*
* @return string
*/
public static function StrToLowerIfAscii($sValue)
public static function StrToLowerIfAscii(string $sValue) : string
{
return static::IsAscii($sValue) ? \strtolower($sValue) : $sValue;
}
/**
* @param string $sValue
*
* @return string
*/
public static function StrToUpperIfAscii($sValue)
public static function StrToUpperIfAscii(string $sValue) : string
{
return static::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
}
/**
* @param string $sValue
*
* @return string
*/
public static function StrMailDomainToLowerIfAscii($sValue)
public static function StrMailDomainToLowerIfAscii(string $sValue) : string
{
$aParts = \explode('@', $sValue, 2);
if (!empty($aParts[1]))
@ -454,35 +394,19 @@ END;
return \implode('@', $aParts);
}
/**
* @param string $sValue
*
* @return string
*/
public static function StripSpaces($sValue)
public static function StripSpaces(string $sValue) : string
{
return static::Trim(
\preg_replace('/[\s]+/u', ' ', $sValue));
}
/**
* @param string $sValue
*
* @return bool
*/
public static function IsUtf8($sValue)
public static function IsUtf8(string $sValue) : bool
{
return (bool) (\function_exists('mb_check_encoding') ?
\mb_check_encoding($sValue, 'UTF-8') : \preg_match('//u', $sValue));
}
/**
* @param int $iSize
* @param int $iRound
*
* @return string
*/
public static function FormatFileSize($iSize, $iRound = 0)
public static function FormatFileSize(int $iSize, int $iRound = 0) : string
{
$aSizes = array('B', 'KB', 'MB');
for ($iIndex = 0; $iSize > 1024 && isset($aSizes[$iIndex + 1]); $iIndex++)
@ -492,13 +416,7 @@ END;
return \round($iSize, $iRound).$aSizes[$iIndex];
}
/**
* @param string $sEncodedValue
* @param string $sEncodeingType
*
* @return string
*/
public static function DecodeEncodingValue($sEncodedValue, $sEncodeingType)
public static function DecodeEncodingValue(string $sEncodedValue, string $sEncodeingType) : string
{
$sResult = $sEncodedValue;
switch (\strtolower($sEncodeingType))
@ -516,24 +434,12 @@ END;
return $sResult;
}
/**
* @param string $sInputValue
*
* @return string
*/
public static function DecodeFlowedFormat($sInputValue)
public static function DecodeFlowedFormat(string $sInputValue) : string
{
return \preg_replace('/ ([\r]?[\n])/m', ' ', $sInputValue);
}
/**
* @param string $sEncodedValue
* @param string $sIncomingCharset = ''
* @param string $sForcedIncomingCharset = ''
*
* @return string
*/
public static function DecodeHeaderValue($sEncodedValue, $sIncomingCharset = '', $sForcedIncomingCharset = '')
public static function DecodeHeaderValue(string $sEncodedValue, string $sIncomingCharset = '', string $sForcedIncomingCharset = '') : string
{
$sValue = $sEncodedValue;
if (0 < \strlen($sIncomingCharset))
@ -646,13 +552,7 @@ END;
return $sValue;
}
/**
* @param string $sIncHeaders
* @param string $aHeadersToRemove = array()
*
* @return string
*/
public static function RemoveHeaderFromHeaders($sIncHeaders, $aHeadersToRemove = array())
public static function RemoveHeaderFromHeaders(string $sIncHeaders, array $aHeadersToRemove = array()) : string
{
$sResultHeaders = $sIncHeaders;
@ -704,13 +604,7 @@ END;
return $sResultHeaders;
}
/**
* @param string $sEncodeType
* @param string $sValue
*
* @return string
*/
public static function EncodeUnencodedValue($sEncodeType, $sValue)
public static function EncodeUnencodedValue(string $sEncodeType, string $sValue) : string
{
$sValue = \trim($sValue);
if (0 < \strlen($sValue) && !static::IsAscii($sValue))
@ -736,13 +630,9 @@ END;
/**
* @unused
*
* @param string $sEncodeType
* @param string $sEncodeCharset
* @param string $sValue
*
* @return string
*/
public static function EncodeHeaderValue($sEncodeType, $sEncodeCharset, $sValue)
public static function EncodeHeaderValue(string $sEncodeType, string $sEncodeCharset, string $sValue) : string
{
$sValue = \trim($sValue);
if (0 < \strlen($sValue) && !static::IsAscii($sValue))
@ -764,16 +654,7 @@ END;
return \trim($sValue);
}
/**
* @param string $sAttrName
* @param string $sValue = 'utf-8'
* @param string $sCharset = ''
* @param string $sLang = ''
* @param int $iLen = 78
*
* @return string|bool
*/
public static function AttributeRfc2231Encode($sAttrName, $sValue, $sCharset = 'utf-8', $sLang = '', $iLen = 1000)
public static function AttributeRfc2231Encode(string $sAttrName, string $sValue, string $sCharset = 'utf-8', string $sLang = '', int $iLen = 1000) : string
{
$sValue = \strtoupper($sCharset).'\''.$sLang.'\''.
\preg_replace_callback('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', function ($match) {
@ -806,13 +687,8 @@ END;
return $sAttrName.'*='.$sValue;
}
}
/**
* @param string $sAttrName
* @param string $sValue
*
* @return string
*/
public static function EncodeHeaderUtf8AttributeValue($sAttrName, $sValue)
public static function EncodeHeaderUtf8AttributeValue(string $sAttrName, string $sValue) : string
{
$sAttrName = \trim($sAttrName);
$sValue = \trim($sValue);
@ -836,12 +712,7 @@ END;
return \trim($sValue);
}
/**
* @param string $sEmail
*
* @return string
*/
public static function GetAccountNameFromEmail($sEmail)
public static function GetAccountNameFromEmail(string $sEmail) : string
{
$sResult = '';
if (0 < \strlen($sEmail))
@ -853,12 +724,7 @@ END;
return $sResult;
}
/**
* @param string $sEmail
*
* @return string
*/
public static function GetDomainFromEmail($sEmail)
public static function GetDomainFromEmail(string $sEmail) : string
{
$sResult = '';
if (0 < \strlen($sEmail))
@ -873,12 +739,7 @@ END;
return $sResult;
}
/**
* @param string $sDomain
*
* @return string
*/
public static function GetClearDomainName($sDomain)
public static function GetClearDomainName(string $sDomain) : string
{
$sResultDomain = \preg_replace(
'/^(webmail|email|mail|www|imap4|imap|demo|client|ssl|secure|test|cloud|box|m)\./i',
@ -887,23 +748,13 @@ END;
return false === \strpos($sResultDomain, '.') ? $sDomain : $sResultDomain;
}
/**
* @param string $sFileName
*
* @return string
*/
public static function GetFileExtension($sFileName)
public static function GetFileExtension(string $sFileName) : string
{
$iLast = \strrpos($sFileName, '.');
return false === $iLast ? '' : \strtolower(\substr($sFileName, $iLast + 1));
}
/**
* @param string $sFileName
*
* @return string
*/
public static function MimeContentType($sFileName)
public static function MimeContentType(string $sFileName) : string
{
$sResult = 'application/octet-stream';
$sFileName = \trim(\strtolower($sFileName));
@ -1085,13 +936,7 @@ END;
return $sResult;
}
/**
* @param string $sContentType
* @param string $sFileName
*
* @return string
*/
public static function ContentTypeType($sContentType, $sFileName)
public static function ContentTypeType(string $sContentType, string $sFileName) : string
{
$sResult = '';
$sContentType = \strtolower($sContentType);
@ -1151,12 +996,9 @@ END;
/**
* @staticvar bool $bValidateAction
*
* @param int $iTimeToReset = 15
* @param int $iTimeToAdd = 120
*
* @return bool
*/
public static function ResetTimeLimit($iTimeToReset = 15, $iTimeToAdd = 120)
public static function ResetTimeLimit(int $iTimeToReset = 15, int $iTimeToAdd = 120) : bool
{
$iTime = \time();
if ($iTime < \MailSo\Base\Loader::$InitTime + 5)
@ -1193,12 +1035,7 @@ END;
return false;
}
/**
* @param string $sText
*
* @return string
*/
public static function InlineRebuildStringToJsString($sText)
public static function InlineRebuildStringToJsString(string $sText) : string
{
static $aJsonReplaces = array(
array('\\', "\n", "\t", "\r", '\b', "\f", '"'),
@ -1209,10 +1046,7 @@ END;
\str_replace($aJsonReplaces[0], $aJsonReplaces[1], $sText));
}
/**
* @param array $aInput
*/
public static function ClearArrayUtf8Values(&$aInput)
public static function ClearArrayUtf8Values(array &$aInput)
{
if (\is_array($aInput))
{
@ -1233,11 +1067,8 @@ END;
/**
* @param mixed $mInput
* @param \MailSo\Log\Logger|null $oLogger = null
*
* @return string
*/
public static function Php2js($mInput, $oLogger = null)
public static function Php2js($mInput, ?\MailSo\Log\Logger $oLogger = null) : string
{
static $iOpt = null;
if (null === $iOpt)
@ -1283,46 +1114,26 @@ END;
return $sResult;
}
/**
* @param string $sFileName
*
* @return string
*/
public static function ClearFileName($sFileName)
public static function ClearFileName(string $sFileName) : string
{
return static::Trim(static::ClearNullBite(
static::StripSpaces(
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sFileName))));
}
/**
* @param string $sValue
*
* @return string
*/
public static function ClearXss($sValue)
public static function ClearXss(string $sValue) : string
{
return static::Trim(static::ClearNullBite(
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue)));
}
/**
* @param string $sValue
*
* @return string
*/
public static function Trim($sValue)
public static function Trim(string $sValue) : string
{
return \trim(\preg_replace('/^[\x00-\x1F]+/u', '',
\preg_replace('/[\x00-\x1F]+$/u', '', \trim($sValue))));
}
/**
* @param string $sDir
*
* @return bool
*/
public static function RecRmDir($sDir)
public static function RecRmDir(string $sDir) : bool
{
if (@\is_dir($sDir))
{
@ -1349,11 +1160,7 @@ END;
return false;
}
/**
* @param string $sSource
* @param string $sDestination
*/
public static function CopyDir($sSource, $sDestination)
public static function CopyDir(string $sSource, string $sDestination)
{
if (\is_dir($sSource))
{
@ -1387,14 +1194,7 @@ END;
}
}
/**
* @param string $sTempPath
* @param int $iTime2Kill
* @param int $iNow
*
* @return bool
*/
public static function RecTimeDirRemove($sTempPath, $iTime2Kill, $iNow)
public static function RecTimeDirRemove(string $sTempPath, int $iTime2Kill, int $iNow) : bool
{
$iFileCount = 0;
@ -1444,12 +1244,7 @@ END;
return true;
}
/**
* @param string $sTempPath
* @param int $iTime2Kill
* @param int $iNow
*/
public static function TimeFilesRemove($sTempPath, $iTime2Kill, $iNow)
public static function TimeFilesRemove(string $sTempPath, int $iTime2Kill, int $iNow)
{
$bResult = true;
@ -1481,13 +1276,7 @@ END;
return $bResult;
}
/**
* @param string $sUtfString
* @param int $iLength
*
* @return string
*/
public static function Utf8Truncate($sUtfString, $iLength)
public static function Utf8Truncate(string $sUtfString, int $iLength) : string
{
if (\strlen($sUtfString) <= $iLength)
{
@ -1507,13 +1296,7 @@ END;
return '';
}
/**
* @param string $sUtfString
* @param string $sReplaceOn = ''
*
* @return string
*/
public static function Utf8Clear($sUtfString, $sReplaceOn = '')
public static function Utf8Clear(string $sUtfString, string $sReplaceOn = '') : string
{
if ('' === $sUtfString)
{
@ -1539,12 +1322,7 @@ END;
return $sUtfString;
}
/**
* @param string $sUtfString
*
* @return bool
*/
public static function IsRTL($sUtfString)
public static function IsRTL(string $sUtfString) : bool
{
// \x{0591}-\x{05F4} - Hebrew
// \x{0600}-\x{068F} - Arabic
@ -1554,12 +1332,7 @@ END;
return 0 < (int) preg_match('/[\x{0591}-\x{05F4}\x{0600}-\x{068F}\x{0750}-\x{077F}\x{08A0}-\x{08FF}\x{103A0}-\x{103DF}]/u', $sUtfString);
}
/**
* @param string $sString
*
* @return string
*/
public static function Base64Decode($sString)
public static function Base64Decode(string $sString) : string
{
$sResultString = \base64_decode($sString, true);
if (false === $sResultString)
@ -1587,33 +1360,18 @@ END;
return $sResultString;
}
/**
* @param string $sValue
*
* @return string
*/
public static function UrlSafeBase64Encode($sValue)
public static function UrlSafeBase64Encode(string $sValue) : string
{
return \rtrim(\strtr(\base64_encode($sValue), '+/', '-_'), '=');
}
/**
* @param string $sValue
*
* @return string
*/
public static function UrlSafeBase64Decode($sValue)
public static function UrlSafeBase64Decode(string $sValue) : string
{
$sValue = \rtrim(\strtr($sValue, '-_.', '+/='), '=');
return static::Base64Decode(\str_pad($sValue, \strlen($sValue) + (\strlen($sValue) % 4), '=', STR_PAD_RIGHT));
}
/**
* @param string $sSequence
*
* @return array
*/
public static function ParseFetchSequence($sSequence)
public static function ParseFetchSequence(string $sSequence) : array
{
$aResult = array();
$sSequence = \trim($sSequence);
@ -1641,12 +1399,8 @@ END;
return $aResult;
}
/**
* @param array $aSequence
*
* @return string
*/
public static function PrepearFetchSequence($aSequence)
public static function PrepearFetchSequence(array $aSequence) : string
{
$aResult = array();
if (\is_array($aSequence) && 0 < \count($aSequence))
@ -1693,13 +1447,9 @@ END;
}
/**
*
* @param resource $fResource
* @param int $iBufferLen = 8192
*
* @return bool
*/
public static function FpassthruWithTimeLimitReset($fResource, $iBufferLen = 8192)
public static function FpassthruWithTimeLimitReset($fResource, int $iBufferLen = 8192) : bool
{
$bResult = false;
if (\is_resource($fResource))
@ -1725,15 +1475,8 @@ END;
/**
* @param resource $rRead
* @param array $aWrite
* @param int $iBufferLen = 8192
* @param bool $bResetTimeLimit = true
* @param bool $bFixCrLf = false
* @param bool $bRewindOnComplete = false
*
* @return int|bool
*/
public static function MultipleStreamWriter($rRead, $aWrite, $iBufferLen = 8192, $bResetTimeLimit = true, $bFixCrLf = false, $bRewindOnComplete = false)
public static function MultipleStreamWriter($rRead, array $aWrite, int $iBufferLen = 8192, bool $bResetTimeLimit = true, bool $bFixCrLf = false, bool $bRewindOnComplete = false) : int
{
$mResult = false;
if ($rRead && \is_array($aWrite) && 0 < \count($aWrite))
@ -1791,12 +1534,7 @@ END;
return $mResult;
}
/**
* @param string $sUtfModifiedString
*
* @return string
*/
public static function ModifiedToPlainUtf7($sUtfModifiedString)
public static function ModifiedToPlainUtf7(string $sUtfModifiedString) : string
{
$sUtf = '';
$bBase = false;
@ -1840,12 +1578,7 @@ END;
return $sUtf;
}
/**
* @param string $sStr
*
* @return string|bool
*/
public static function Utf7ModifiedToUtf8($sStr)
public static function Utf7ModifiedToUtf8(string $sStr) : string
{
$aArray = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,62, 63,-1,-1,-1,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,
@ -1942,12 +1675,7 @@ END;
return $sResult;
}
/**
* @param string $sStr
*
* @return string|bool
*/
public static function Utf8ToUtf7Modified($sStr)
public static function Utf8ToUtf7Modified(string $sStr) : string
{
$sArray = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S',
'T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
@ -2087,12 +1815,7 @@ END;
return $sReturn;
}
/**
* @param string|array $mFunctionNameOrNames
*
* @return bool
*/
public static function FunctionExistsAndEnabled($mFunctionNameOrNames)
public static function FunctionExistsAndEnabled($mFunctionNameOrNames) : bool
{
static $aCache = null;
@ -2141,23 +1864,17 @@ END;
return !\in_array($mFunctionNameOrNames, $aCache);
}
/**
* @param string $mValue
*
* @return string
*/
public static function ClearNullBite($mValue)
public static function ClearNullBite($mValue) : string
{
return \str_replace('%00', '', $mValue);
}
/**
* @param mixed $mValue
* @param bool $bClearNullBite = false
*
* @return mixed
*/
public static function StripSlashesValue($mValue, $bClearNullBite = false)
public static function StripSlashesValue($mValue, bool $bClearNullBite = false)
{
static $bIsMagicQuotesOn = null;
if (null === $bIsMagicQuotesOn)
@ -2190,12 +1907,7 @@ END;
return $mValue;
}
/**
* @param string $sStr
*
* @return string
*/
public static function CharsetDetect($sStr)
public static function CharsetDetect(string $sStr) : string
{
$mResult = '';
if (!static::IsAscii($sStr))
@ -2206,35 +1918,19 @@ END;
return \is_string($mResult) && 0 < \strlen($mResult) ? $mResult : '';
}
/**
* @param string $sAdditionalSalt = ''
*
* @return string
*/
public static function Md5Rand($sAdditionalSalt = '')
public static function Md5Rand(string $sAdditionalSalt = '') : string
{
return \md5(\microtime(true).\rand(10000, 99999).
\md5($sAdditionalSalt).\rand(10000, 99999).\microtime(true));
}
/**
* @param string $sAdditionalSalt = ''
*
* @return string
*/
public static function Sha1Rand($sAdditionalSalt = '')
public static function Sha1Rand(string $sAdditionalSalt = '') : string
{
return \sha1(\microtime(true).\rand(10000, 99999).
\sha1($sAdditionalSalt).\rand(10000, 99999).\microtime(true));
}
/**
* @param string $sData
* @param string $sKey
*
* @return string
*/
public static function Hmac($sData, $sKey)
public static function Hmac(string $sData, string $sKey) : string
{
if (\function_exists('hash_hmac'))
{
@ -2254,13 +1950,7 @@ END;
return \md5(($sKey ^ $sOpad).\pack('H*', \md5(($sKey ^ $sIpad).$sData)));
}
/**
* @param string $sDomain
* @param bool $bSimple = false
*
* @return bool
*/
public static function ValidateDomain($sDomain, $bSimple = false)
public static function ValidateDomain(string $sDomain, bool $bSimple = false) : bool
{
$aMatch = array();
if ($bSimple)
@ -2274,20 +1964,12 @@ END;
));
}
/**
* @param string $sIp
*
* @return bool
*/
public static function ValidateIP($sIp)
public static function ValidateIP(string $sIp) : bool
{
return !empty($sIp) && $sIp === @\filter_var($sIp, FILTER_VALIDATE_IP);
}
/**
* @return \Net_IDNA2
*/
private static function idn()
private static function idn() : \Net
{
static $oIdn = null;
if (null === $oIdn)
@ -2300,13 +1982,7 @@ END;
return $oIdn;
}
/**
* @param string $sStr
* @param bool $bLowerIfAscii = false
*
* @return string
*/
public static function IdnToUtf8($sStr, $bLowerIfAscii = false)
public static function IdnToUtf8(string $sStr, bool $bLowerIfAscii = false) : string
{
if (0 < \strlen($sStr) && \preg_match('/(^|\.|@)xn--/i', $sStr))
{
@ -2314,19 +1990,13 @@ END;
{
$sStr = self::idn()->decode($sStr);
}
catch (\Exception $oException) {}
catch (\Throwable $oException) {}
}
return $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr;
}
/**
* @param string $sStr
* @param bool $bLowerIfAscii = false
*
* @return string
*/
public static function IdnToAscii($sStr, $bLowerIfAscii = false)
public static function IdnToAscii(string $sStr, bool $bLowerIfAscii = false) : string
{
$sStr = $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr;
@ -2344,19 +2014,13 @@ END;
{
$sDomain = self::idn()->encode($sDomain);
}
catch (\Exception $oException) {}
catch (\Throwable $oException) {}
}
return ('' === $sUser ? '' : $sUser.'@').$sDomain;
}
/**
* @param string $sHash
* @param string $sSalt
*
* @return int
*/
public static function HashToId($sHash, $sSalt = '')
public static function HashToId(string $sHash, string $sSalt = '') : int
{
$sData = $sHash ? @\MailSo\Base\Crypt::XxteaDecrypt(\hex2bin($sHash), \md5($sSalt)) : null;
@ -2369,25 +2033,14 @@ END;
return null;
}
/**
* @param int $iID
* @param string $sSalt
*
* @return string
*/
public static function IdToHash($iID, $sSalt = '')
public static function IdToHash(int $iID, string $sSalt = '') : string
{
return is_int($iID) ?
\bin2hex(\MailSo\Base\Crypt::XxteaEncrypt('id:'.$iID, \md5($sSalt))) : null
;
}
/**
* @param string $sPassword
*
* @return bool
*/
public static function PasswordWeaknessCheck($sPassword)
public static function PasswordWeaknessCheck(string $sPassword) : bool
{
$sPassword = \trim($sPassword);
if (6 > \strlen($sPassword))

View file

@ -17,13 +17,8 @@ namespace MailSo\Base;
*/
class Validator
{
/**
* @param string $sEmail
* @param array $aAllowedInternalDomains = array('localhost')
*
* @return bool
*/
public static function EmailString($sEmail, $aAllowedInternalDomains = array('localhost'))
public static function EmailString(string $sEmail, array $aAllowedInternalDomains = array('localhost')) : bool
{
$bResult = false;
if (\MailSo\Base\Validator::NotEmptyString($sEmail, true))
@ -41,59 +36,31 @@ class Validator
return $bResult;
}
/**
* @param string $sEmail
*
* @return bool
*/
public static function SimpleEmailString($sEmail)
public static function SimpleEmailString(string $sEmail) : bool
{
return \MailSo\Base\Validator::NotEmptyString($sEmail, true) &&
!!\preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\.\+\-_]*@[a-zA-Z0-9][a-zA-Z0-9\.\+\-_]*$/', $sEmail);
}
/**
* @param string $sString
* @param bool $bTrim = false
*
* @return bool
*/
public static function NotEmptyString($sString, $bTrim = false)
public static function NotEmptyString(string $sString, bool $bTrim = false) : bool
{
return \is_string($sString) &&
(0 < \strlen($bTrim ? \trim($sString) : $sString));
}
/**
* @param array $aList
*
* @return bool
*/
public static function NotEmptyArray($aList)
public static function NotEmptyArray(array $aList) : bool
{
return \is_array($aList) && 0 < \count($aList);
}
/**
* @param int $iNumber
* @param int $iMin = null
* @param int $iMax = null
*
* @return bool
*/
public static function RangeInt($iNumber, $iMin = null, $iMax = null)
public static function RangeInt(int $iNumber, int $iMin = null, int $iMax = null) : bool
{
return \is_int($iNumber) &&
(null !== $iMin && $iNumber >= $iMin || null === $iMin) &&
(null !== $iMax && $iNumber <= $iMax || null === $iMax);
}
/**
* @param int $iPort
*
* @return bool
*/
public static function PortInt($iPort)
public static function PortInt(int $iPort) : bool
{
return \MailSo\Base\Validator::RangeInt($iPort, 0, 65535);
}