XRL  latest
Simple XML-RPC Library (both client and server)
fpoirotte\XRL\Decoder Class Reference

A decoder that can process XML-RPC requests and responses, with optional XML validation. More...

+ Inheritance diagram for fpoirotte\XRL\Decoder:

Public Member Functions

 __construct (\DateTimeZone $timezone=null, $validate=true)
 
 decodeRequest ($URI)
 
 decodeResponse ($URI)
 

Protected Member Functions

 decodeValue (\XMLReader $reader, array $allowedTypes=array())
 
 expectEndTag ($reader, $expectedTag)
 
 expectStartTag ($reader, $expectedTag)
 
 getReader ($URI, $request)
 
 parseText ($reader)
 
 prepareNextNode ()
 
 readNode ($reader)
 

Static Protected Member Functions

static checkType (array $allowedTypes, $type, $value)
 

Protected Attributes

 $currentNode
 The fpoirotte::XRL::Node currently being processed.
 
 $timezone
 Timezone used to decode date/times.
 
 $validate
 Whether the documents should be validated or not.
 

Static Protected Attributes

static $types
 Names for the various types of XML nodes in libxml. More...
 

Detailed Description

A decoder that can process XML-RPC requests and responses, with optional XML validation.

Authors
François Poirotte click.nosp@m.y@er.nosp@m.ebot..nosp@m.net

Definition at line 21 of file Decoder.php.

Constructor & Destructor Documentation

fpoirotte\XRL\Decoder::__construct ( \DateTimeZone  $timezone = null,
  $validate = true 
)

Creates a new decoder.

Parameters
DateTimeZone$timezone(optional) Information on the timezone incoming date/times come from. If omitted, the machine's current timezone is used.
bool$validate(optional) Whether the decoder should validate its input (true) or not (false). Validation is enabled by default.
Exceptions
InvalidArgumentExceptionThe value passed for $validate was not a boolean.

Definition at line 71 of file Decoder.php.

References fpoirotte\XRL\Decoder\$timezone, and fpoirotte\XRL\Decoder\$validate.

Member Function Documentation

static fpoirotte\XRL\Decoder::checkType ( array  $allowedTypes,
  $type,
  $value 
)
staticprotected

Check the type of a value.

Parameters
array$allowedTypesWhitelist of allowed types. If empty, any type is allowed.
string$typeThe actual type of the value being tested.
mixed$valueThe value being tested.
Return values
mixedThe original value that was passed to this method, if type allows.
Exceptions
InvalidArgumentExceptionThe given type cannot be used in this context (disallowed).

Definition at line 310 of file Decoder.php.

fpoirotte\XRL\Decoder::decodeRequest (   $URI)

Decode an XML-RPC request.

Parameters
string$URIURI to XML-RPC request.
Return values
fpoirotte::XRL::RequestAn object representing an XML-RPC request.
Exceptions
InvalidArgumentExceptionThe given $data was invalid. For example, it wasn't a string, it didn"t contain any XML or the request was malformed.

Implements fpoirotte\XRL\DecoderInterface.

Definition at line 490 of file Decoder.php.

References fpoirotte\XRL\Decoder\decodeValue(), fpoirotte\XRL\Decoder\expectEndTag(), fpoirotte\XRL\Decoder\expectStartTag(), fpoirotte\XRL\Decoder\getReader(), fpoirotte\XRL\Decoder\parseText(), and fpoirotte\XRL\Decoder\readNode().

fpoirotte\XRL\Decoder::decodeResponse (   $URI)

Decode an XML-RPC response.

Parameters
string$URIURI to the XML-RPC response.
Return values
mixedThe return value represented by the XML-RPC response.
Exceptions
fpoirotte::XRL::ExceptionThrown whenever the response described a failure. This exception's getCode() and getMessage() methods can be used to retrieve the original failure's code and description, respectively.
InvalidArgumentExceptionThe given $data was invalid. For example, it wasn't a string, it didn"t contain any XML or the request was malformed.

Implements fpoirotte\XRL\DecoderInterface.

Definition at line 560 of file Decoder.php.

References fpoirotte\XRL\Decoder\decodeValue(), fpoirotte\XRL\Decoder\expectEndTag(), fpoirotte\XRL\Decoder\expectStartTag(), fpoirotte\XRL\Decoder\getReader(), and fpoirotte\XRL\Decoder\readNode().

fpoirotte\XRL\Decoder::decodeValue ( \XMLReader  $reader,
array  $allowedTypes = array() 
)
protected

Decodes a value encoded using XML-RPC types.

Parameters
XMLReader$readerReader the value will be read from.
array$allowedTypesWhitelist will the names of the types that are allowed in this context.
Return values
mixedThe value that was decoded, if any, with the appropriate PHP type.
Exceptions
InvalidArgumentExceptionNo value could be decoded (probably because the input document was invalid) or the decoded value was of a type that is not allowed in this context.

Definition at line 342 of file Decoder.php.

References fpoirotte\XRL\Decoder\$types, fpoirotte\XRL\Decoder\expectEndTag(), fpoirotte\XRL\Decoder\expectStartTag(), fpoirotte\XRL\Decoder\parseText(), and fpoirotte\XRL\Types\AbstractType\read().

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), and fpoirotte\XRL\Decoder\decodeResponse().

