本文整理汇总了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);
}
}
示例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: 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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
}
示例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]));
}
示例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();
}
示例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);
}