...
Code Block | ||||
---|---|---|---|---|
| ||||
namespace My\Bundle\RestBundle\InputParser;
use eZ\Publish\Core\REST\Server\Input\Parser\Base as BaseParser;
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
use My\Bundle\RestBundle\Rest\Value\Hello;
use eZ\Publish\Core\REST\Common\Exceptions;
class Greetings extends BaseParser
{
/**
* @return My\Bundle\RestBundle\Rest\Value\Hello
*/
public function parse( array $data, ParsingDispatcher $parsingDispatcher )
{
// re-using the REST exceptions will make sure that those already have a ValueObjectVisitor
if ( !array_key_exists( 'name', $data ) )
throw new Exceptions\Parser( "Missing or invalid 'name' element for Greetings." );
// the root level of the parsed structure is ignored
$name = $data['name']
return new Hello( $name );
}
} |
...