eZ\Publish\Core\REST\Server\Input\Parser\SortClause\DataKeyValueObjectClass::parse PHP Метод

parse() публичный Метод

Parse input structure.
public parse ( array $data, ParsingDispatcher $parsingDispatcher ) : eZ\Publish\API\Repository\Values\ValueObject
$data array
$parsingDispatcher eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Результат eZ\Publish\API\Repository\Values\ValueObject
    public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!class_exists($this->valueObjectClass)) {
            throw new Exceptions\Parser("Value object class <{$this->valueObjectClass}> is not defined");
        }
        if (!array_key_exists($this->dataKey, $data)) {
            throw new Exceptions\Parser("The <{$this->dataKey}> sort clause doesn't exist in the input structure");
        }
        $direction = $data[$this->dataKey];
        if (!in_array($direction, [Query::SORT_ASC, Query::SORT_DESC])) {
            throw new Exceptions\Parser("Invalid direction format in <{$this->dataKey}> sort clause");
        }
        return new $this->valueObjectClass($direction);
    }

Usage Example

 /**
  * Test DataKeyValueObjectClass parser throwing exception on nonexisting value object class.
  *
  * @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser
  * @expectedExceptionMessage Value object class <eC\Pubish\APl\Repudiatory\BadValues\Discontent\Queezy\SantaClause\ThisClassIsExistentiallyChallenged> is not defined
  */
 public function testParseExceptionOnNonexistingValueObjectClass()
 {
     $inputArray = array('DatePublished' => Query::SORT_ASC);
     $dataKeyValueObjectClass = new DataKeyValueObjectClass('DatePublished', 'eC\\Pubish\\APl\\Repudiatory\\BadValues\\Discontent\\Queezy\\SantaClause\\ThisClassIsExistentiallyChallenged');
     $dataKeyValueObjectClass->parse($inputArray, $this->getParsingDispatcherMock());
 }
DataKeyValueObjectClass