public function testParsingARequestWithARelateBody() { // Given... $queryOverrides = ['getContent' => function () { return self::HTTP_PUT_BODY; }]; $request = self::createRequest('/api/v1/users', $queryOverrides, Parser::HTTP_PUT, self::HTTP_PUT_BODY); $action = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\RequestAction', ['name' => RequestAction::ACTION_UPDATE, 'target' => RequestAction::TARGET_RELATIONSHIP]); $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => self::RESOURCE_TYPE, 'action' => $action]); $hydrant = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\ResourceLinksHydrant'); $parser = new BodyParser(self::createJsonCoder(), self::createDocNavigator(), $hydrant, self::createCreationBodyParser(), self::createMutationBodyParser(), self::createLinkingBodyParser(), self::createUnlinkingBodyParser()); // When... $resources = $parser->parse($request, $params); // Then... $this->assertSame(['7' => ['links' => ['user-groups' => []]]], $resources); }
/** * Parsea ciertos parámetros de un pedido de HTTP. * @param Request $request * @throws ResourceNotFoundException * @throws ActionNotAllowedException * @throws ParseException * @throws EntityAccessDeniedException * @throws EntityNotFoundException */ public function parse(Request $request) { $content = $request->getContent(); if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) { throw new ParseException(self::ERROR_CONTENT_ON_DELETE); } $params = new Params(); $params->path = $this->parsePath($request); $params->i18n = $this->parseI18n($request); $params->primaryType = $this->parsePrimaryType($request); $params->primaryClass = $this->getEntityClass($params->primaryType); $params->relationship = $this->parseRelationship($request, $params); $params->primaryIds = $this->parsePrimaryIds($request, $params->relationship); $params->relationshipIds = $this->parseRelationshipIds($request); $params->locale = $this->localeNegotiator->negotiate($request); if (!empty($this->translatableListener) && !empty($params->locale)) { $params->translatable = TRUE; $this->translatableListener->setTranslatableLocale($params->locale); } else { $params->translatable = FALSE; } if ($request->query->has('include')) { $params->include = $this->parseInclude($request); } if ($request->query->has('fields')) { $params->sparseFields = $this->parseSparseFields($request, $params->primaryType); } if ($request->query->has('page')) { $params->pagination = $this->paginationParser->parse($request, $params); } $params->sorting = $this->sortingParser->parse($request, $params); $params->filters = $this->filterParser->parse($request, $params); $params->action = $this->actionParser->parse($request, $params); $params->resourceConfig = $this->resourceEntityMapper->getResourcesConfig()->get($params->primaryType); // Needs the params from the ActionParser. $params->entities = $this->entityFinder->find($params); // Needs the params from the ActionParser (and ParamEntityFinder). $params->resources = $this->bodyParser->parse($request, $params); return $params; }