当前位置: 首页>>代码示例>>PHP>>正文


PHP FireCake::jsonEncode方法代码示例

本文整理汇总了PHP中FireCake::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP FireCake::jsonEncode方法的具体用法?PHP FireCake::jsonEncode怎么用?PHP FireCake::jsonEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FireCake的用法示例。


在下文中一共展示了FireCake::jsonEncode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fb

 /**
  * fb - Send messages with FireCake to FirePHP
  *
  * Much like FirePHP's fb() this method can be called with various parameter counts
  * fb($message) - Just send a message defaults to LOG type
  * fb($message, $type) - Send a message with a specific type
  * fb($message, $label, $type) - Send a message with a custom label and type.
  *
  * @param mixed $message Message to output. For other parameters see usage above.
  * @return boolean Success
  */
 public static function fb($message)
 {
     $_this = FireCake::getInstance();
     if (headers_sent($filename, $linenum)) {
         trigger_error(__d('debug_kit', 'Headers already sent in %s on line %s. Cannot send log data to FirePHP.', $filename, $linenum), E_USER_WARNING);
         return false;
     }
     if (!$_this->_enabled || !$_this->detectClientExtension()) {
         return false;
     }
     $args = func_get_args();
     $type = $label = null;
     switch (count($args)) {
         case 1:
             $type = $_this->_levels['log'];
             break;
         case 2:
             $type = $args[1];
             break;
         case 3:
             $type = $args[2];
             $label = $args[1];
             break;
         default:
             trigger_error(__d('debug_kit', 'Incorrect parameter count for FireCake::fb()'), E_USER_WARNING);
             return false;
     }
     if (isset($_this->_levels[$type])) {
         $type = $_this->_levels[$type];
     } else {
         $type = $_this->_levels['log'];
     }
     $meta = array();
     $skipFinalObjectEncode = false;
     if ($type == $_this->_levels['trace']) {
         $trace = debug_backtrace();
         if (!$trace) {
             return false;
         }
         $message = FireCake::_parseTrace($trace, $args[0]);
         $skipFinalObjectEncode = true;
     }
     if ($_this->options['includeLineNumbers']) {
         if (!isset($meta['file']) || !isset($meta['line'])) {
             $trace = debug_backtrace();
             for ($i = 0, $len = count($trace); $i < $len; $i++) {
                 $keySet = isset($trace[$i]['class']) && isset($trace[$i]['function']);
                 $selfCall = $keySet && strtolower($trace[$i]['class']) == 'firecake' && in_array($trace[$i]['function'], $_this->_methodIndex);
                 if ($selfCall) {
                     $meta['File'] = isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : '';
                     $meta['Line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : '';
                     break;
                 }
             }
         }
     }
     $structureIndex = 1;
     if ($type == $_this->_levels['dump']) {
         $structureIndex = 2;
         $_this->_sendHeader('X-Wf-1-Structure-2', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
     } else {
         $_this->_sendHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
     }
     $_this->_sendHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
     $_this->_sendHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . $_this->_version);
     if ($type == $_this->_levels['groupStart']) {
         $meta['Collapsed'] = 'true';
     }
     if ($type == $_this->_levels['dump']) {
         $dump = FireCake::jsonEncode($message);
         $msg = '{"' . $label . '":' . $dump . '}';
     } else {
         $meta['Type'] = $type;
         if ($label !== null) {
             $meta['Label'] = $label;
         }
         $msg = '[' . $_this->jsonEncode($meta) . ',' . $_this->jsonEncode($message, $skipFinalObjectEncode) . ']';
     }
     $lines = explode("\n", chunk_split($msg, 5000, "\n"));
     foreach ($lines as $i => $line) {
         if (empty($line)) {
             continue;
         }
         $header = 'X-Wf-1-' . $structureIndex . '-1-' . $_this->_messageIndex;
         if (count($lines) > 2) {
             $first = $i == 0 ? strlen($msg) : '';
             $end = $i < count($lines) - 2 ? '\\' : '';
             $message = $first . '|' . $line . '|' . $end;
             $_this->_sendHeader($header, $message);
//.........这里部分代码省略.........
开发者ID:cc2i,项目名称:calibrephp,代码行数:101,代码来源:FireCake.php

示例2: testNonNativeEncoding

 /**
  * test of Non Native JSON encoding.
  *
  * @return void
  */
 public function testNonNativeEncoding()
 {
     FireCake::setOptions(array('useNativeJsonEncode' => false));
     $json = FireCake::jsonEncode(array('one' => 1, 'two' => 2));
     $this->assertEqual($json, '{"one":1,"two":2}');
     $json = FireCake::jsonEncode(array(1, 2, 3));
     $this->assertEqual($json, '[1,2,3]');
     $json = FireCake::jsonEncode(FireCake::getInstance());
     $this->assertPattern('/"options"\\:\\{"maxObjectDepth"\\:\\d*,/', $json);
 }
开发者ID:carriercomm,项目名称:professional-inventory-and-billing-system,代码行数:15,代码来源:FireCakeTest.php


注:本文中的FireCake::jsonEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。