<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\CurlUtil; class Json extends AbstractField { const MODE_API = 'api'; const MODE_DEFAULT = 'default'; protected function setup() { $this->addVariables(array('editorHeight' => '200px', 'jsonMode' => 'default')); } public function jsonMode($ib3B9) { $this->addVariables(array('jsonMode' => $ib3B9)); return $this; } public function editorHeight($ib3B9) { $this->addVariables(array('editorHeight' => $ib3B9)); return $this; } public function unserializeValue($ib3B9, AbstractField $pu1ro) { if (null === $ib3B9) { return $ib3B9; } return @json_decode($ib3B9, true); } public function serializeValue($ib3B9, $nzuw7) { return json_encode($ib3B9, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function prepareInput($ib3B9, $nzuw7) { goto ZdtOC; ARL0Q: return $xoOBk; goto DfD4A; VxLY6: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $ib3B9 && null === $xoOBk); goto ARL0Q; ZdtOC: $xoOBk = @json_decode($ib3B9, true); goto VxLY6; DfD4A: } public static function executeApi($ib3B9) { goto PnShp; LTj4x: $c3D3W['header'] = array(); goto xEFS9; ZVz2C: $c3D3W = array(); goto lZMpW; J8AIK: switch ($c3D3W['method']) { case 'POST': switch ($ib3B9['enctype']) { case 'FormData': goto V1K_u; eQr7e: $c3D3W['header']['Content-Type'] = 'multipart/form-data'; goto BkJuy; V1K_u: $pmJAc = array(); goto athyj; BkJuy: break; goto OUN0H; athyj: if (!empty($ib3B9['bodyParam'])) { foreach ($ib3B9['bodyParam'] as $JiRHR) { $pmJAc[$JiRHR['key']] = $JiRHR['value']; } } goto eQr7e; OUN0H: case 'UrlEncoded': goto bXZDP; VNHLn: if (!empty($ib3B9['bodyParam'])) { foreach ($ib3B9['bodyParam'] as $JiRHR) { $pmJAc[$JiRHR['key']] = $JiRHR['value']; } } goto kctDa; kctDa: $c3D3W['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto bNQLW; bXZDP: $pmJAc = array(); goto VNHLn; bNQLW: break; goto k8PWT; k8PWT: case 'Json': goto WxJHO; WxJHO: $pmJAc = $ib3B9['bodyRaw']; goto upR7l; JtrbQ: break; goto rAqCx; upR7l: $c3D3W['header']['Content-Type'] = 'application/json'; goto JtrbQ; rAqCx: } break; } goto Fqt29; BdydO: BizException::throwsIf('method错误', empty($ib3B9['method']) || !in_array($ib3B9['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto NCDsm; NCDsm: BizException::throwsIf('enctype错误', empty($ib3B9['enctype']) || !in_array($ib3B9['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto pUyto; xEFS9: if (!empty($ib3B9['headers'])) { foreach ($ib3B9['headers'] as $JiRHR) { $c3D3W['header'][$JiRHR['key']] = $JiRHR['value']; } } goto kx04p; ij8zn: return $gbVzz; goto h7OuD; pUyto: $pmJAc = array(); goto ZVz2C; Fqt29: $gbVzz = CurlUtil::request($ib3B9['url'], $pmJAc, $c3D3W); goto ij8zn; lZMpW: $c3D3W['returnHeader'] = true; goto BjdFW; BjdFW: $c3D3W['method'] = $ib3B9['method']; goto LTj4x; kx04p: if (!empty($ib3B9['query'])) { goto lDJWd; iUqGl: $pmJAc = $xaAIg; goto PjuPT; QQDrh: foreach ($ib3B9['query'] as $JiRHR) { $xaAIg[$JiRHR['key']] = $JiRHR['value']; } goto iUqGl; lDJWd: $xaAIg = array(); goto QQDrh; PjuPT: } goto J8AIK; PnShp: BizException::throwsIf('url为空', empty($ib3B9['url'])); goto BdydO; h7OuD: } }