예제 #1
0
파일: Utils.php 프로젝트: pigi72333/MailSo
 /**
  * @param mixed $mInput
  *
  * @return string
  */
 public static function Php2js($mInput)
 {
     return \json_encode($mInput, defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0);
     if (\is_null($mInput)) {
         return 'null';
     } else {
         if ($mInput === false) {
             return 'false';
         } else {
             if ($mInput === true) {
                 return 'true';
             } else {
                 if (\is_scalar($mInput)) {
                     if (\is_float($mInput)) {
                         $mInput = \str_replace(',', '.', \strval($mInput));
                     }
                     return '"' . \MailSo\Base\Utils::InlineRebuildStringToJsString($mInput) . '"';
                 }
             }
         }
     }
     $bIsList = true;
     for ($iIndex = 0, \reset($mInput), $iLen = \count($mInput); $iIndex < $iLen; $iIndex++, \next($mInput)) {
         if (\key($mInput) !== $iIndex) {
             $bIsList = false;
             break;
         }
     }
     $aResult = array();
     if ($bIsList) {
         foreach ($mInput as $mValue) {
             $aResult[] = \MailSo\Base\Utils::Php2js($mValue);
         }
         return '[' . \join(',', $aResult) . ']';
     } else {
         foreach ($mInput as $sKey => $mValue) {
             $aResult[] = \MailSo\Base\Utils::Php2js($sKey) . ':' . \MailSo\Base\Utils::Php2js($mValue);
         }
         return '{' . \join(',', $aResult) . '}';
     }
 }