fpoirotte\XRL\Decoder::expectEndTag (   $reader,
  $expectedTag 
)
protected

Read a node from the document and throw an exception if it is not a closing tag with the given name.

Parameters
XMLReader$readerReader object the node will be read from.
string$expectedTagName of the tag we're expecting.
Exceptions
InvalidArgumentExceptionThrown whenever one of the following conditions is met:
  • We reached the end of the document.
  • The next node was not a closing tag.
  • The next node was a closing tag, but its name was not the one we expected.

Definition at line 230 of file Decoder.php.

References fpoirotte\XRL\Decoder\prepareNextNode(), and fpoirotte\XRL\Decoder\readNode().

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), fpoirotte\XRL\Decoder\decodeResponse(), and fpoirotte\XRL\Decoder\decodeValue().

fpoirotte\XRL\Decoder::expectStartTag (   $reader,
  $expectedTag 
)
protected

Read a node from the document and throw an exception if it is not an opening tag with the given name.

Parameters
XMLReader$readerReader object the node will be read from.
string$expectedTagName of the tag we're expecting.
Exceptions
InvalidArgumentExceptionThrown whenever one of the following conditions is met:
  • We reached the end of the document.
  • The next node was not an opening tag.
  • The next node was an opening tag, but its name was not the one we expected.

Definition at line 188 of file Decoder.php.

References fpoirotte\XRL\Decoder\prepareNextNode(), and fpoirotte\XRL\Decoder\readNode().

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), fpoirotte\XRL\Decoder\decodeResponse(), and fpoirotte\XRL\Decoder\decodeValue().

fpoirotte\XRL\Decoder::getReader (   $URI,
  $request 
)
protected

Returns an XML reader for some data.

Parameters
string$URIURI to the XML data to process.
bool$requestWhether the data refers to an XML-RPC request (true) or a response (false).
Return values
XMLReaderAn XML reader for the given data.
Exceptions
InvalidArgumentExceptionYou tried to pass something that is not a boolean as the $request parameter.
Note
The reader is set to validate the document on the fly if that's what this decoder was configured to do during construction.

Definition at line 114 of file Decoder.php.

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), and fpoirotte\XRL\Decoder\decodeResponse().

fpoirotte\XRL\Decoder::parseText (   $reader)
protected

Read a node from the document and throw an exception if it is not a text node. Otherwise, return its content.

Parameters
XMLReader$readerReader object the node will be read from.
Return values
stringThe value of the text node.
Exceptions
InvalidArgumentExceptionThrown whenever one of the following conditions is met:
  • We reached the end of the document.
  • The next node was not a text node.

Definition at line 270 of file Decoder.php.

References fpoirotte\XRL\Decoder\prepareNextNode(), and fpoirotte\XRL\Decoder\readNode().

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), and fpoirotte\XRL\Decoder\decodeValue().

fpoirotte\XRL\Decoder::prepareNextNode ( )
protected

Prepare for the next XML node read. This method should be called after each successful node parsing.

Definition at line 162 of file Decoder.php.

Referenced by fpoirotte\XRL\Decoder\expectEndTag(), fpoirotte\XRL\Decoder\expectStartTag(), and fpoirotte\XRL\Decoder\parseText().

fpoirotte\XRL\Decoder::readNode (   $reader)
protected

Read a node from the XML reader and return it.

Parameters
XMLReader$readerReader to read the node from.
Return values
fpoirotte::XRL::NodeThe XML node that's been read.

Definition at line 147 of file Decoder.php.

References fpoirotte\XRL\Decoder\$currentNode.

Referenced by fpoirotte\XRL\Decoder\decodeRequest(), fpoirotte\XRL\Decoder\decodeResponse(), fpoirotte\XRL\Decoder\expectEndTag(), fpoirotte\XRL\Decoder\expectStartTag(), and fpoirotte\XRL\Decoder\parseText().

Member Data Documentation

fpoirotte\XRL\Decoder::$types
staticprotected
Initial value:
= array(
\XMLReader::NONE => 'NONE',
\XMLReader::ELEMENT => 'ELEMENT',
\XMLReader::ATTRIBUTE => 'ATTRIBUTE',
\XMLReader::TEXT => 'TEXT',
\XMLReader::CDATA => 'CDATA',
\XMLReader::ENTITY_REF => 'ENTITY_REF',
\XMLReader::ENTITY => 'ENTITY',
\XMLReader::PI => 'PI',
\XMLReader::COMMENT => 'COMMENT',
\XMLReader::DOC => 'DOC',
\XMLReader::DOC_TYPE => 'DOC_TYPE',
\XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT',
\XMLReader::NOTATION => 'NOTATION',
\XMLReader::WHITESPACE => 'WHITESPACE',
\XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE',
\XMLReader::END_ELEMENT => 'END_ELEMENT',
\XMLReader::END_ENTITY => 'END_ENTITY',
\XMLReader::XML_DECLARATION => 'XML_DECLARATION',
)

Names for the various types of XML nodes in libxml.

Definition at line 33 of file Decoder.php.

Referenced by fpoirotte\XRL\Decoder\decodeValue().


The documentation for this class was generated from the following file: