Inheritance: implements JsonSerializabl\JsonSerializable, use trait LinksTrait, use trait MetaTrait
コード例 #1
0
ファイル: StatusJsonResponder.php プロジェクト: keeko/auth
 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);
 }
コード例 #2
0
ファイル: LoginJsonResponder.php プロジェクト: keeko/auth
 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);
 }
コード例 #3
0
ファイル: ErrorHandler.php プロジェクト: clops/core
 /**
  * @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());
 }
コード例 #4
0
ファイル: HandleErrors.php プロジェクト: RudolfFussek/core
 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);
 }
コード例 #5
0
 /**
  * @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']]);
 }
コード例 #6
0
ファイル: DocumentTest.php プロジェクト: ahsanity/json-api
 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());
 }
コード例 #7
0
ファイル: DocumentTest.php プロジェクト: redstarxz/flarumone
 public function testToArrayIncludesTheResourcesRepresentation()
 {
     $resource = new Resource('post', 1);
     $document = new Document();
     $document->setData($resource);
     $this->assertEquals(['data' => $resource->toArray()], $document->toArray());
 }
コード例 #8
0
ファイル: JsonApiResponse.php プロジェクト: flarum/core
 /**
  * {@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);
 }
コード例 #9
0
 /**
  * @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;
 }
コード例 #10
0
 /**
  * @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);
 }
コード例 #11
0
 /**
  * @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);
 }
コード例 #12
0
 /**
  * @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);
 }
コード例 #13
0
 /** @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);
     }
 }
コード例 #14
0
 /**
  * @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);
 }
コード例 #15
0
 /**
  * @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);
 }
コード例 #16
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = FunctionPhase::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['root-skills', 'skill']));
     $resource = $resource->fields($params->getFields(['function-phase' => FunctionPhase::getSerializer()->getFields(), 'root-skill' => Skill::getSerializer()->getFields(), 'skill' => Skill::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #17
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Competition::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['startgroups']));
     $resource = $resource->fields($params->getFields(['competition' => Competition::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #18
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Localization::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['localizations', 'parent', 'language', 'ext-lang', 'script', 'language-variants', 'application-uris']));
     $resource = $resource->fields($params->getFields(['localization' => Localization::getSerializer()->getFields(), 'parent' => Localization::getSerializer()->getFields(), 'language' => Language::getSerializer()->getFields(), 'ext-lang' => Language::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'language-variant' => LanguageVariant::getSerializer()->getFields(), 'application-uri' => ApplicationUri::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #19
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = PerformanceScore::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['routine', 'judge']));
     $resource = $resource->fields($params->getFields(['performance-score' => PerformanceScore::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #20
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = RegionType::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['countries', 'subdivisions', 'area']));
     $resource = $resource->fields($params->getFields(['region-type' => RegionType::getSerializer()->getFields(), 'country' => Country::getSerializer()->getFields(), 'subdivision' => Subdivision::getSerializer()->getFields(), 'area' => RegionArea::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #21
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Application::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['application-uris']));
     $resource = $resource->fields($params->getFields(['application' => Application::getSerializer()->getFields(), 'application-uri' => ApplicationUri::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #22
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Startgroup::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['competition', 'event', 'performance-total-statistic', 'performance-execution-statistic', 'performance-choreography-statistic', 'performance-music-and-timing-statistic', 'routines', 'judges', 'routines.performance-total-statistic', 'routines.performance-execution-statistic', 'routines.performance-choreography-statistic', 'routines.performance-music-and-timing-statistic', 'routines.performance-scores', 'routines.performance-scores.judge']));
     $resource = $resource->fields($params->getFields(['startgroup' => Startgroup::getSerializer()->getFields(), 'competition' => Competition::getSerializer()->getFields(), 'event' => Event::getSerializer()->getFields(), 'performance-total-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-execution-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-choreography-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-music-and-timing-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #23
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = LanguageVariant::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['localizations']));
     $resource = $resource->fields($params->getFields(['language-variant' => LanguageVariant::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #24
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Skill::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sport', 'variations', 'variation-of', 'multiples', 'multiple-of', 'object', 'start-position', 'end-position', 'featured-picture', 'featured-video', 'featured-tutorial', 'kstruktur-root', 'function-phase-root', 'children', 'parents', 'parts', 'composites', 'groups', 'references', 'lineages', 'pictures', 'videos', 'kstrukturs', 'function-phases', 'sport.skills']));
     $resource = $resource->fields($params->getFields(['skill' => Skill::getSerializer()->getFields(), 'sport' => Sport::getSerializer()->getFields(), 'variation' => Skill::getSerializer()->getFields(), 'variation-of' => Skill::getSerializer()->getFields(), 'multiple' => Skill::getSerializer()->getFields(), 'multiple-of' => Skill::getSerializer()->getFields(), 'object' => Object::getSerializer()->getFields(), 'start-position' => Position::getSerializer()->getFields(), 'end-position' => Position::getSerializer()->getFields(), 'featured-picture' => Picture::getSerializer()->getFields(), 'featured-video' => Video::getSerializer()->getFields(), 'featured-tutorial' => Video::getSerializer()->getFields(), 'kstruktur-root' => Kstruktur::getSerializer()->getFields(), 'function-phase-root' => FunctionPhase::getSerializer()->getFields(), 'child' => Skill::getSerializer()->getFields(), 'parent' => Skill::getSerializer()->getFields(), 'part' => Skill::getSerializer()->getFields(), 'composite' => Skill::getSerializer()->getFields(), 'group' => Group::getSerializer()->getFields(), 'reference' => Reference::getSerializer()->getFields(), 'lineage' => Lineage::getSerializer()->getFields(), 'picture' => Picture::getSerializer()->getFields(), 'video' => Video::getSerializer()->getFields(), 'kstruktur' => Kstruktur::getSerializer()->getFields(), 'function-phase' => FunctionPhase::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #25
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Reference::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['videos', 'skills']));
     $resource = $resource->fields($params->getFields(['reference' => Reference::getSerializer()->getFields(), 'video' => Video::getSerializer()->getFields(), 'skill' => Skill::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #26
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = User::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sessions', 'groups', 'activities']));
     $resource = $resource->fields($params->getFields(['user' => User::getSerializer()->getFields(), 'session' => Session::getSerializer()->getFields(), 'group' => Group::getSerializer()->getFields(), 'activity' => Activity::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #27
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = ActivityObject::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['activities']));
     $resource = $resource->fields($params->getFields(['activity-object' => ActivityObject::getSerializer()->getFields(), 'activity' => Activity::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #28
0
ファイル: JudgeReadJsonResponder.php プロジェクト: iuf/junia
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Judge::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['startgroup', 'user', 'performance-score']));
     $resource = $resource->fields($params->getFields(['judge' => Judge::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'performance-score' => PerformanceScore::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #29
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Preference::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude([]));
     $resource = $resource->fields($params->getFields(['preference' => Preference::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #30
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Routine::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['startgroup', 'performance-total-statistic', 'performance-execution-statistic', 'performance-choreography-statistic', 'performance-music-and-timing-statistic', 'performance-scores']));
     $resource = $resource->fields($params->getFields(['routine' => Routine::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'performance-total-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-execution-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-choreography-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-music-and-timing-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-score' => PerformanceScore::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }