本文整理汇总了PHP中FormatJson::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP FormatJson::decode方法的具体用法?PHP FormatJson::decode怎么用?PHP FormatJson::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormatJson
的用法示例。
在下文中一共展示了FormatJson::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $repoDir The root directory of the repo where .git can be found
* @param bool $usePrecomputed Use precomputed information if available
* @see precomputeValues
*/
public function __construct($repoDir, $usePrecomputed = true)
{
$this->cacheFile = self::getCacheFilePath($repoDir);
wfDebugLog('gitinfo', "Computed cacheFile={$this->cacheFile} for {$repoDir}");
if ($usePrecomputed && $this->cacheFile !== null && is_readable($this->cacheFile)) {
$this->cache = FormatJson::decode(file_get_contents($this->cacheFile), true);
wfDebugLog('gitinfo', "Loaded git data from cache for {$repoDir}");
}
if (!$this->cacheIsComplete()) {
wfDebugLog('gitinfo', "Cache incomplete for {$repoDir}");
$this->basedir = $repoDir . DIRECTORY_SEPARATOR . '.git';
if (is_readable($this->basedir) && !is_dir($this->basedir)) {
$GITfile = file_get_contents($this->basedir);
if (strlen($GITfile) > 8 && substr($GITfile, 0, 8) === 'gitdir: ') {
$path = rtrim(substr($GITfile, 8), "\r\n");
if ($path[0] === '/' || substr($path, 1, 1) === ':') {
// Path from GITfile is absolute
$this->basedir = $path;
} else {
$this->basedir = $repoDir . DIRECTORY_SEPARATOR . $path;
}
}
}
}
}
示例2: 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");
}
示例3: execute
public function execute()
{
$params = $this->extractRequestParams();
$this->requireOnlyOneParameter($params, 'vars', 'rcid', 'logid');
// "Anti-DoS"
if (!$this->getUser()->isAllowed('abusefilter-modify')) {
$this->dieUsageMsg('permissiondenied');
}
if ($params['vars']) {
$vars = FormatJson::decode($params['vars'], true);
} elseif ($params['rcid']) {
$dbr = wfGetDB(DB_SLAVE);
$row = $dbr->selectRow('recentchanges', '*', array('rc_id' => $params['rcid']), __METHOD__);
if (!$row) {
$this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
}
$vars = AbuseFilter::getVarsFromRCRow($row);
} elseif ($params['logid']) {
$dbr = wfGetDB(DB_SLAVE);
$row = $dbr->selectRow('abuse_filter_log', '*', array('afl_id' => $params['logid']), __METHOD__);
if (!$row) {
$this->dieUsage("There is no abuselog entry with the id ``{$params['logid']}''", 'nosuchlogid');
}
$vars = AbuseFilter::loadVarDump($row->afl_var_dump);
}
if (AbuseFilter::checkSyntax($params['filter']) !== true) {
$this->dieUsage('The filter has invalid syntax', 'badsyntax');
}
$result = AbuseFilter::checkConditions($params['filter'], $vars);
$this->getResult()->addValue(null, $this->getModuleName(), array('result' => $result));
}
示例4: fetchScriptList
protected function fetchScriptList()
{
$data = ['action' => 'query', 'format' => 'json', 'list' => 'allpages', 'apnamespace' => '8', 'aplimit' => '500', 'continue' => ''];
$baseUrl = $this->getArg(0);
$pages = [];
while (true) {
$url = wfAppendQuery($baseUrl, $data);
$strResult = Http::get($url, [], __METHOD__);
$result = FormatJson::decode($strResult, true);
$page = null;
foreach ($result['query']['allpages'] as $page) {
if (substr($page['title'], -3) === '.js') {
strtok($page['title'], ':');
$pages[] = strtok('');
}
}
if ($page !== null) {
$this->output("Fetched list up to {$page['title']}\n");
}
if (isset($result['continue'])) {
// >= 1.21
$data = array_replace($data, $result['continue']);
} elseif (isset($result['query-continue']['allpages'])) {
// <= 1.20
$data = array_replace($data, $result['query-continue']['allpages']);
} else {
break;
}
}
return $pages;
}
示例5: testPreSaveTransform
/**
* Tests JSON pretty-printing.
* @covers JsonSchemaContent::preSaveTransform
*/
function testPreSaveTransform()
{
$transformed = new JsonSchemaContent(self::VALID_JSON_SCHEMA);
$prettyJson = $transformed->preSaveTransform(new Title(), new User(), new ParserOptions())->getNativeData();
$this->assertContains("\n", $prettyJson, 'Transformed JSON is beautified.');
$this->assertEquals(FormatJson::decode($prettyJson), FormatJson::decode(self::VALID_JSON_SCHEMA), 'Beautification does not alter JSON value.');
}
示例6: execute
public function execute()
{
global $wgUser;
if (!$wgUser->isAllowed('surveysubmit') || $wgUser->isBlocked()) {
$this->dieUsageMsg(array('badaccess-groups'));
}
$params = $this->extractRequestParams();
if (!(isset($params['id']) xor isset($params['name']))) {
$this->dieUsage(wfMsg('survey-err-id-xor-name'), 'id-xor-name');
}
if (isset($params['name'])) {
$survey = Survey::newFromName($params['name'], null, false);
if ($survey === false) {
$this->dieUsage(wfMsgExt('survey-err-survey-name-unknown', 'parsemag', $params['name']), 'survey-name-unknown');
}
} else {
$survey = Survey::newFromId($params['id'], null, false);
if ($survey === false) {
$this->dieUsage(wfMsgExt('survey-err-survey-id-unknown', 'parsemag', $params['id']), 'survey-id-unknown');
}
}
$submission = new SurveySubmission(array('survey_id' => $survey->getId(), 'page_id' => 0, 'user_name' => $GLOBALS['wgUser']->getName(), 'time' => wfTimestampNow()));
foreach (FormatJson::decode($params['answers']) as $answer) {
$submission->addAnswer(SurveyAnswer::newFromArray((array) $answer));
}
$submission->writeToDB();
}
示例7: getUntranslatedPages
protected function getUntranslatedPages($apiUrl, $category, $targetDomain)
{
$this->output("Fetching pages from {$category} not present in {$targetDomain} ...");
$pages = array();
$params = array('action' => 'query', 'format' => 'json', 'generator' => 'categorymembers', 'gcmtitle' => "Category:{$category}", 'gcmnamespace' => 0, 'gcmlimit' => 500, 'gcmsort' => 'timestamp', 'prop' => 'langlinks', 'lllang' => $targetDomain, 'lllimit' => 500, 'continue' => '');
while (true) {
$url = $apiUrl . http_build_query($params);
$json = Http::get($url);
$data = FormatJson::decode($json, true);
if (!isset($data['query'])) {
$this->output("\t[FAIL]\n");
return array();
}
$pagesInCategory = $data['query']['pages'];
foreach ($pagesInCategory as $pageId => $page) {
if (!isset($page['langlinks'])) {
$pages[] = $page['title'];
}
}
if (!isset($data['continue']) || count($pages) > 5000) {
break;
} else {
unset($params['llcontinue']);
unset($params['gcmcontinue']);
$params += $data['continue'];
}
}
$this->output("\t[OK]\n");
return $pages;
}
示例8: execute
public function execute()
{
global $wgUser;
$result = $this->getResult();
$params = $this->extractRequestParams();
$token = array();
if ($wgUser->isAnon()) {
if (!isset($params['anontoken'])) {
$this->dieUsageMsg(array('missingparam', 'anontoken'));
} elseif (strlen($params['anontoken']) != 32) {
$this->dieUsage('The anontoken is not 32 characters', 'invalidtoken');
}
$token = $params['anontoken'];
} else {
$token = '';
}
$dbr = wfGetDB(DB_SLAVE);
$dbw = wfGetDB(DB_MASTER);
// Check if the incoming survey is valid
$surveyCount = $dbr->selectRow('research_tools_surveys', 'rts_id', array('rts_id' => $params['survey']), __METHOD__);
if ($surveyCount === false) {
$this->dieUsage('The survey is unknown', 'invalidsurvey');
}
// Find an existing response from this user for this survey
$response = $dbr->selectRow('research_tools_survey_responses', 'rtsr_id', array('rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
if ($response !== false) {
// Delete any of the previous answers (they questions may have changed)
$dbw->delete('research_tools_survey_answers', array('rtsa_response' => $response->rtsr_id), __METHOD__);
}
// Decode JSON answer data
$answers = FormatJson::decode($params['answers'], true);
if (!is_array($answers)) {
$this->dieUsage('Invalid answer data', 'invalidanswers');
}
// Verify questions exist
foreach ($answers as $question => $answer) {
$question = $dbr->selectRow('research_tools_survey_questions', 'rtsq_id', array('rtsq_survey' => $params['survey'], 'rtsq_id' => $question), __METHOD__);
if ($question === false) {
$this->dieUsage('A question is unknown', 'invalidquestion');
}
}
if ($response === false) {
// Insert a new response row
$dbw->insert('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW), 'rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
$response = $dbw->insertId();
} else {
$response = $response->rtsr_id;
// Update the timestamp of the existing response row
$dbw->update('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW)), array('rtsr_id' => $response), __METHOD__);
}
// Insert answers for the response
$answerRows = array();
foreach ($answers as $question => $answer) {
// Build row data
$answerRows[] = array('rtsa_response' => $response, 'rtsa_question' => $question, 'rtsa_value_integer' => is_numeric($answer) ? intval($answer) : null, 'rtsa_value_text' => is_numeric($answer) ? '' : $answer);
}
$dbw->insert('research_tools_survey_answers', $answerRows, __METHOD__);
// Add success to result
$result->addValue(null, $this->getModuleName(), array('result' => 'Success'));
}
示例9: passCaptcha
/**
* Check, if the user solved the captcha.
*
* Based on reference implementation:
* https://github.com/google/recaptcha#php
*
* @return boolean
*/
function passCaptcha()
{
global $wgRequest, $wgReCaptchaSecretKey, $wgReCaptchaSendRemoteIP;
$url = 'https://www.google.com/recaptcha/api/siteverify';
// Build data to append to request
$data = array('secret' => $wgReCaptchaSecretKey, 'response' => $wgRequest->getVal('g-recaptcha-response'));
if ($wgReCaptchaSendRemoteIP) {
$data['remoteip'] = $wgRequest->getIP();
}
$url = wfAppendQuery($url, $data);
$request = MWHttpRequest::factory($url, array('method' => 'GET'));
$status = $request->execute();
if (!$status->isOK()) {
$this->error = 'http';
$this->logStatusError($status);
return false;
}
$response = FormatJson::decode($request->getContent(), true);
if (!$response) {
$this->error = 'json';
$this->logStatusError($this->error);
return false;
}
if (isset($response['error-codes'])) {
$this->error = 'recaptcha-api';
$this->logCheckError($response['error-codes']);
return false;
}
return $response['success'];
}
示例10: beautifyJSON
/**
* Pretty-print JSON
*
* @return bool|null|string
*/
public function beautifyJSON()
{
$decoded = FormatJson::decode($this->getNativeData(), true);
if (!is_array($decoded)) {
return null;
}
return FormatJson::encode($decoded, true);
}
示例11: newFromJson
/**
* @param string $json JSON representation of the restrictions
* @return MWRestrictions
*/
public static function newFromJson($json)
{
$restrictions = FormatJson::decode($json, true);
if (!is_array($restrictions)) {
throw new InvalidArgumentException('Invalid restrictions JSON');
}
return new self($restrictions);
}
示例12: query
/**
@brief Perform API request and return the resulting structure.
@note If $query contains 'token' => 'null', then 'token'
will be set to the current value of $editToken.
*/
public function query($query)
{
$query['format'] = 'json';
if (array_key_exists('token', $query) && is_null($query['token'])) {
$query['token'] = $this->editToken;
}
$req = $this->t->httpPost($this->apiUrl, $query);
return FormatJson::decode($req->getContent(), true);
}
示例13: parse
public function parse($contents)
{
$messages = FormatJson::decode($contents, true);
unset($messages['@metadata']);
if ($this->code) {
return array($this->code => $messages);
}
// Assuming that the array is keyed by language codes
return $messages;
}
示例14: __construct
/**
* @param object $row bot_passwords database row
* @param bool $isSaved Whether the bot password was read from the database
* @param int $flags IDBAccessObject read flags
*/
protected function __construct($row, $isSaved, $flags = self::READ_NORMAL)
{
$this->isSaved = $isSaved;
$this->flags = $flags;
$this->centralId = (int) $row->bp_user;
$this->appId = $row->bp_app_id;
$this->token = $row->bp_token;
$this->restrictions = MWRestrictions::newFromJson($row->bp_restrictions);
$this->grants = FormatJson::decode($row->bp_grants);
}
示例15: preloadModuleInfo
/**
* Load information stored in the database about modules.
*
* This method grabs modules dependencies from the database and updates modules
* objects.
*
* This is not inside the module code because it is much faster to
* request all of the information at once than it is to have each module
* requests its own information. This sacrifice of modularity yields a substantial
* performance improvement.
*
* @param array $modules List of module names to preload information for
* @param ResourceLoaderContext $context Context to load the information within
*/
public function preloadModuleInfo(array $modules, ResourceLoaderContext $context)
{
if (!count($modules)) {
// Or else Database*::select() will explode, plus it's cheaper!
return;
}
$dbr = wfGetDB(DB_SLAVE);
$skin = $context->getSkin();
$lang = $context->getLanguage();
// Get file dependency information
$res = $dbr->select('module_deps', array('md_module', 'md_deps'), array('md_module' => $modules, 'md_skin' => $skin), __METHOD__);
// Set modules' dependencies
$modulesWithDeps = array();
foreach ($res as $row) {
$module = $this->getModule($row->md_module);
if ($module) {
$module->setFileDependencies($skin, FormatJson::decode($row->md_deps, true));
$modulesWithDeps[] = $row->md_module;
}
}
// Register the absence of a dependency row too
foreach (array_diff($modules, $modulesWithDeps) as $name) {
$module = $this->getModule($name);
if ($module) {
$this->getModule($name)->setFileDependencies($skin, array());
}
}
// Get message blob mtimes. Only do this for modules with messages
$modulesWithMessages = array();
foreach ($modules as $name) {
$module = $this->getModule($name);
if ($module && count($module->getMessages())) {
$modulesWithMessages[] = $name;
}
}
$modulesWithoutMessages = array_flip($modules);
// Will be trimmed down by the loop below
if (count($modulesWithMessages)) {
$res = $dbr->select('msg_resource', array('mr_resource', 'mr_timestamp'), array('mr_resource' => $modulesWithMessages, 'mr_lang' => $lang), __METHOD__);
foreach ($res as $row) {
$module = $this->getModule($row->mr_resource);
if ($module) {
$module->setMsgBlobMtime($lang, wfTimestamp(TS_UNIX, $row->mr_timestamp));
unset($modulesWithoutMessages[$row->mr_resource]);
}
}
}
foreach (array_keys($modulesWithoutMessages) as $name) {
$module = $this->getModule($name);
if ($module) {
$module->setMsgBlobMtime($lang, 0);
}
}
}