本文整理汇总了PHP中phootwork\json\Json::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::decode方法的具体用法?PHP Json::decode怎么用?PHP Json::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phootwork\json\Json
的用法示例。
在下文中一共展示了Json::decode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->extensions = new Map();
$this->packages = new Map();
// load up all extensions
$exts = ExtensionQuery::create()->joinPackage()->find();
foreach ($exts as $ext) {
/* @var $ext Extension */
$key = $ext->getKey();
$packageName = $ext->getPackage()->getName();
$data = Json::decode($ext->getData());
// add to global extensions
if (!$this->extensions->has($key)) {
$this->extensions->set($key, new ArrayList());
}
$this->extensions->get($key)->add($data);
// add to package extensions
if (!$this->packages->has($packageName)) {
$this->packages->set($packageName, new Map());
}
$pkg = $this->packages->get($packageName);
if (!$pkg->has($key)) {
$pkg->set($key, new ArrayList());
}
$pkg->get($key)->add($data);
}
}
示例2: load
/**
* {@inheritDoc}
* @see \Symfony\Component\Translation\Loader\LoaderInterface::load()
*/
public function load($resource, $locale, $domain = 'messages')
{
$repo = $this->service->getResourceRepository();
if (!$repo->contains($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
// find file in puli repo
$file = $repo->get($resource);
$json = $file->getBody();
$data = Json::decode($json);
$messages = [];
// flatten plural strings
foreach ($data as $key => $value) {
if (is_array($value)) {
$vals = [];
foreach ($value as $k => $v) {
$vals[] = sprintf('%s: %s', $k, $v);
}
$val = implode('|', $vals);
} else {
$val = $value;
}
$messages[$key] = str_replace(['{{', '}}'], '%', $val);
}
// put them into message catalog
$catalogue = new MessageCatalogue($locale);
$catalogue->add($messages, $domain);
return $catalogue;
}
示例3: fileToArray
private function fileToArray($filename)
{
$file = new File($filename);
if (!$file->exists()) {
throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
}
return Json::decode($file->read());
}
示例4: fromFile
/**
*
* @param string $filename
* @throws FileNotFoundException
* @throws JsonException
* @return static
*/
public static function fromFile($filename)
{
$file = new File($filename);
if (!$file->exists()) {
throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
}
$json = Json::decode($file->read());
return new static($json);
}
示例5: getJson
/**
*
* @param BodyResource $file
* @return array
*/
private function getJson(BodyResource $file)
{
$config = Json::decode($file->getBody());
// fix version
if (!isset($config['version'])) {
$config['version'] = 'dev-master';
}
return $config;
}
示例6: run
/**
* Automatically generated method, will be overridden
*
* @param Request $request
* @return Response
*/
public function run(Request $request)
{
$json = Json::decode($request->getContent());
$path = new JSONPath($json);
$login = $path->find('$.data.attributes.login')->first();
$password = $path->find('$.data.attributes.password')->first();
$domain = new SessionDomain($this->getServiceContainer());
$payload = $domain->login($login, $password);
return $this->responder->run($request, $payload);
}
示例7: run
/**
* Automatically generated run method
*
* @param Request $request
* @return Response
*/
public function run(Request $request)
{
$body = Json::decode($request->getContent());
if (!isset($body['data'])) {
throw new InvalidParameterException();
}
$data = $body['data'];
$domain = new JudgeDomain($this->getServiceContainer());
$payload = $domain->create($data);
return $this->responder->run($request, $payload);
}
示例8: run
/**
* Automatically generated run method
*
* @param Request $request
* @return Response
*/
public function run(Request $request)
{
$body = Json::decode($request->getContent());
if (!isset($body['data'])) {
throw new InvalidParameterException();
}
$data = $body['data'];
$id = $this->getParam('id');
$domain = new StartgroupDomain($this->getServiceContainer());
$payload = $domain->setCompetitionId($id, $data);
return $this->responder->run($request, $payload);
}
示例9: run
/**
* Automatically generated run method
*
* @param Request $request
* @return Response
*/
public function run(Request $request)
{
$body = Json::decode($request->getContent());
if (!isset($body['data'])) {
throw new InvalidParameterException();
}
$data = $body['data'];
$id = $this->getParam('id');
$domain = new LocalizationDomain($this->getServiceContainer());
$payload = $domain->updateLanguageVariant($id, $data);
return $this->responder->run($request, $payload);
}
示例10: run
/**
* Automatically generated run method
*
* @param Request $request
* @return Response
*/
public function run(Request $request)
{
$body = Json::decode($request->getContent());
if (!isset($body['data'])) {
throw new InvalidParameterException();
}
$data = $body['data'];
$id = $this->getParam('id');
$domain = new RoutineDomain($this->getServiceContainer());
$payload = $domain->setPerformanceChoreographyStatisticId($id, $data);
return $this->responder->run($request, $payload);
}
示例11: updateApi
private function updateApi(Module $model, ModuleSchema $module, $actions)
{
$repo = $this->service->getResourceRepository();
$filename = sprintf('/packages/%s/api.json', $model->getName());
if (!$repo->contains($filename)) {
return;
}
// delete every api existent for the given module prior to create the new ones
ApiQuery::create()->filterByActionId(array_values($actions))->delete();
// $extensions = $this->service->getExtensionRegistry()->getExtensionsByPackage('keeko.api', $model->getName());
$json = Json::decode($repo->get($filename)->getBody());
$swagger = new Swagger($json);
foreach ($swagger->getPaths() as $path) {
/* @var $path Path */
foreach (Swagger::$METHODS as $method) {
if ($path->hasOperation($method)) {
$op = $path->getOperation($method);
$actionName = $op->getOperationId();
if (!isset($actions[$actionName])) {
continue;
}
// find required parameters
$required = [];
foreach ($op->getParameters() as $param) {
/* @var $param Parameter */
if ($param->getIn() == 'path' && $param->getRequired()) {
$required[] = $param->getName();
}
}
// $prefix = isset($extensions[$actionName])
// ? $extensions[$actionName]
// : $module->getSlug();
$prefix = $module->getSlug();
$fullPath = str_replace('//', '/', $prefix . '/' . $path->getPath());
$api = new Api();
$api->setMethod($method);
$api->setRoute($fullPath);
$api->setActionId($actions[$actionName]);
$api->setRequiredParams(implode(',', $required));
$api->save();
}
}
}
$model->setApi(true);
$model->save();
}
示例12: loadModules
private function loadModules()
{
if (!empty($this->modules)) {
return $this->modules;
}
$modules = [];
$models = ModuleQuery::create()->filterByApi(true)->find();
$repo = $this->service->getResourceRepository();
foreach ($models as $model) {
$package = $this->service->getPackageManager()->getPackage($model->getName());
$filename = sprintf('/packages/%s/api.json', $model->getName());
if ($repo->contains($filename)) {
$routes = [];
$json = Json::decode($repo->get($filename)->getBody());
$swagger = new Swagger($json);
foreach ($swagger->getPaths() as $path) {
/* @var $path Path */
foreach (Swagger::$METHODS as $method) {
if ($path->hasOperation($method)) {
$op = $path->getOperation($method);
$actionName = $op->getOperationId();
$routes[str_replace('-', '_', $actionName)] = ['method' => $method, 'path' => $path->getPath()];
}
}
}
$modules[] = ['title' => $model->getTitle(), 'slug' => $package->getKeeko()->getModule()->getSlug(), 'model' => $model, 'routes' => $routes];
}
}
$this->modules = $modules;
return $modules;
}
示例13: testDecodeBrokenStackDepth
/**
*
* @expectedException \phootwork\json\JsonException
* @expectedExceptionCode \phootwork\json\Json::ERROR_DEPTH
*/
public function testDecodeBrokenStackDepth()
{
$json = json_encode([1 => ['English' => ['One', 'January'], 'French' => ['Une', 'Janvier']]]);
Json::decode($json, 0, 3);
}