function testConstruct() { // Initialize $sLabel = 'label_test'; $sValue = 'value_test'; // Create sorter criterias $oSorterCriteria1 = new SorterCriteria($sLabel, $sValue); $oSorterCriteria2 = new SorterCriteria('-' . $sLabel, $sValue); // Assert $this->assertEquals(SorterDirection::ASC, $oSorterCriteria1->getDirection()); $this->assertEquals($sValue . ' ASC', $oSorterCriteria1->getQueryString()); $this->assertEquals(SorterDirection::DESC, $oSorterCriteria2->getDirection()); $this->assertEquals($sValue . ' DESC', $oSorterCriteria2->getQueryString()); }
public function parseRequest(ServerRequestInterface $oRequest) { // Sort query parameter exists if (array_key_exists('sort', $oRequest->getQueryParams())) { // Loop through sort labels foreach (explode(',', $oRequest->getQueryParams()['sort']) as $sLabel) { // Label is allowed if (array_key_exists($sLabel, $this->aAllowedLabels)) { // Create sorter criteria $oSorterCriteria = new SorterCriteria($sLabel, $this->aAllowedLabels[$sLabel]); // Update $this->aCriterias[] = $oSorterCriteria; $this->aCriteriaQueryStrings[] = $oSorterCriteria->getQueryString(); } } } }