XML_Query2XML
[ class tree: XML_Query2XML ] [ index: XML_Query2XML ] [ all elements ]

Class: XML_Query2XML_Callback

Source Location: /XML_Query2XML-1.7.2/XML/Query2XML/Callback.php

Class Overview


Callback interface


Author(s):

Version:

  • Release: 1.7.2

Copyright:

  • 2006 Lukas Feiler

Methods


Inherited Variables

Inherited Methods


Class Details

[line 84]
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');



[ Top ]


Method Detail

execute   [line 96]

mixed execute( array $record)

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

Parameters:

array   $record   —  A record as an associative array.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:43:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.