Interface XML_Query2XML_Callback

Description

Callback interface

If you want to use a non-static method as a callback for XML_Query2XML you have to use an instance of a class that implements this interface. Your command class (read more about the command pattern here) therefore has to implement a public method that is named "execute" and accepts an array as its first argument. Here goes an example:

  1.  require_once 'XML/Query2XML/Callback.php';
  2.  class MyCallback implements XML_Query2XML_Callback
  3.  {
  4.    public function execute(array $record)
  5.    {
  6.        $data $record['some_column'];
  7.        // do some really complex things with $data
  8.  
  9.        return $data;
  10.    }
  11.  }
  12.  $myCallback new MyCallback();
XML_Query2XML will always invoke the execute() method and will pass the current record as an associative array as the first and only argument. A command object can be used for
  • Simple Element Specifications
  • Complex Element Specifications ($options['value')
  • Simple Attribute Specifications
  • Complex Attribute Specifications ($options['value')
  • $options['condition']
  • $options['sql']['data']
  • $options['idColumn']
If you want to use the same command class for different columns, I suggest you pass the column name to the constructor:
  1.  require_once 'XML/Query2XML/Callback.php';
  2.  class MyCallback implements XML_Query2XML_Callback
  3.  {
  4.    private $_columnName '';
  5.    public function __construct($columnName)
  6.    {
  7.        $this->_columnName $columnName;
  8.    }
  9.    public function execute(array $record)
  10.    {
  11.        if (!isset($record[$this->_columnName])) {
  12.            // throw an exception here
  13.        }
  14.        $data $record[$this->_columnName];
  15.        // do some really complex things with $data
  16.  
  17.        return $data;
  18.    }
  19.  }
  20.  $myCallback new MyCallback('some_column_name');

Located in /Query2XML/Callback.php (line 84)


	
			
Method Summary
mixed execute ( $record)
Methods
execute (line 96)

This method will be called by XML_Query2XML.

This method has to return a value that can be cast to a string or if used within a Complex Element Specification, an instance of DOMNode.

  • return: A value that can be cast to a string or an instance of DOMNode.
  • access: public
mixed execute ( $record)
  • array $record: A record as an associative array.

Documentation generated on Sun, 03 Apr 2011 13:13:07 +0200 by phpDocumentor 1.4.1