<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\CurlUtil; use ModStart\Core\Util\SerializeUtil; 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($Mczr_) { $this->addVariables(array('jsonMode' => $Mczr_)); return $this; } public function editorHeight($Mczr_) { $this->addVariables(array('editorHeight' => $Mczr_)); return $this; } public function unserializeValue($Mczr_, AbstractField $rZfgs) { if (null === $Mczr_) { return $Mczr_; } return @json_decode($Mczr_, true); } public function serializeValue($Mczr_, $vn_cr) { return SerializeUtil::jsonEncode($Mczr_); } public function prepareInput($Mczr_, $vn_cr) { goto IciMk; IciMk: $mpJUG = @json_decode($Mczr_, true); goto vN7PM; wu2To: return $mpJUG; goto qfOY_; vN7PM: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $Mczr_ && null === $mpJUG); goto wu2To; qfOY_: } public static function executeApi($Mczr_) { goto vV2xU; tSxWO: $Ggr9v['returnHeader'] = true; goto SxSD3; qib7i: if (!empty($Mczr_['query'])) { goto XxN_L; K4ahr: foreach ($Mczr_['query'] as $Xz28r) { $LBO09[$Xz28r['key']] = $Xz28r['value']; } goto jV3a1; jV3a1: $ACVUe = $LBO09; goto SnU1J; XxN_L: $LBO09 = array(); goto K4ahr; SnU1J: } goto L_LGD; fM4vf: if (!empty($Mczr_['headers'])) { foreach ($Mczr_['headers'] as $Xz28r) { $Ggr9v['header'][$Xz28r['key']] = $Xz28r['value']; } } goto qib7i; nInXu: return $ZIe4d; goto G9VN1; HTw7z: $ACVUe = array(); goto ZSonG; S17uj: BizException::throwsIf('method错误', empty($Mczr_['method']) || !in_array($Mczr_['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto zZiFH; L_LGD: switch ($Ggr9v['method']) { case 'POST': switch ($Mczr_['enctype']) { case 'FormData': goto x7jl5; Qxbri: $Ggr9v['header']['Content-Type'] = 'multipart/form-data'; goto KV_jM; KV_jM: break; goto M4UFn; x7jl5: $ACVUe = array(); goto f6cPZ; f6cPZ: if (!empty($Mczr_['bodyParam'])) { foreach ($Mczr_['bodyParam'] as $Xz28r) { $ACVUe[$Xz28r['key']] = $Xz28r['value']; } } goto Qxbri; M4UFn: case 'UrlEncoded': goto d8wc_; AnO55: if (!empty($Mczr_['bodyParam'])) { foreach ($Mczr_['bodyParam'] as $Xz28r) { $ACVUe[$Xz28r['key']] = $Xz28r['value']; } } goto fziHz; DKSGq: break; goto jGSH9; d8wc_: $ACVUe = array(); goto AnO55; fziHz: $Ggr9v['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto DKSGq; jGSH9: case 'Json': goto akXYs; akXYs: $ACVUe = $Mczr_['bodyRaw']; goto Yu_Pk; Yu_Pk: $Ggr9v['header']['Content-Type'] = 'application/json'; goto GghZV; GghZV: break; goto NYtnX; NYtnX: } break; } goto a02K0; OzCw_: $Ggr9v['header'] = array(); goto fM4vf; zZiFH: BizException::throwsIf('enctype错误', empty($Mczr_['enctype']) || !in_array($Mczr_['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto HTw7z; SxSD3: $Ggr9v['method'] = $Mczr_['method']; goto OzCw_; vV2xU: BizException::throwsIf('url为空', empty($Mczr_['url'])); goto S17uj; ZSonG: $Ggr9v = array(); goto tSxWO; a02K0: $ZIe4d = CurlUtil::request($Mczr_['url'], $ACVUe, $Ggr9v); goto nInXu; G9VN1: } }