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


PHP JsonApi\Document类代码示例

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


在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: found

 protected function found(Request $request, Found $payload)
 {
     $serializer = new AuthSessionSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:keeko,项目名称:auth,代码行数:7,代码来源:StatusJsonResponder.php

示例2: success

 protected function success(Request $request, Success $payload)
 {
     $serializer = new AuthSessionSerializer();
     $resource = new Resource($payload->get('session'), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201);
 }
开发者ID:keeko,项目名称:auth,代码行数:7,代码来源:LoginJsonResponder.php

示例3: handle

 /**
  * @param Exception $e
  * @return JsonApiResponse
  */
 public function handle(Exception $e)
 {
     $response = $this->errorHandler->handle($e);
     $document = new Document();
     $document->setErrors($response->getErrors());
     return new JsonApiResponse($document, $response->getStatus());
 }
开发者ID:clops,项目名称:core,代码行数:11,代码来源:ErrorHandler.php

示例4: handle

 public function handle(Exception $e)
 {
     if ($e instanceof JsonApiSerializableInterface) {
         $status = $e->getStatusCode();
         $errors = $e->getErrors();
     } elseif ($e instanceof ValidationException) {
         $status = 422;
         $errors = $e->errors()->toArray();
         $errors = array_map(function ($field, $messages) {
             return ['detail' => implode("\n", $messages), 'source' => ['pointer' => '/data/attributes/' . $field]];
         }, array_keys($errors), $errors);
     } elseif ($e instanceof ModelNotFoundException) {
         $status = 404;
         $errors = [];
     } else {
         $status = 500;
         $error = ['code' => $status, 'title' => 'Internal Server Error'];
         if ($this->app->inDebugMode()) {
             $error['detail'] = (string) $e;
         }
         $errors = [$error];
     }
     $document = new Document();
     $document->setErrors($errors);
     return new JsonApiResponse($document, $status);
 }
开发者ID:RudolfFussek,项目名称:core,代码行数:26,代码来源:HandleErrors.php

示例5: created

 /**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = PerformanceStatistic::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]);
 }
开发者ID:iuf,项目名称:junia,代码行数:11,代码来源:PerformanceStatisticCreateJsonResponder.php

示例6: testToArrayIncludesTheResourcesRepresentation

 public function testToArrayIncludesTheResourcesRepresentation()
 {
     $post = (object) ['id' => 1, 'foo' => 'bar'];
     $resource = new Resource($post, new PostSerializer2());
     $document = new Document($resource);
     $this->assertEquals(['data' => $resource->toArray()], $document->toArray());
 }
开发者ID:ahsanity,项目名称:json-api,代码行数:7,代码来源:DocumentTest.php

示例7: testToArrayIncludesTheResourcesRepresentation

 public function testToArrayIncludesTheResourcesRepresentation()
 {
     $resource = new Resource('post', 1);
     $document = new Document();
     $document->setData($resource);
     $this->assertEquals(['data' => $resource->toArray()], $document->toArray());
 }
开发者ID:redstarxz,项目名称:flarumone,代码行数:7,代码来源:DocumentTest.php

示例8: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct(Document $document, $status = 200, array $headers = [], $encodingOptions = 15)
 {
     $headers['content-type'] = 'application/vnd.api+json';
     // The call to jsonSerialize prevents rare issues with json_encode() failing with a
     // syntax error even though Document implements the JsonSerializable interface.
     // See https://github.com/flarum/core/issues/685
     parent::__construct($document->jsonSerialize(), $status, $headers, $encodingOptions);
 }
开发者ID:flarum,项目名称:core,代码行数:11,代码来源:JsonApiResponse.php

示例9: search

 /**
  * @param string $status
  * @param string $title
  * @param string $description
  * @param string $type
  * @param string $priority
  *
  * @return Document
  */
 public function search($status = null, $title = null, $description = null, $type = null, $priority = null)
 {
     $results = $this->service->search($status, $title, $description, $type, $priority);
     $collection = (new Collection($results, $this->serializer))->with(['author', 'comments']);
     $document = new Document($collection);
     $document->addMeta('total', count($results));
     return $document;
 }
开发者ID:kleijnweb,项目名称:swagger-bundle-example,代码行数:17,代码来源:TicketController.php

示例10: found

 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Language::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sublanguages', 'parent', 'scope', 'type', 'script', 'family', 'localizations']));
     $resource = $resource->fields($params->getFields(['language' => Language::getSerializer()->getFields(), 'sublanguage' => Language::getSerializer()->getFields(), 'parent' => Language::getSerializer()->getFields(), 'scope' => LanguageScope::getSerializer()->getFields(), 'type' => LanguageType::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'family' => LanguageFamily::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:keeko,项目名称:core,代码行数:14,代码来源:LanguageReadJsonResponder.php

示例11: found

 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = PerformanceStatistic::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['events', 'startgroups', 'routine']));
     $resource = $resource->fields($params->getFields(['performance-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'event' => Event::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:iuf,项目名称:junia,代码行数:14,代码来源:PerformanceStatisticReadJsonResponder.php

示例12: updated

 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Position::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sport', 'skill']));
     $resource = $resource->fields($params->getFields(['position' => Position::getSerializer()->getFields(), 'sport' => Sport::getSerializer()->getFields(), 'skill' => Skill::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:gossi,项目名称:trixionary,代码行数:14,代码来源:PositionUpdateJsonResponder.php

示例13: generateMetaData

 /** @return  void */
 protected function generateMetaData(ResponseInterface $response, Document $document)
 {
     if (is_null($this->metaDataGenerator)) {
         return;
     }
     $metaData = call_user_func($this->metaDataGenerator, $response);
     foreach ($metaData as $key => $value) {
         $document->addMeta($key, $value);
     }
 }
开发者ID:WebspotCode,项目名称:SpotApi,代码行数:11,代码来源:AbstractSerializingGenerator.php

示例14: found

 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Object::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sport', 'skills', 'skills.variations', 'skills.variationOf', 'skills.multiples', 'sport.objects']));
     $resource = $resource->fields($params->getFields(['object' => Object::getSerializer()->getFields(), 'sport' => Sport::getSerializer()->getFields(), 'skill' => Skill::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:gossi,项目名称:trixionary,代码行数:14,代码来源:ObjectReadJsonResponder.php

示例15: updated

 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Sport::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['objects', 'positions', 'skills', 'groups', 'skills.groups', 'skills.objects', 'skills.start-position', 'skills.end-position', 'skills.variationOf', 'skills.parents', 'skills.lineages', 'skills.lineages.ancestor', 'skills.lineages.skill', 'skills.featured-picture']));
     $resource = $resource->fields($params->getFields(['sport' => Sport::getSerializer()->getFields(), 'object' => Object::getSerializer()->getFields(), 'position' => Position::getSerializer()->getFields(), 'skill' => Skill::getSerializer()->getFields(), 'group' => Group::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
开发者ID:gossi,项目名称:trixionary,代码行数:14,代码来源:SportUpdateJsonResponder.php


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