eZ\Publish\Core\REST\Common\Input\ParserTools::parseDefaultSortOrder PHP Méthode

parseDefaultSortOrder() public méthode

Parses the default sort order from the given $defaultSortOrderString.
public parseDefaultSortOrder ( string $defaultSortOrderString ) : integer
$defaultSortOrderString string
Résultat integer
    public function parseDefaultSortOrder($defaultSortOrderString)
    {
        switch (strtoupper($defaultSortOrderString)) {
            case 'ASC':
                return Values\Content\Location::SORT_ORDER_ASC;
            case 'DESC':
                return Values\Content\Location::SORT_ORDER_DESC;
        }
        throw new \RuntimeException("Unknown default sort order: '{$defaultSortOrderString}'.");
    }

Usage Example

 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) {
         throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate.");
     }
     if (!array_key_exists('_href', $data['ParentLocation'])) {
         throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate.");
     }
     $locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath'));
     $locationCreateStruct = $this->locationService->newLocationCreateStruct(array_pop($locationHrefParts));
     if (array_key_exists('priority', $data)) {
         $locationCreateStruct->priority = (int) $data['priority'];
     }
     if (array_key_exists('hidden', $data)) {
         $locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']);
     }
     if (array_key_exists('remoteId', $data)) {
         $locationCreateStruct->remoteId = $data['remoteId'];
     }
     if (!array_key_exists('sortField', $data)) {
         throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate.");
     }
     $locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
     if (!array_key_exists('sortOrder', $data)) {
         throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate.");
     }
     $locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
     return $locationCreateStruct;
 }
All Usage Examples Of eZ\Publish\Core\REST\Common\Input\ParserTools::parseDefaultSortOrder