本文整理汇总了PHP中JSON::translateObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::translateObjects方法的具体用法?PHP JSON::translateObjects怎么用?PHP JSON::translateObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSON
的用法示例。
在下文中一共展示了JSON::translateObjects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeToStream
public static function writeToStream($stream, $records, $columns = '*')
{
if (!is_array($records)) {
throw new Exception('fromRecords expects an array');
} elseif (empty($records)) {
return 'No data';
}
if (is_string($columns) && $columns != '*') {
$columns = explode(',', $columns);
}
$firstRecord = $records[0];
if (is_array($firstRecord)) {
$columnNames = array_keys($firstRecord);
$columnNames = array_combine($columnNames, $columnNames);
} else {
$dynamicFields = $firstRecord->aggregateStackedConfig('dynamicFields');
$fields = $firstRecord->aggregateStackedConfig('fields');
$columnNames = array_merge(array_keys($fields), array_keys($dynamicFields));
$columnNames = array_combine($columnNames, $columnNames);
foreach ($columnNames as &$columnName) {
$dynamicField = $dynamicFields[$columnName];
$field = $fields[$columnName];
if ($dynamicField && !empty($dynamicField['label'])) {
$columnName = $dynamicField['label'];
} elseif ($field && !empty($field['label'])) {
$columnName = $field['label'];
}
}
}
fputcsv($stream, static::getColumns($columnNames, $columns));
foreach ($records as $record) {
fputcsv($stream, static::getColumns(is_array($record) ? $record : JSON::translateObjects($record, false, $columns, true), $columns));
}
}
示例2: Dwoo_Plugin_template_variables
function Dwoo_Plugin_template_variables(Dwoo_Core $dwoo, $format = 'json')
{
if ($format == 'json') {
return json_encode(JSON::translateObjects($dwoo->data));
} else {
throw new Exception('Unsupported $format for template_variables');
}
}
示例3: Dwoo_Plugin_jscout
function Dwoo_Plugin_jscout(Dwoo $dwoo, $lib = '/jslib', $use = array(), $debug = false, $writeTemplateVars = false, $useReady = false)
{
// process lib
if (empty($lib) || $lib[0] != '/') {
throw new Exception('jscout loader: lib must be an absolute http path from the server root starting with /');
} else {
$lib = explode('/', trim($lib, '/'));
}
// process use
if (is_string($use)) {
$use = preg_split('/\\s*,\\s*/', $use);
}
if (!is_array($use)) {
throw new Exception('jscout loader: use must be array or comma-delimited string');
}
// allow override of debug via GET/POST
if (!empty($_REQUEST['jsdebug'])) {
$debug = true;
}
// ext3 source
$return = '<script src="/jslib/ext3/adapter/ext/ext-base' . ($debug ? '-debug' : '') . '.js"></script>' . PHP_EOL;
$return .= '<script src="/jslib/ext3/ext-all' . ($debug ? '-debug' : '') . '.js"></script>' . PHP_EOL;
// jScout source
$return .= '<script src="/jslib/jScout.js"></script>' . PHP_EOL;
// Ext and jScout setup
$return .= '<script>' . PHP_EOL;
$return .= 'Ext.BLANK_IMAGE_URL="/jslib/ext3/resources/images/default/s.gif";' . PHP_EOL;
$return .= 'jScout.libRoot=' . json_encode($lib) . ';' . PHP_EOL;
$return .= "jScout.use('MICS',function(){\n\t";
$return .= "\tMICS.SessionCookie = \"" . addslashes(Session::$cookieName) . "\";\n";
$return .= "\tMICS.SiteName = \"" . addslashes(Site::$Title) . "\";\n";
$return .= "\tMICS.User = " . json_encode($_SESSION['User'] ? $_SESSION['User']->getData() : false) . ";\n";
if ($writeTemplateVars) {
$return .= ' MICS.responseVars=' . json_encode(JSON::translateObjects($dwoo->data)) . ";\n";
}
if (!empty($use)) {
if (empty($useReady)) {
$return .= 'jScout.use(' . json_encode($use) . ');' . PHP_EOL;
} else {
$return .= 'jScout.use(' . json_encode($use) . ', function() {' . $useReady . '});' . PHP_EOL;
}
}
$return .= "});";
$return .= '</script>' . PHP_EOL;
// ext3 stylesheet
$return .= '<link rel="stylesheet" type="text/css" href="/jslib/ext3/resources/css/ext-all.css" />' . PHP_EOL;
return $return;
}
示例4: getData
public function getData()
{
return array_merge(parent::getData(), array('items' => array_values(JSON::translateObjects($this->Items)), 'tags' => array_values(JSON::translateObjects($this->Tags)), 'Author' => $this->Author ? $this->Author->getData() : null));
}
示例5: translateAndRespond
public static function translateAndRespond($data)
{
static::respond(JSON::translateObjects($data));
}