class Parser (View source)

The parser which is underlying http\Message.

NOTE: This class was added in v2.2.0.

Constants

CLEANUP

Finish up parser at end of (incomplete) input.

DUMB_BODIES

Soak up the rest of input if no entity length is deducible.

EMPTY_REDIRECTS

Redirect messages do not contain any body despite of indication of such.

GREEDY

Continue parsing while input is available.

STATE_FAILURE

Parse failure.

STATE_START

Expecting HTTP info (request/response line) or headers.

STATE_HEADER

Parsing headers.

STATE_HEADER_DONE

Completed parsing headers.

STATE_BODY

Parsing the body.

STATE_BODY_DUMB

Soaking up all input as body.

STATE_BODY_LENGTH

Reading body as indicated by Content-Length or Content-Range.

STATE_BODY_CHUNKED

Parsing chunked encoded body.

STATE_BODY_DONE

Finished parsing the body.

STATE_UPDATE_CL

Updating Content-Length based on body size.

STATE_DONE

Finished parsing the message.

NOTE: Most of this states won't be returned to the user, because the parser immediately jumps to the next expected state.

Methods

int
getState()

Retrieve the current state of the parser.

int
parse(string $data, int $flags, Message $message)

Parse a string.

int
stream(resource $stream, int $flags, Message $message)

Parse a stream.

Details

int getState()

Retrieve the current state of the parser.

See http\Message\Parser::STATE_* constants.

Return Value

int

http\Message\Parser::STATE_* constant.

Exceptions

InvalidArgumentException

int parse(string $data, int $flags, Message $message)

Parse a string.

Parameters

string $data

The (part of the) message to parse.

int $flags

Any combination of parser flags.

Message $message

The current state of the message parsed.

Return Value

int

http\Message\Parser::STATE_* constant.

Exceptions

InvalidArgumentException

int stream(resource $stream, int $flags, Message $message)

Parse a stream.

Parameters

resource $stream

The message stream to parse from.

int $flags

Any combination of parser flags.

Message $message

The current state of the message parsed.

Return Value

int

http\Message\Parser::STATE_* constant.

Exceptions

InvalidArgumentException
UnexpectedValueException