예제 #1
0
 public function send($errorCode, $data, $more = true, $extra = array(), $execute = true)
 {
     //注意要判断message是否为空。
     $arr = array('errorCode' => (string) $errorCode, 'message' => format($data, $more, $extra));
     $json = CJSON::encode($arr);
     $json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'unescapedUnicode', $json);
     if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android') !== FALSE) {
         header('Content-type:application/json;charset=utf-8');
         if ($execute) {
             exit($json);
         } else {
             echo $json;
         }
     } else {
         if (empty($_SERVER['HTTP_USER_AGENT'])) {
             header('Content-type:application/json;charset=utf-8');
             if ($execute) {
                 exit($json);
             } else {
                 echo $json;
             }
         } else {
             header('Content-type:text/html;charset=utf-8');
             Yii::app()->getController()->jsonText = jsonFormat($json);
         }
     }
 }
예제 #2
0
 public function format($errorCode, $data, $execute = true)
 {
     $this->errorCode = $errorCode;
     if (is_array($data)) {
         foreach ($data as $name => $value) {
             $this->{$name} = $value;
         }
     } else {
         $this->result = $data;
     }
     $this->setProvider();
     $json = CJSON::encode($this->merge());
     $json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'unescapedUnicode', $json);
     $sever = $_SERVER['HTTP_USER_AGENT'];
     if (strpos(strtolower($sever), 'android') !== FALSE || empty($sever)) {
         header('Content-type:application/json;charset=utf-8');
         if ($execute) {
             exit($json);
         }
     } else {
         header('Content-type:text/html;charset=utf-8');
         Yii::app()->getController()->jsonText = jsonFormat($json);
     }
 }
    $apiConfig[$action]['dependencyFields'] = array();
}
// fields generation
foreach ($fields as $fieldName => $fieldInfo) {
    $dependancyArray = createDependencyArray($fieldInfo, $dependencyVariables);
    createAPIConfig($apiConfig, $fieldName, $fieldInfo, $dependancyArray);
}
foreach ($apiConfig as $action => $data) {
    $apiConfig[$action]['dependencies'] = array_values($apiConfig[$action]['dependencies']);
    usort($apiConfig[$action]['columns'], function ($a, $b) {
        return $a['columnPosition'] > $b['columnPosition'];
    });
    //    $apiConfig[$action]['columns'] = array_values($apiConfig[$action]['columns']);
}
$apiConfig['__meta'] = array('comment' => "Generated " . date('Y-m-d') . " with Solr Schema Generator (https://github.com/TomLous/solr-schema-dataimport-generator)");
file_put_contents('target/apiconfig.json', jsonFormat($apiConfig));
// methods
function createAPIConfig(&$conf, $fieldName, $fieldInfo, $dependancyArray)
{
    global $config;
    if (isset($fieldInfo['searchOptions'])) {
        foreach ($dependancyArray as $pos => $dependancyData) {
            $searchActions = $fieldInfo['searchOptions']['searchActions'];
            $returnActions = $fieldInfo['searchOptions']['returnActions'];
            $combinedActions = array_unique(array_merge($searchActions, $returnActions));
            foreach ($fieldInfo['types'] as $fieldNamePostfix => $fieldType) {
                foreach ($combinedActions as $action) {
                    $isSourceField = false;
                    $currentFieldName = $fieldName;
                    if ($fieldNamePostfix == '_') {
                        $isSourceField = true;