本文整理汇总了PHP中CM_Util::jsonDecode方法的典型用法代码示例。如果您正苦于以下问题:PHP CM_Util::jsonDecode方法的具体用法?PHP CM_Util::jsonDecode怎么用?PHP CM_Util::jsonDecode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CM_Util
的用法示例。
在下文中一共展示了CM_Util::jsonDecode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setConfig
/**
* @param string $filename
* @param string $configJson
* @param bool|null $merge
*/
public function setConfig($filename, $configJson, $merge = null)
{
$merge = (bool) $merge;
$configJson = (object) CM_Util::jsonDecode($configJson);
$configFile = new CM_File(DIR_ROOT . 'resources/config/' . $filename . '.php');
$config = new CM_Config_Node();
if ($merge && $configFile->exists()) {
$config->extendWithFile($configFile);
}
$config->extendWithConfig($configJson);
$configStr = $config->exportAsString('$config');
$indentation = ' ';
$indent = function ($content) use($indentation) {
return preg_replace('/(:?^|[\\n])/', '$1' . $indentation, $content);
};
$configFile->ensureParentDirectory();
$configFile->write(join(PHP_EOL, ['<?php', '// This is autogenerated config file. You should not change it manually.', '', 'return function (CM_Config_Node $config) {', $indent($configStr), '};', '']));
$this->_getStreamOutput()->writeln('Created `' . $configFile->getPath() . '`');
}
示例2: jsonDecode
/**
* @param string $value
* @return mixed
* @throws CM_Exception_Invalid
*/
public static function jsonDecode($value)
{
return CM_Util::jsonDecode($value);
}
示例3: fromJson
/**
* @param string $conversionJson
* @return CMService_AdWords_Conversion
*/
public static function fromJson($conversionJson)
{
$conversionJson = (string) $conversionJson;
return self::fromArray(CM_Util::jsonDecode($conversionJson));
}
示例4: testJsonDecodeInvalid
/**
* @expectedException CM_Exception_Invalid
*/
public function testJsonDecodeInvalid()
{
CM_Util::jsonDecode('{[foo:bar)}');
}
示例5: decodeField
/**
* @param string $key
* @param mixed $value
* @return mixed
* @throws CM_Exception_Invalid
* @throws CM_Model_Exception_Validation
*/
public function decodeField($key, $value)
{
$key = (string) $key;
if ($this->hasField($key)) {
$schemaField = $this->_schema[$key];
if (null !== $value) {
$type = isset($schemaField['type']) ? $schemaField['type'] : null;
if (null !== $type) {
switch ($type) {
case 'integer':
case 'int':
$value = (int) $value;
break;
case 'float':
$value = (double) $value;
break;
case 'string':
$value = (string) $value;
break;
case 'boolean':
case 'bool':
$value = (bool) $value;
break;
case 'array':
break;
case 'DateTime':
$value = DateTime::createFromFormat('U', $value);
break;
default:
if (!class_exists($type)) {
throw new CM_Model_Exception_Validation('Field type is not a valid class/interface', null, ['type' => $type]);
}
$className = $type;
if (is_a($className, 'CM_Model_Abstract', true)) {
/** @var CM_Model_Abstract $type */
if ($this->_isJson($value)) {
$value = CM_Util::jsonDecode($value);
}
$id = $value;
if (!is_array($id)) {
$id = ['id' => $id];
}
$value = CM_Model_Abstract::factoryGeneric($type::getTypeStatic(), $id);
} elseif (is_subclass_of($className, 'CM_ArrayConvertible', true)) {
/** @var CM_ArrayConvertible $className */
$value = CM_Util::jsonDecode($value);
$value = $className::fromArray($value);
} else {
throw new CM_Model_Exception_Validation('Class is neither CM_Model_Abstract nor CM_ArrayConvertible', null, ['className' => $className]);
}
if (!$value instanceof $className) {
throw new CM_Model_Exception_Validation('Value is not an instance of the class', null, ['value' => CM_Util::var_line($value), 'className' => $className]);
}
}
}
}
}
return $value;
}