cvs: pear /XML_Query2XML/XML/Query2XML/Command Base64.php CDATA.php Chain.php ColumnValue.php NonEmpty.php PHPCallback.php Static.php Unserialize.php

From: Date: Sun, 16 Sep 2007 02:04:06 +0000
Subject: cvs: pear /XML_Query2XML/XML/Query2XML/Command Base64.php CDATA.php Chain.php ColumnValue.php NonEmpty.php PHPCallback.php Static.php Unserialize.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48611@lists.php.net to get a copy of this message
lukasfeiler Sun Sep 16 02:04:06 2007 UTC Added files: /pear/XML_Query2XML/XML/Query2XML/Command Base64.php CDATA.php Chain.php ColumnValue.php NonEmpty.php PHPCallback.php Static.php Unserialize.php Log: new command classes used during pre-processing

http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/Base64.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/Base64.php +++ pear/XML_Query2XML/XML/Query2XML/Command/Base64.php <?php /**This file contains the class XML_Query2XML_Command_Base64. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: Base64.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_Base64 extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class that base64-encodes the string returned by a pre-processor. * * XML_Query2XML_Command_Base64 only works with a pre-processor * that returns a string. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_Base64( * new XML_Query2XML_Command_ColumnValue('name') //pre-processor * ); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_Base64 extends XML_Query2XML_Command_Chain { /**Called by XML_Query2XML for every record in the result set. * * @throws XML_Query2XML_ConfigException If the pre-processor returns * something that cannot be converted to a string * (i.e. an object or an array). * @param array $record An associative array. * @return string The base64-encoded version the string returned * by the pre-processor. */ public function execute(array $record) { $data = $this->_runPreProcessor($record); if (is_array($data) || is_object($data)) { throw new XML_Query2XML_ConfigException( $this->_configPath . ': XML_Query2XML_Command_Base64: string ' . 'expected from pre-processor, but ' . gettype($data) . ' returned.' ); } return base64_encode($data); } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/CDATA.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/CDATA.php +++ pear/XML_Query2XML/XML/Query2XML/Command/CDATA.php <?php /**This file contains the class XML_Query2XML_Command_CDATA. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: CDATA.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_CDATA extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class that creates a CDATA section around the string returned by * a pre-processor. * * XML_Query2XML_Command_CDATA only works with a pre-processor * that returns a string. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_CDATA( * new XML_Query2XML_Command_ColumnValue('name') //pre-processor * ); * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 * </code> */ class XML_Query2XML_Command_CDATA extends XML_Query2XML_Command_Chain { /**Called by XML_Query2XML for every record in the result set. * This method will return an instance of DOMCDATASection or null * if an empty string was returned by the pre-processor. * * @throws XML_Query2XML_ConfigException If the pre-processor returns * something that cannot be converted to a string (i.e. an * array or an object) or if no pre-processor was set. * @param array $record An associative array. * @return DOMCDATASection */ public function execute(array $record) { $doc = new DOMDocument(); $data = $this->_runPreProcessor($record); if (is_array($data) || is_object($data)) { throw new XML_Query2XML_ConfigException( $this->_configPath . 'XML_Query2XML_Command_CDATA: string expected ' . 'from pre-processor, but ' . gettype($data) . ' returned.' ); } if (strlen($data) > 0) { return $doc->createCDATASection($data); } else { return null; } } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/Chain.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/Chain.php +++ pear/XML_Query2XML/XML/Query2XML/Command/Chain.php <?php /**This file contains the class XML_Query2XML_Command_Chain. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: Chain.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_Chain implements the interface XML_Query2XML_Callback. */ require_once 'XML/Query2XML/Callback.php'; /**Abstract class extended by all command classes that are part of the * XML_Query2XML package. * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ abstract class XML_Query2XML_Command_Chain implements XML_Query2XML_Callback { /**Another instance of XML_Query2XML_Command_Chain to process before this one. * @var XML_Query2XML_Command_Chain */ protected $_preProcessor = null; /**The configuration path; it is used for exception messages * @var string */ protected $_configPath = ''; /**Constructor * @param XML_Query2XML_Command_Chain $preProcessor The pre-processor to be used. * This argument is optional. * @param string $configPath The configuration path within the $options array. * This argument is optional. */ public function __construct(XML_Query2XML_Command_Chain $preProcessor = null, $configPath = '') { $this->_preProcessor = $preProcessor; $this->_configPath = $configPath; if ($this->_configPath) { $this->_configPath .= ': '; } } /**Allows the pre-processor to be set (or changed) after an instance was created. * @param XML_Query2XML_Command_Chain $preProcessor The pre-processor to be used. */ public function setPreProcessor(XML_Query2XML_Command_Chain $preProcessor) { $this->_preProcessor = $preProcessor; } /**Runs the pre-processor if one was defined and returns it's return value. * * @throws XML_Query2XML_ConfigException If no pre-processor was defined. * @param array $record The record to process - this is an associative array. * @return mixed Whatever was returned by the pre-processor */ protected function _runPreProcessor(array $record) { if (!is_null($this->_preProcessor)) { return $this->_preProcessor->execute($record); } else { require_once 'XML/Query2XML.php'; throw new XML_Query2XML_ConfigException( $this->_configPath . get_class($this) . ' requires a pre-processor.' ); } } /**Returns the first pre-processor in the chain. * * This will be the innerst one when using the following notation: * <code> * new XML_Query2XML_Command_Base64(new XML_Query2XML_Command_Static('test')) * </code> * If there is no pre-processor, $this is returned. * * @return XML_Query2XML_Command_Chain */ public function getFirstPreProcessor() { if (!is_null($this->_preProcessor)) { return $this->_preProcessor->getFirstPreProcessor(); } return $this; } /**Returns a textual representation of this instance. * This might be useful for debugging. * @return string */ public function toString() { $str = get_class($this) . '('; if (!is_null($this->_preProcessor)) { $str .= $this->_preProcessor->toString(); } return $str . ')'; } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/ColumnValue.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/ColumnValue.php +++ pear/XML_Query2XML/XML/Query2XML/Command/ColumnValue.php <?php /**This file contains the class XML_Query2XML_Command_ColumnValue. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: ColumnValue.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_ColumnValue extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class that allows the column value to be used as the data source. * * This command class does not accept a pre-processor. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_ColumnValue('name'); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_ColumnValue extends XML_Query2XML_Command_Chain implements XML_Query2XML_Command_DataSource { /**The column name. * @var string */ private $_column = ''; /**Constructor * @param string $column The name of the column. * @param string $configPath The configuration path within the $options array. */ public function __construct($column, $configPath) { $this->_column = $column; $this->_configPath = $configPath; if ($this->_configPath) { $this->_configPath .= ': '; } } /**Called by XML_Query2XML for every record in the result set. * * @throws XML_Query2XML_ConfigException If $column does not exist in the * result set, i.e. $record[$column] does not exist. * @param array $record An associative array. * @return mixed The contents of $record[$column] where $column is the first * argument passed to the constructor. */ public function execute(array $record) { if (array_key_exists($this->_column, $record)) { return $record[$this->_column]; } throw new XML_Query2XML_ConfigException( $this->_configPath . 'The column "' . $this->_column . '" was not found in the result set' ); } /**This method is called by XML_Query2XML in case the asterisk shortcut was used. * * The interface XML_Query2XML_Command_DataSource requires an implementation of * this method. * * @param string $columnName The column name that is to replace every occurance * of the asterisk character '*' in $column (the first * argument passed to the constructor). */ public function replaceAsterisks($columnName) { $this->_column = str_replace('*', $columnName, $this->_column); } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/NonEmpty.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/NonEmpty.php +++ pear/XML_Query2XML/XML/Query2XML/Command/NonEmpty.php <?php /**This file contains the class XML_Query2XML_Command_NonEmpty. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: NonEmpty.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_NonEmpty extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class implementing a condition based on whether the value * returned by a pre-processor is an object or a non-empty string. * * XML_Query2XML_Command_NonEmpty requires a pre-processor to be used. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_NonEmpty( * new XML_Query2XML_Command_ColumnValue('name') //pre-processor * ); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_NonEmpty extends XML_Query2XML_Command_Chain implements XML_Query2XML_Command_Conditional { /**Called by XML_Query2XML for every record in the result set. * * @throws XML_Query2XML_ConfigException If no pre-processor was set. * @param array $record An associative array. * @return mixed whatever is returned by the pre-processor */ public function execute(array $record) { return $this->_runPreProcessor($record); } /**As this class implements XML_Query2XML_Command_Conditional, XML_Query2XML * will call this method to determin whether the condition is fulfilled. * @param mixed $value The value previously returned by $this->execute(). * @return boolean Whether the condition is fulfilled. */ public function evaluateCondition($value) { return is_object($value) || !(is_null($value) || (is_string($value) && strlen($value) == 0)); } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/PHPCallback.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/PHPCallback.php +++ pear/XML_Query2XML/XML/Query2XML/Command/PHPCallback.php <?php /**This file contains the class XML_Query2XML_Command_PHPCallback. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: PHPCallback.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_PHPCallback extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class that invokes a callback function, using the return value as the * data source. * * This command class does not accept a pre-processor. * * usage: * <code> * function myFunction($record) { ... } * $commandObject = new XML_Query2XML_Command_PHPCallback('myFunction'); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_PHPCallback extends XML_Query2XML_Command_Chain implements XML_Query2XML_Command_DataSource { private $_callback = null; private $_args = array(); /**Constructor * * The following formats are supported for $callback: * - 'myFunction' * - 'myFunction(arg1, arg2, ...)' * - 'MyClass::myStaticMethod' * - 'MyClass::myStaticMethod(arg1, arg2, ...)' * You can also pass additional string arguments to the callback function by * specifing them within the opening and closing brace; e.g. 'Utils::limit(12)' * will result in Util::limit() being called by execute() with the $record as * the first and '12' as the second argument. * If you do not want to pass additional arguments to the callback function, * the opening and closing brace are optional. * * @throws XML_Query2XML_ConfigException If $callback is not callable. * @param mixed $callback * @param string $configPath The configuration path within the $options array. * This argument is optional. */ public function __construct($callback, $configPath) { $this->_configPath = $configPath; if ($this->_configPath) { $this->_configPath .= ': '; } $braceOpen = strpos($callback, '('); if ($braceOpen !== false) { $braceClose = strpos($callback, ')'); if ($braceOpen + 1 < $braceClose) { $argsString = substr( $callback, $braceOpen + 1, $braceClose - $braceOpen - 1 ); $this->_args = explode(',', str_replace(', ', ',', $argsString)); } if ($braceOpen < $braceClose) { $callback = substr($callback, 0, $braceOpen); } } if (strpos($callback, '::') !== false) { $callback = split('::', $callback); } if (!is_callable($callback, false, $callableName)) { /* * unit tests: _applyColumnStringToRecord/ * throwConfigException_callback_function1.phpt * throwConfigException_callback_function2.phpt * throwConfigException_callback_method1.phpt * throwConfigException_callback_method2.phpt */ throw new XML_Query2XML_ConfigException( $this->_configPath . 'The method/function "' . $callableName . '" is not callable.' ); } $this->_callback = $callback; } /**Called by XML_Query2XML for every record in the result set. * * @param array $record An associative array. * @return mixed Whatever the callback function returned. */ public function execute(array $record) { return call_user_func_array( $this->_callback, array_merge(array($record), $this->_args) ); } /**This method is called by XML_Query2XML in case the asterisk shortcut was used. * * The interface XML_Query2XML_Command_DataSource requires an implementation of * this method. * * @param string $columnName The column name that is to replace every occurance * of the asterisk character '*' in any of the arguments * specified in the 'myFunction(arg1, arg2, ...)' or * 'MyClass::myStaticMethod(arg1, arg2, ...)' notation. */ public function replaceAsterisks($columnName) { foreach ($this->_args as $key => $arg) { $this->_args[$key] = str_replace('*', $columnName, $this->_args[$key]); } } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/Static.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/Static.php +++ pear/XML_Query2XML/XML/Query2XML/Command/Static.php <?php /**This file contains the class XML_Query2XML_Command_Static. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: Static.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_Static extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command class that allows a static value to be used as the data source. * * This command class does not accept a pre-processor. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_Static('my static value'); * </code> * * The static value can also be an instance of DOMNode or an array of DOMNode * instances: * <code> * $commandObject = new XML_Query2XML_Command_Static(new DOMElement('test')); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_Static extends XML_Query2XML_Command_Chain implements XML_Query2XML_Command_DataSource { /**The static data. * @var mixed */ private $_data = null; /**Constructor * @param mixed $data The static data. */ public function __construct($data) { if ($data === false) { $data = ''; } $this->_data = $data; } /**Called by XML_Query2XML for every record in the result set. * * @param array $record An associative array. * @return mixed Whatever was passed as $data to the constructor. */ public function execute(array $record) { return $this->_data; } /**This method is called by XML_Query2XML in case the asterisk shortcut was used. * * The interface XML_Query2XML_Command_DataSource requires an implementation of * this method. * * @param string $columnName The column name that is to replace every occurance * of the asterisk character '*' in the static value, * in case it is a string. */ public function replaceAsterisks($columnName) { if (is_string($this->_data)) { $this->_data = str_replace('*', $columnName, $this->_data); } } } ?> http://cvs.php.net/viewvc.cgi/pear/XML_Query2XML/XML/Query2XML/Command/Unserialize.php?view=markup&rev=1.1 Index: pear/XML_Query2XML/XML/Query2XML/Command/Unserialize.php +++ pear/XML_Query2XML/XML/Query2XML/Command/Unserialize.php <?php /**This file contains the class XML_Query2XML_Command_Unserialize. * * LICENSE: * This source file is subject to version 2.1 of the LGPL * that is bundled with this package in the file LICENSE. * * COPYRIGHT: * Empowered Media * http://www.empoweredmedia.com * 481 Eighth Avenue Suite 1530 * New York, NY 10001 * * @copyright Empowered Media 2006 * @license http://www.gnu.org/copyleft/lesser.html LGPL Version 2.1 * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @package XML_Query2XML * @version $Id: Unserialize.php,v 1.1 2007/09/16 02:04:06 lukasfeiler Exp $ */ /**XML_Query2XML_Command_Unserialize extends the class XML_Query2XML_Command_Chain. */ require_once 'XML/Query2XML/Command/Chain.php'; /**Command object that allows unserialization of XML data returned by a pre-processor * as a string. * * XML_Query2XML_Command_Unserialize only works with a pre-processor * that returns a string. * * usage: * <code> * $commandObject = new XML_Query2XML_Command_Unserialize( * new XML_Query2XML_Command_ColumnValue('xml_data') //pre-processor * ); * </code> * * @author Lukas Feiler <lukas.feiler@lukasfeiler.com> * @version Release: @package_version@ * @copyright Empowered Media 2006 * @package XML_Query2XML * @since Interface available since Release 1.5.0RC1 */ class XML_Query2XML_Command_Unserialize extends XML_Query2XML_Command_Chain { /**Called by XML_Query2XML for every record in the result set. * This method will return an instance of DOMElement or null * if an empty string was returned by the pre-processor. * * @throws XML_Query2XML_ConfigException If the pre-processor returned * something that cannot be converted to a string (i.e. an * array or an object) or if that string could not be * unserialized, i.e. was not corretly formatted XML. * @param array $record An associative array. * @return DOMElement */ public function execute(array $record) { $doc = new DOMDocument(); $xml = $this->_runPreProcessor($record); if (is_array($xml) || is_object($xml)) { throw new XML_Query2XML_XMLException( $this->_configPath . 'XML_Query2XML_Command_Unserialize: string ' . 'expected from pre-processor, but ' . gettype($xml) . ' returned.' ); } else { if (strlen($xml)) { if (!@$doc->loadXML($xml)) { throw new XML_Query2XML_XMLException( $this->_configPath . 'XML_Query2XML_Command_Unserialize: ' . 'Could not unserialize the following XML data: "' . $xml . '"' ); } return $doc->documentElement; } else { return null; } } } } ?>
« previous php.pear.cvs (#48611) next »