class Parser (View source)

The parser which is underlying http\Header and http\Message.

NOTE: This class has been added in v2.3.0.

Constants

CLEANUP

Finish up parser at end of (incomplete) input.

STATE_FAILURE

Parse failure.

STATE_START

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

STATE_KEY

Expecting a key or already parsing a key.

STATE_VALUE

Expecting a value or already parsing the value.

STATE_VALUE_EX

At EOL of an header, checking whether a folded header line follows.

STATE_HEADER_DONE

A header was completed.

STATE_DONE

Finished parsing the headers.

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, array $header = null)

Parse a string.

int
stream(resource $stream, int $flags, array $headers)

Parse a stream.

Details

int getState()

Retrieve the current state of the parser.

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

Return Value

int

http\Header\Parser::STATE_* constant.

Exceptions

InvalidArgumentException

int parse(string $data, int $flags, array $header = null)

Parse a string.

Parameters

string $data

The (part of the) header to parse.

int $flags

Any combination of parser flags.

array $header

Successfully parsed headers.

Return Value

int

http\Header\Parser::STATE_* constant.

Exceptions

InvalidArgumentException

int stream(resource $stream, int $flags, array $headers)

Parse a stream.

Parameters

resource $stream

The header stream to parse from.

int $flags

Any combination of parser flags.

array $headers

The headers parsed.

Return Value

int

http\Header\Parser::STATE_* constant.

Exceptions

InvalidArgumentException
UnexpectedValueException