示例#1
0
 /**
  * @param mixed $mInput
  * @param \MailSo\Log\Logger|null $oLogger = null
  *
  * @return string
  */
 public static function Php2js($mInput, $oLogger = null)
 {
     static $iOpt = null;
     if (null === $iOpt) {
         $iOpt = \defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
     }
     $sResult = @\json_encode($mInput, $iOpt);
     if (!\is_string($sResult) || '' === $sResult) {
         if (!$oLogger && \MailSo\Log\Logger::IsSystemEnabled()) {
             $oLogger = \MailSo\Config::$SystemLogger;
         }
         if (!$oLogger instanceof \MailSo\Log\Logger) {
             $oLogger = null;
         }
         if ($oLogger) {
             $oLogger->Write('json_encode: ' . \trim((\MailSo\Base\Utils::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: ' . \json_last_error() . ']' : '') . (\MailSo\Base\Utils::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: ' . \json_last_error_msg() . ']' : '')), \MailSo\Log\Enumerations\Type::WARNING, 'JSON');
         }
         if (\is_array($mInput)) {
             if ($oLogger) {
                 $oLogger->WriteDump($mInput, \MailSo\Log\Enumerations\Type::INFO, 'JSON');
                 $oLogger->Write('Trying to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
             }
             \MailSo\Base\Utils::ClearArrayUtf8Values($mInput);
             $sResult = @\json_encode($mInput, $iOpt);
         }
     }
     return $sResult;
 }