当前位置: 首页>>代码示例>>PHP>>正文


PHP json\Json类代码示例

本文整理汇总了PHP中phootwork\json\Json的典型用法代码示例。如果您正苦于以下问题:PHP Json类的具体用法?PHP Json怎么用?PHP Json使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
     }
 }
开发者ID:keeko,项目名称:framework,代码行数:27,代码来源:ExtensionRegistry.php

示例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;
 }
开发者ID:keeko,项目名称:framework,代码行数:33,代码来源:KeekoJsonTranslationLoader.php

示例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());
 }
开发者ID:gossi,项目名称:swagger,代码行数:8,代码来源:KeekoTest.php

示例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);
 }
开发者ID:keeko,项目名称:framework,代码行数:16,代码来源:RootSchema.php

示例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;
 }
开发者ID:keeko,项目名称:framework,代码行数:14,代码来源:PackageManager.php

示例6: testComplex

 public function testComplex()
 {
     $data = ['a' => 1, 'b' => [1, 2, 4], 'c' => 3, 'd' => 4, 'e' => 5];
     $json = Json::encode($data);
     $map = Json::toMap($json);
     $this->assertTrue($map instanceof Map);
     $this->assertTrue($map->get('b') instanceof ArrayList);
     $this->assertEquals($data, $map->toArray());
 }
开发者ID:phootwork,项目名称:json,代码行数:9,代码来源:CollectionTest.php

示例7: 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);
 }
开发者ID:keeko,项目名称:auth,代码行数:16,代码来源:LoginAction.php

示例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'];
     $domain = new JudgeDomain($this->getServiceContainer());
     $payload = $domain->create($data);
     return $this->responder->run($request, $payload);
 }
开发者ID:iuf,项目名称:junia,代码行数:17,代码来源:JudgeCreateAction.php

示例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 RoutineDomain($this->getServiceContainer());
     $payload = $domain->setPerformanceChoreographyStatisticId($id, $data);
     return $this->responder->run($request, $payload);
 }
开发者ID:iuf,项目名称:junia,代码行数:18,代码来源:RoutinePerformanceChoreographyStatisticUpdateAction.php

示例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 StartgroupDomain($this->getServiceContainer());
     $payload = $domain->setCompetitionId($id, $data);
     return $this->responder->run($request, $payload);
 }
开发者ID:iuf,项目名称:junia,代码行数:18,代码来源:StartgroupCompetitionUpdateAction.php

示例11: 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);
 }
开发者ID:keeko,项目名称:core,代码行数:18,代码来源:LocalizationLanguageVariantUpdateAction.php

示例12: updateExtensions

 protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg)
 {
     // remove all existing extensions from this package first
     ExtensionQuery::create()->filterByPackage($model)->delete();
     // add them one by one
     foreach ($pkg->getAllExtensions() as $key => $exts) {
         foreach ($exts as $data) {
             $ext = new Extension();
             $ext->setKey($key);
             $ext->setData(Json::encode($data, Json::UNESCAPED_SLASHES));
             $ext->setPackage($model);
             $ext->save();
         }
     }
 }
开发者ID:keeko,项目名称:framework,代码行数:15,代码来源:AbstractPackageInstaller.php

示例13: run

 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $url = str_replace($request->getRequestUri(), '', $request->getUri());
     $baseurl = str_replace($url, '', $this->getBaseUrl());
     $sport = SportQuery::create()->findOneById($this->getParam('sport'));
     if (!$sport->getIsDefault()) {
         $baseurl .= '/' . $sport->getSlug();
     }
     // load assets
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $repo = $this->getServiceContainer()->getResourceRepository();
     $page->addStyles($repo->find('/gossi/trixionary-client/public/app/assets/*.css')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/vendor-*.js')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/trixionary-*.js')->getPaths());
     // set configuration
     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
     $config = ['modulePrefix' => 'trixionary', 'environment' => 'production', 'rootURL' => $baseurl, 'locationType' => 'auto', 'APP' => ['name' => 'trixionary', 'version' => '0.0.0+0d11dfba'], 'keeko' => ['api' => $prefs->getApiUrl(), 'trixionary' => ['sportId' => $sport->getId(), 'slug' => ['skill' => $sport->getSkillSlug(), 'group' => $sport->getGroupSlug(), 'object' => $sport->getObjectSlug()]]]];
     $meta = new Meta();
     $meta->setName('trixionary/config/environment');
     $meta->setContent(rawurlencode(Json::encode($config)));
     $page->addMeta($meta);
     return $this->responder->run($request, new Blank(['sport' => $sport]));
 }
开发者ID:gossi,项目名称:trixionary-client,代码行数:29,代码来源:SportAction.php

示例14: 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();
 }
开发者ID:keeko,项目名称:framework,代码行数:46,代码来源:ModuleInstaller.php

示例15: 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);
 }
开发者ID:phootwork,项目名称:json,代码行数:10,代码来源:JsonTest.php


注:本文中的phootwork\json\Json类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。