mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Filter improvements
This commit is contained in:
parent
f91f74fe7c
commit
05b1c1dfe5
14 changed files with 222 additions and 68 deletions
|
|
@ -47,6 +47,11 @@ abstract class Driver
|
|||
*/
|
||||
protected $bTypedPrefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sNewLine;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
@ -79,6 +84,7 @@ abstract class Driver
|
|||
{
|
||||
$this->sDatePattern = 'H:i:s';
|
||||
$this->sName = 'INFO';
|
||||
$this->sNewLine = "\r\n";
|
||||
$this->bTimePrefix = true;
|
||||
$this->bTypedPrefix = true;
|
||||
$this->bGuidPrefix = true;
|
||||
|
|
@ -246,15 +252,44 @@ abstract class Driver
|
|||
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $mDesc
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function localWriteImplementation($mDesc, $bDiplayCrLf = false)
|
||||
{
|
||||
if ($bDiplayCrLf)
|
||||
{
|
||||
if (\is_array($mDesc))
|
||||
{
|
||||
foreach ($mDesc as &$sLine)
|
||||
{
|
||||
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
|
||||
$sLine = \rtrim($mDesc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
|
||||
$mDesc = \rtrim($mDesc);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->writeImplementation($mDesc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @final
|
||||
* @param string $sDesc
|
||||
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||
* @param string $sName = ''
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
|
||||
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bDiplayCrLf = false)
|
||||
{
|
||||
$bResult = true;
|
||||
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
|
||||
|
|
@ -285,18 +320,18 @@ abstract class Driver
|
|||
if (isset($this->aCache[0]) && empty($this->aCache[0]))
|
||||
{
|
||||
$this->aCache[0] = $sFlush;
|
||||
array_unshift($this->aCache, '');
|
||||
\array_unshift($this->aCache, '');
|
||||
}
|
||||
else
|
||||
{
|
||||
array_unshift($this->aCache, $sFlush);
|
||||
\array_unshift($this->aCache, $sFlush);
|
||||
}
|
||||
|
||||
$this->aCache[] = '--- FlushLogCache: Trigger';
|
||||
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
|
||||
|
||||
$this->bFlushCache = true;
|
||||
$bResult = $this->writeImplementation($this->aCache);
|
||||
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
|
||||
$this->aCache = array();
|
||||
}
|
||||
else if (0 < $this->iWriteOnTimeoutOnly && \time() - APP_START_TIME > $this->iWriteOnTimeoutOnly)
|
||||
|
|
@ -305,18 +340,18 @@ abstract class Driver
|
|||
if (isset($this->aCache[0]) && empty($this->aCache[0]))
|
||||
{
|
||||
$this->aCache[0] = $sFlush;
|
||||
array_unshift($this->aCache, '');
|
||||
\array_unshift($this->aCache, '');
|
||||
}
|
||||
else
|
||||
{
|
||||
array_unshift($this->aCache, $sFlush);
|
||||
\array_unshift($this->aCache, $sFlush);
|
||||
}
|
||||
|
||||
$this->aCache[] = '--- FlushLogCache: Trigger';
|
||||
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
|
||||
|
||||
$this->bFlushCache = true;
|
||||
$bResult = $this->writeImplementation($this->aCache);
|
||||
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
|
||||
$this->aCache = array();
|
||||
}
|
||||
else
|
||||
|
|
@ -326,13 +361,21 @@ abstract class Driver
|
|||
}
|
||||
else
|
||||
{
|
||||
$bResult = $this->writeImplementation(
|
||||
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName));
|
||||
$bResult = $this->localWriteImplementation(
|
||||
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName), $bDiplayCrLf);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetNewLine()
|
||||
{
|
||||
return $this->sNewLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @final
|
||||
* @return bool
|
||||
|
|
|
|||
|
|
@ -23,23 +23,18 @@ class File extends \MailSo\Log\Driver
|
|||
*/
|
||||
private $sLoggerFileName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sCrLf;
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*
|
||||
* @param string $sLoggerFileName
|
||||
* @param string $sCrLf = "\r\n"
|
||||
* @param string $sNewLine = "\r\n"
|
||||
*/
|
||||
protected function __construct($sLoggerFileName, $sCrLf = "\r\n")
|
||||
protected function __construct($sLoggerFileName, $sNewLine = "\r\n")
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->sLoggerFileName = $sLoggerFileName;
|
||||
$this->sCrLf = $sCrLf;
|
||||
$this->sNewLine = $sNewLine;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,13 +47,13 @@ class File extends \MailSo\Log\Driver
|
|||
|
||||
/**
|
||||
* @param string $sLoggerFileName
|
||||
* @param string $sCrLf = "\r\n"
|
||||
* @param string $sNewLine = "\r\n"
|
||||
*
|
||||
* @return \MailSo\Log\Drivers\File
|
||||
*/
|
||||
public static function NewInstance($sLoggerFileName, $sCrLf = "\r\n")
|
||||
public static function NewInstance($sLoggerFileName, $sNewLine = "\r\n")
|
||||
{
|
||||
return new self($sLoggerFileName, $sCrLf);
|
||||
return new self($sLoggerFileName, $sNewLine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,11 +81,11 @@ class File extends \MailSo\Log\Driver
|
|||
*/
|
||||
private function writeToLogFile($mDesc)
|
||||
{
|
||||
if (is_array($mDesc))
|
||||
if (\is_array($mDesc))
|
||||
{
|
||||
$mDesc = \implode($this->sCrLf, $mDesc);
|
||||
$mDesc = \implode($this->sNewLine, $mDesc);
|
||||
}
|
||||
|
||||
return \error_log($mDesc.$this->sCrLf, 3, $this->sLoggerFileName);
|
||||
|
||||
return \error_log($mDesc.$this->sNewLine, 3, $this->sLoggerFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ namespace MailSo\Log\Drivers;
|
|||
*/
|
||||
class Inline extends \MailSo\Log\Driver
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sNewLine;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -296,11 +296,13 @@ class Logger extends \MailSo\Base\Collection
|
|||
* @param string $sDesc
|
||||
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||
* @param string $sName = ''
|
||||
* @param bool $bSearchWords = false
|
||||
* @param bool $bSearchSecretWords = true
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchWords = false)
|
||||
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO,
|
||||
$sName = '', $bSearchSecretWords = true, $bDiplayCrLf = false)
|
||||
{
|
||||
if (isset($this->aForbiddenTypes[$iType]) && true === $this->aForbiddenTypes[$iType])
|
||||
{
|
||||
|
|
@ -313,7 +315,7 @@ class Logger extends \MailSo\Base\Collection
|
|||
$aLoggers = array();
|
||||
$iResult = 1;
|
||||
|
||||
if ($bSearchWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
|
||||
if ($bSearchSecretWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
|
||||
{
|
||||
$sDesc = \str_replace($this->aSecretWords, '*******', $sDesc);
|
||||
}
|
||||
|
|
@ -321,7 +323,7 @@ class Logger extends \MailSo\Base\Collection
|
|||
$aLoggers =& $this->GetAsArray();
|
||||
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
|
||||
{
|
||||
$iResult &= $oLogger->Write($sDesc, $iType, $sName);
|
||||
$iResult &= $oLogger->Write($sDesc, $iType, $sName, $bDiplayCrLf);
|
||||
}
|
||||
|
||||
return (bool) $iResult;
|
||||
|
|
@ -332,12 +334,14 @@ class Logger extends \MailSo\Base\Collection
|
|||
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||
* @param string $sName = ''
|
||||
* @param bool $bSearchSecretWords = false
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchSecretWords = false)
|
||||
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '',
|
||||
$bSearchSecretWords = false, $bDiplayCrLf = false)
|
||||
{
|
||||
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords);
|
||||
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -345,10 +349,12 @@ class Logger extends \MailSo\Base\Collection
|
|||
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
|
||||
* @param string $sName = ''
|
||||
* @param bool $bSearchSecretWords = true
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '', $bSearchSecretWords = true)
|
||||
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
|
||||
$bSearchSecretWords = true, $bDiplayCrLf = false)
|
||||
{
|
||||
if ($oException instanceof \Exception)
|
||||
{
|
||||
|
|
@ -359,7 +365,7 @@ class Logger extends \MailSo\Base\Collection
|
|||
|
||||
$oException->__LOGINNED__ = true;
|
||||
|
||||
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords);
|
||||
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -370,10 +376,12 @@ class Logger extends \MailSo\Base\Collection
|
|||
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
|
||||
* @param string $sName = ''
|
||||
* @param bool $bSearchSecretWords = true
|
||||
* @param bool $bDiplayCrLf = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function WriteMixed($mData, $iType = null, $sName = '', $bSearchSecretWords = true)
|
||||
public function WriteMixed($mData, $iType = null, $sName = '',
|
||||
$bSearchSecretWords = true, $bDiplayCrLf = false)
|
||||
{
|
||||
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::INFO : $iType;
|
||||
if (\is_array($mData) || \is_object($mData))
|
||||
|
|
@ -381,16 +389,16 @@ class Logger extends \MailSo\Base\Collection
|
|||
if ($mData instanceof \Exception)
|
||||
{
|
||||
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
|
||||
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords);
|
||||
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords);
|
||||
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->Write($mData, $iType, $sName, $bSearchSecretWords);
|
||||
return $this->Write($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -557,11 +557,11 @@ abstract class NetClient
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function writeLog($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO)
|
||||
protected function writeLog($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO, $bDiplayCrLf = false)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write($sDesc, $iDescType, $this->getLogName());
|
||||
$this->oLogger->Write($sDesc, $iDescType, $this->getLogName(), true, $bDiplayCrLf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -573,7 +573,7 @@ abstract class NetClient
|
|||
*/
|
||||
protected function writeLogWithCrlf($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO)
|
||||
{
|
||||
$this->writeLog(\strtr($sDesc, array("\r" => '\r', "\n" => '\n')), $iDescType);
|
||||
$this->writeLog($sDesc, $iDescType, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue