本文整理汇总了PHP中FormatJson::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP FormatJson::encode方法的具体用法?PHP FormatJson::encode怎么用?PHP FormatJson::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormatJson
的用法示例。
在下文中一共展示了FormatJson::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormatOutput
/**
* Prepare data output
*
* @since 1.8
*
* @param array $data label => value
*/
protected function getFormatOutput(array $data)
{
static $statNr = 0;
$chartID = 'jqplot-' . $this->params['charttype'] . '-' . ++$statNr;
$this->isHTML = true;
// Prepare data objects
if (in_array($this->params['charttype'], array('bar', 'line'))) {
// Parse bar relevant data
$dataObject = $this->prepareBarData($data);
} elseif (in_array($this->params['charttype'], array('pie', 'donut'))) {
//Parse pie/donut relevant data
$dataObject = $this->preparePieData($data);
} else {
// Return with an error
return Html::rawElement('span', array('class' => "error"), wfMessage('srf-error-missing-layout')->inContentLanguage()->text());
}
// Encode data objects
$requireHeadItem = array($chartID => FormatJson::encode($dataObject));
SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem));
// Processing placeholder
$processing = SRFUtils::htmlProcessingElement($this->isHTML);
// Ensure right conversion
$width = strstr($this->params['width'], "%") ? $this->params['width'] : $this->params['width'] . 'px';
// Chart/graph placeholder
$chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none; width: {$width}; height: {$this->params['height']}px;"), null);
// Beautify class selector
$class = $this->params['charttype'] ? '-' . $this->params['charttype'] : '';
$class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class . ' jqplot-common';
// Chart/graph wrappper
return Html::rawElement('div', array('class' => 'srf-jqplot' . $class), $processing . $chart);
}
示例2: execute
public function execute()
{
$variantLangs = array();
$variants = array();
foreach (LanguageConverter::$languagesWithVariants as $langCode) {
$lang = Language::factory($langCode);
if (count($lang->getVariants()) > 1) {
$variants += array_flip($lang->getVariants());
$variantLangs[$langCode] = $lang->getVariants();
}
}
$variants = array_keys($variants);
sort($variants);
$result = $this->hasOption('flat') ? $variants : $variantLangs;
// Not using $this->output() because muting makes no sense here
if ($this->hasOption('json')) {
echo FormatJson::encode($result, true) . "\n";
} else {
foreach ($result as $key => $value) {
if (is_array($value)) {
echo "{$key}\n";
foreach ($value as $variant) {
echo " {$variant}\n";
}
} else {
echo "{$value}\n";
}
}
}
}
示例3: getFormatOutput
/**
* Prepare data output
*
* @since 1.8
*
* @param array $data label => value
*/
protected function getFormatOutput(array $data)
{
//Init
$dataObject = array();
static $statNr = 0;
$chartID = 'sparkline-' . $this->params['charttype'] . '-' . ++$statNr;
$this->isHTML = true;
// Prepare data array
foreach ($data as $key => $value) {
if ($value >= $this->params['min']) {
$dataObject['label'][] = $key;
$dataObject['value'][] = $value;
}
}
$dataObject['charttype'] = $this->params['charttype'];
// Encode data objects
$requireHeadItem = array($chartID => FormatJson::encode($dataObject));
SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem));
// RL module
SMWOutputs::requireResource('ext.srf.sparkline');
// Processing placeholder
$processing = SRFUtils::htmlProcessingElement(false);
// Chart/graph placeholder
$chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none;"), null);
// Beautify class selector
$class = $this->params['class'] ? ' ' . $this->params['class'] : '';
// Chart/graph wrappper
return Html::rawElement('span', array('class' => 'srf-sparkline' . $class), $processing . $chart);
}
示例4: execute
/**
* @return string
*/
public function execute()
{
$r = $this->parent->request;
if ($r->wasPosted()) {
if ($this->submit()) {
return 'continue';
}
}
$this->startForm();
// Encourage people to not name their site 'MediaWiki' by blanking the
// field. I think that was the intent with the original $GLOBALS['wgSitename']
// but these two always were the same so had the effect of making the
// installer forget $wgSitename when navigating back to this page.
if ($this->getVar('wgSitename') == 'MediaWiki') {
$this->setVar('wgSitename', '');
}
// Set wgMetaNamespace to something valid before we show the form.
// $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
$metaNS = $this->getVar('wgMetaNamespace');
$this->setVar('wgMetaNamespace', wfMessage('config-ns-other-default')->inContentLanguage()->text());
$pingbackInfo = (new Pingback())->getSystemInfo();
// Database isn't available in config yet, so take it
// from the installer
$pingbackInfo['database'] = $this->getVar('wgDBtype');
$this->addHTML($this->parent->getTextBox(['var' => 'wgSitename', 'label' => 'config-site-name', 'help' => $this->parent->getHelpBox('config-site-name-help')]) . $this->parent->getRadioSet(['var' => '_NamespaceType', 'label' => 'config-project-namespace', 'itemLabelPrefix' => 'config-ns-', 'values' => ['site-name', 'generic', 'other'], 'commonAttribs' => ['class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace'], 'help' => $this->parent->getHelpBox('config-project-namespace-help')]) . $this->parent->getTextBox(['var' => 'wgMetaNamespace', 'label' => '', 'attribs' => ['readonly' => 'readonly', 'class' => 'enabledByOther']]) . $this->getFieldsetStart('config-admin-box') . $this->parent->getTextBox(['var' => '_AdminName', 'label' => 'config-admin-name', 'help' => $this->parent->getHelpBox('config-admin-help')]) . $this->parent->getPasswordBox(['var' => '_AdminPassword', 'label' => 'config-admin-password']) . $this->parent->getPasswordBox(['var' => '_AdminPasswordConfirm', 'label' => 'config-admin-password-confirm']) . $this->parent->getTextBox(['var' => '_AdminEmail', 'attribs' => ['dir' => 'ltr'], 'label' => 'config-admin-email', 'help' => $this->parent->getHelpBox('config-admin-email-help')]) . $this->parent->getCheckBox(['var' => '_Subscribe', 'label' => 'config-subscribe', 'help' => $this->parent->getHelpBox('config-subscribe-help')]) . $this->parent->getCheckBox(['var' => 'wgPingback', 'label' => 'config-pingback', 'help' => $this->parent->getHelpBox('config-pingback-help', FormatJson::encode($pingbackInfo, true)), 'value' => true]) . $this->getFieldsetEnd() . $this->parent->getInfoBox(wfMessage('config-almost-done')->text()) . $this->parent->getRadioSet(['var' => '_SkipOptional', 'itemLabelPrefix' => 'config-optional-', 'values' => ['continue', 'skip']]));
// Restore the default value
$this->setVar('wgMetaNamespace', $metaNS);
$this->endForm();
return 'output';
}
示例5: execute
public function execute()
{
global $wgCommandLineMode;
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
} elseif ($procs != 1) {
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
}
$outputJSON = $this->getOption('result') === 'json';
// Enable DBO_TRX for atomicity; JobRunner manages transactions
// and works well in web server mode already (@TODO: this is a hack)
$wgCommandLineMode = false;
$runner = new JobRunner(LoggerFactory::getInstance('runJobs'));
if (!$outputJSON) {
$runner->setDebugHandler(array($this, 'debugInternal'));
}
$response = $runner->run(array('type' => $this->getOption('type', false), 'maxJobs' => $this->getOption('maxjobs', false), 'maxTime' => $this->getOption('maxtime', false), 'throttle' => $this->hasOption('nothrottle') ? false : true));
if ($outputJSON) {
$this->output(FormatJson::encode($response, true));
}
$wgCommandLineMode = true;
}
示例6: execute
public function execute()
{
if (wfReadOnly()) {
$this->error("Unable to run jobs; the wiki is in read-only mode.", 1);
// die
}
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
} elseif ($procs != 1) {
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
}
$json = $this->getOption('result') === 'json';
$runner = new JobRunner();
if (!$json) {
$runner->setDebugHandler(array($this, 'debugInternal'));
}
$response = $runner->run(array('type' => $this->getOption('type', false), 'maxJobs' => $this->getOption('maxjobs', false), 'maxTime' => $this->getOption('maxtime', false), 'throttle' => $this->hasOption('nothrottle') ? false : true));
if ($json) {
$this->output(FormatJson::encode($response, true));
}
}
示例7: execute
public function execute()
{
$res = array();
foreach (explode(' ', $this->getOption('settings')) as $name) {
if (!preg_match('/^wg[A-Z]/', $name)) {
throw new MWException("Variable '{$name}' does start with 'wg'.");
} elseif (!isset($GLOBALS[$name])) {
throw new MWException("Variable '{$name}' is not set.");
} elseif (!$this->isAllowedVariable($GLOBALS[$name])) {
throw new MWException("Variable '{$name}' includes non-array, non-scalar, items.");
}
$res[$name] = $GLOBALS[$name];
}
$out = null;
switch ($this->getOption('format')) {
case 'PHP':
$out = serialize($res);
break;
case 'JSON':
$out = FormatJson::encode($res);
break;
default:
throw new MWException("Invalid serialization format given.");
}
if (!is_string($out)) {
throw new MWException("Failed to serialize the requested settings.");
}
$this->output($out . "\n");
}
示例8: makeMemberList
/**
* @param $username string
* @return CollaborationListContent
*/
public static function makeMemberList($username, $initialDescription)
{
$linkToUserpage = Title::makeTitleSafe(NS_USER, $username)->getPrefixedText();
$newMemberList = ["displaymode" => "members", "columns" => [["items" => [["title" => $linkToUserpage]]]], "options" => ["mode" => "normal"], "description" => "{$initialDescription}"];
$newMemberListJson = FormatJson::encode($newMemberList, "\t", FormatJson::ALL_OK);
return new CollaborationListContent($newMemberListJson);
}
开发者ID:wikimedia,项目名称:mediawiki-extensions-CollaborationKit,代码行数:11,代码来源:CollaborationListContentHandler.php
示例9: testFillParserOutput
/**
* @dataProvider provideDataAndParserText
*/
public function testFillParserOutput($data, $expected)
{
$obj = new JsonContent(FormatJson::encode($data));
$parserOutput = $obj->getParserOutput($this->getMockTitle(), null, null, true);
$this->assertInstanceOf('ParserOutput', $parserOutput);
$this->assertEquals($expected, $parserOutput->getText());
}
示例10: getFormatOutput
/**
* @see SMWResultPrinter::getFormatOutput
*
* @since 1.8
*
* @param array $data label => value
* @return string
*/
protected function getFormatOutput(array $data)
{
// Object count
static $statNr = 0;
$d3chartID = 'd3-chart-' . ++$statNr;
$this->isHTML = true;
// Reorganize the raw data
foreach ($data as $name => $value) {
if ($value >= $this->params['min']) {
$dataObject[] = array('label' => $name, 'value' => $value);
}
}
// Ensure right conversion
$width = strstr($this->params['width'], "%") ? $this->params['width'] : $this->params['width'] . 'px';
// Prepare transfer objects
$d3data = array('data' => $dataObject, 'parameters' => array('colorscheme' => $this->params['colorscheme'] ? $this->params['colorscheme'] : null, 'charttitle' => $this->params['charttitle'], 'charttext' => $this->params['charttext'], 'datalabels' => $this->params['datalabels']));
// Encoding
$requireHeadItem = array($d3chartID => FormatJson::encode($d3data));
SMWOutputs::requireHeadItem($d3chartID, Skin::makeVariablesScript($requireHeadItem));
// RL module
$resource = 'ext.srf.d3.chart.' . $this->params['charttype'];
SMWOutputs::requireResource($resource);
// Chart/graph placeholder
$chart = Html::rawElement('div', array('id' => $d3chartID, 'class' => 'container', 'style' => 'display:none;'), null);
// Processing placeholder
$processing = SRFUtils::htmlProcessingElement($this->isHTML);
// Beautify class selector
$class = $this->params['charttype'] ? '-' . $this->params['charttype'] : '';
$class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class . ' d3-chart-common';
// D3 wrappper
return Html::rawElement('div', array('class' => 'srf-d3-chart' . $class, 'style' => "width:{$width}; height:{$this->params['height']}px;"), $processing . $chart);
}
示例11: execute
public function execute()
{
$filename = $this->getArg(0);
if (!is_readable($filename)) {
$this->error("Error: Unable to read {$filename}", 1);
}
$json = FormatJson::decode(file_get_contents($filename), true);
if ($json === null) {
$this->error("Error: Invalid JSON", 1);
}
if (!isset($json['manifest_version'])) {
$json['manifest_version'] = 1;
}
if ($json['manifest_version'] == ExtensionRegistry::MANIFEST_VERSION) {
$this->output("Already at the latest version: {$json['manifest_version']}\n");
return;
}
while ($json['manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION) {
$json['manifest_version'] += 1;
$func = "updateTo{$json['manifest_version']}";
$this->{$func}($json);
}
file_put_contents($filename, FormatJson::encode($json, "\t", FormatJson::ALL_OK) . "\n");
$this->output("Updated to {$json['manifest_version']}...\n");
}
示例12: testParseGeocoderCircle
public function testParseGeocoderCircle()
{
global $egMultiMaps_AllowGeocoderTests;
if (!$egMultiMaps_AllowGeocoderTests) {
return;
}
$this->assertRegExp('{"circles":\\[{"radius":\\[[0-9\\.]+\\],"pos":\\[{"lat":[0-9\\.]+,"lon":[0-9\\.]+}\\]}\\],"bounds":{"ne":{"lat":[0-9\\.]+,"lon":[0-9\\.]+},"sw":{"lat":[0-9\\.]+,"lon":[0-9\\.]+}}}', \FormatJson::encode($this->object->getMapData(array('circle=Moscow', 'service=google'))));
}
示例13: testGetTourNames
public function testGetTourNames()
{
$this->assertSame(array(), GuidedTourHooks::getTourNames(null), 'Returns empty array for null parameter');
$this->assertSame(array('test'), GuidedTourHooks::getTourNames(FormatJson::encode(array('version' => 1, 'tours' => array('test' => array('step' => 3))))), 'Valid JSON cookie with a single tour is parsed correctly');
$this->assertSame(array('firsttour', 'secondtour', 'thirdtour'), GuidedTourHooks::getTourNames(FormatJson::encode(array('version' => 1, 'tours' => array('firsttour' => array('step' => 4), 'secondtour' => array('step' => 2), 'thirdtour' => array('step' => 3, 'firstArticleId' => 38333))))), 'Valid JSON cookie with multiple tours is parsed correctly');
$this->assertSame(array(), GuidedTourHooks::getTourNames('{"bad": "cookie"}'), 'Valid JSON with missing tours field returns empty array');
$this->assertSame(array(), GuidedTourHooks::getTourNames('<invalid: JSON>'), 'Invalid JSON returns empty array');
}
示例14: beforePageDisplay
/**
* BeforePageDisplay hook
*
* Adds the modules to the page
*
* @param $out OutputPage output page
* @param $skin Skin current skin
*/
public static function beforePageDisplay( $out, $skin ) {
$title = $out->getTitle();
if( $title->isSpecial( 'Preferences' ) ) {
$out->addModules('ext.tzpicker');
$out->addInlineScript("window.mw_ext_tzpicker_ZoneInfo=" .
FormatJson::encode(self::zoneInfo()));
}
return true;
}
示例15: addJSLocalisation
/**
* Adds the needed JS messages to the page output.
* This is for backward compatibility with pre-RL MediaWiki.
*
* @since 0.1
*/
protected static function addJSLocalisation()
{
global $egLTJSMessages, $wgOut;
$data = array();
foreach ($egLTJSMessages as $msg) {
$data[$msg] = wfMsgNoTrans($msg);
}
$wgOut->addInlineScript('var wgLTEMessages = ' . FormatJson::encode($data) . ';');
}