| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* This file contains the interface XML_Query2XML_Callback.
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category XML
|
|
|
8 |
* @package XML_Query2XML
|
|
|
9 |
* @author Lukas Feiler <lukas.feiler@lukasfeiler.com>
|
|
|
10 |
* @copyright 2007 Lukas Feiler
|
|
|
11 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1
|
|
|
12 |
* @version CVS: $Id: Callback.php 276639 2009-03-01 13:17:08Z lukasfeiler $
|
|
|
13 |
* @link http://pear.php.net/package/XML_Query2XML
|
|
|
14 |
*/
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Callback interface
|
|
|
18 |
*
|
|
|
19 |
* If you want to use a non-static method as a callback for XML_Query2XML
|
|
|
20 |
* you have to use an instance of a class that implements this interface.
|
|
|
21 |
* Your command class (read more about the command pattern
|
|
|
22 |
* {@link http://en.wikipedia.org/wiki/Command_pattern here}) therefore
|
|
|
23 |
* has to implement a public method that is named "execute" and accepts an
|
|
|
24 |
* array as its first argument. Here goes an example:
|
|
|
25 |
* <code>
|
|
|
26 |
* require_once 'XML/Query2XML/Callback.php';
|
|
|
27 |
* class MyCallback implements XML_Query2XML_Callback
|
|
|
28 |
* {
|
|
|
29 |
* public function execute(array $record)
|
|
|
30 |
* {
|
|
|
31 |
* $data = $record['some_column'];
|
|
|
32 |
* // do some really complex things with $data
|
|
|
33 |
*
|
|
|
34 |
* return $data;
|
|
|
35 |
* }
|
|
|
36 |
* }
|
|
|
37 |
* $myCallback = new MyCallback();
|
|
|
38 |
* </code>
|
|
|
39 |
* XML_Query2XML will always invoke the execute() method and will pass
|
|
|
40 |
* the current record as an associative array as the first and only argument.
|
|
|
41 |
* A command object can be used for
|
|
|
42 |
* - Simple Element Specifications
|
|
|
43 |
* - Complex Element Specifications ($options['value')
|
|
|
44 |
* - Simple Attribute Specifications
|
|
|
45 |
* - Complex Attribute Specifications ($options['value')
|
|
|
46 |
* - $options['condition']
|
|
|
47 |
* - $options['sql']['data']
|
|
|
48 |
* - $options['idColumn']
|
|
|
49 |
*
|
|
|
50 |
* If you want to use the same command class for different columns, I suggest
|
|
|
51 |
* you pass the column name to the constructor:
|
|
|
52 |
* <code>
|
|
|
53 |
* require_once 'XML/Query2XML/Callback.php';
|
|
|
54 |
* class MyCallback implements XML_Query2XML_Callback
|
|
|
55 |
* {
|
|
|
56 |
* private $_columnName = '';
|
|
|
57 |
* public function __construct($columnName)
|
|
|
58 |
* {
|
|
|
59 |
* $this->_columnName = $columnName;
|
|
|
60 |
* }
|
|
|
61 |
* public function execute(array $record)
|
|
|
62 |
* {
|
|
|
63 |
* if (!isset($record[$this->_columnName])) {
|
|
|
64 |
* // throw an exception here
|
|
|
65 |
* }
|
|
|
66 |
* $data = $record[$this->_columnName];
|
|
|
67 |
* // do some really complex things with $data
|
|
|
68 |
*
|
|
|
69 |
* return $data;
|
|
|
70 |
* }
|
|
|
71 |
* }
|
|
|
72 |
* $myCallback = new MyCallback('some_column_name');
|
|
|
73 |
* </code>
|
|
|
74 |
*
|
|
|
75 |
* @category XML
|
|
|
76 |
* @package XML_Query2XML
|
|
|
77 |
* @author Lukas Feiler <lukas.feiler@lukasfeiler.com>
|
|
|
78 |
* @copyright 2006 Lukas Feiler
|
|
|
79 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1
|
|
|
80 |
* @version Release: 1.7.2
|
|
|
81 |
* @link http://pear.php.net/package/XML_Query2XML
|
|
|
82 |
* @since Release 1.1.0
|
|
|
83 |
*/
|
|
|
84 |
interface XML_Query2XML_Callback
|
|
|
85 |
{
|
|
|
86 |
/**
|
|
|
87 |
* This method will be called by XML_Query2XML.
|
|
|
88 |
* This method has to return a value that can be cast to a string
|
|
|
89 |
* or if used within a Complex Element Specification, an instance
|
|
|
90 |
* of DOMNode.
|
|
|
91 |
*
|
|
|
92 |
* @param array $record A record as an associative array.
|
|
|
93 |
*
|
|
|
94 |
* @return mixed A value that can be cast to a string or an instance of DOMNode.
|
|
|
95 |
*/
|
|
|
96 |
public function execute(array $record);
|
|
|
97 |
}
|
|
|
98 |
?>
|