public function testParsingARequestWithSorting()
 {
     /* Given... (Fixture) */
     $mm = self::createMetadataMiner();
     $has = function ($param) {
         return 'sort' == $param;
     };
     $get = function () {
         return 'surname,name,-registered-date';
     };
     $queryOverrides = ['has' => $has, 'get' => $get];
     $request = self::createRequest('/users', $queryOverrides);
     $params = self::createParams();
     $parser = new SortingParser($mm);
     /* When... (Action) */
     $actual = $parser->parse($request, $params);
     /* Then... (Assertions) */
     $expected = ['field' => ['users' => ['surname' => 'ASC', 'name' => 'ASC', 'registeredDate' => 'DESC']]];
     $this->assertSame($expected, $actual);
 }
Exemple #2
0
 /**
  * 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;
 }