kolibri-discuss team mailing list archive
-
kolibri-discuss team
-
Mailing list archive
-
Message #00026
[Merge] lp:~frode-danielsen/kolibri/xml-generator-rewrite into lp:kolibri
Frode Danielsen has proposed merging lp:~frode-danielsen/kolibri/xml-generator-rewrite into lp:kolibri.
Requested reviews:
Kolibri Dev (kolibri-dev)
--
https://code.launchpad.net/~frode-danielsen/kolibri/xml-generator-rewrite/+merge/5284
Your team Kolibri Discuss is subscribed to branch lp:kolibri.
=== modified file 'examples/wishlist/views/error.php'
--- examples/wishlist/views/error.php 2009-02-22 02:42:02 +0000
+++ examples/wishlist/views/error.php 2009-04-03 16:04:34 +0000
@@ -51,7 +51,7 @@
</pre>
<h2>Request</h2>
<pre>
-<?php echo print_vars($request->expose()) ?>
+<?php echo print_vars($request) ?>
</pre>
<h2>Action Variables</h2>
<pre>
=== modified file 'src/conf/autoload.php'
--- src/conf/autoload.php 2008-12-08 20:36:09 +0000
+++ src/conf/autoload.php 2009-04-03 16:04:34 +0000
@@ -33,6 +33,7 @@
'DataProvided' => '/models/DataProvided.php',
'ModelProxy' => '/models/ModelProxy.php',
'Models' => '/models/Models.php',
+ 'Proxy' => '/models/Proxy.php',
'Validateable' => '/models/Validateable.php',
'ValidateableModelProxy' => '/models/ValidateableModelProxy.php',
'AbstractResult' => '/results/AbstractResult.php',
=== modified file 'src/core/Request.php'
--- src/core/Request.php 2008-12-09 23:12:48 +0000
+++ src/core/Request.php 2009-04-03 16:04:34 +0000
@@ -4,24 +4,24 @@
* made available through convenience methods, as well as the complete URI and method of the
* request.
*/
-class Request implements ArrayAccess, IteratorAggregate {
+class Request implements ArrayAccess {
/**
* Request URI.
* @var string
*/
- private $uri;
+ public $uri;
/**
* Request parameters.
* @var array
*/
- private $params;
+ public $params;
/**
* HTTP method for this request.
* @var string
*/
- private $method;
+ public $method;
/**
* Creates an instance of this class. GET and POST parameters are merged. If any parameter keys
@@ -84,15 +84,6 @@
}
/**
- * Returns a default iterator which enables iterating over request parameters.
- *
- * @return ArrayIterator
- */
- public function getIterator () {
- return new ArrayIterator($this->params);
- }
-
- /**
* Returns the value of the parameter with the specified key, or <code>NULL</code> if the parameter is
* not found.
*
@@ -139,22 +130,5 @@
public function putAll ($params) {
$this->params = array_merge($this->params, $params);
}
-
- /**
- * Defines our custom hierarchy when exposing this object. The reason we want a different structure
- * is to provide easy access to request parameters in views. Instead of accessing request/params/foo,
- * users can more simply use params/foo. Request-specific meta-data resides under the request/ element.
- *
- * @return array Exposed structure of this object.
- */
- public function expose () {
- return array(
- 'request' => array(
- 'uri' => $this->uri,
- 'method' => $this->method
- ),
- 'params' => $this->params
- );
- }
}
?>
=== modified file 'src/database/ObjectBuilder.php'
--- src/database/ObjectBuilder.php 2009-03-27 23:31:04 +0000
+++ src/database/ObjectBuilder.php 2009-04-03 16:00:20 +0000
@@ -258,13 +258,15 @@
* <code>FALSE</code> if not.
*/
private function populateObject ($object, $row) {
+ if ($object instanceof Container) return false;
+
$objClass = get_class($object);
/*
* If we have not yet cached the primary key of this object type, we do so here.
* Container need not be evaluated as it isn't an actual model.
*/
- if (!isset($this->primaryKeys[$objClass]) && !$object instanceof Container) {
+ if (!isset($this->primaryKeys[$objClass])) {
$reflection = new ReflectionObject($object);
if (!$reflection->hasConstant('PK')) {
throw new Exception("No primary key defined for model of type $objClass. "
=== modified file 'src/interceptors/ModelInterceptor.php'
--- src/interceptors/ModelInterceptor.php 2008-10-20 16:41:10 +0000
+++ src/interceptors/ModelInterceptor.php 2009-04-03 16:04:34 +0000
@@ -27,7 +27,8 @@
$model = $this->instantiateModel($action->model);
}
- foreach ($dispatcher->getRequest() as $param => $value) {
+ $params = $dispatcher->getRequest()->getAll();
+ foreach ($params as $param => $value) {
if (strpos($param, '::') !== false) {
// Parameter is a property path to inner models. Explode the path and populate.
$exploded = explode('::', $param);
=== modified file 'src/interceptors/ParametersInterceptor.php'
--- src/interceptors/ParametersInterceptor.php 2008-10-20 16:41:10 +0000
+++ src/interceptors/ParametersInterceptor.php 2009-04-03 16:04:34 +0000
@@ -17,7 +17,7 @@
$this->populate($action, $action->session);
}
- $this->populate($action, $dispatcher->getRequest());
+ $this->populate($action, $dispatcher->getRequest()->getAll());
}
return $dispatcher->invoke();
=== modified file 'src/lib/ErrorHandler.php'
--- src/lib/ErrorHandler.php 2009-02-22 02:42:02 +0000
+++ src/lib/ErrorHandler.php 2009-04-03 16:04:34 +0000
@@ -97,7 +97,7 @@
{$exception}
Request:
-{$this->getVars($this->request->expose())}
+{$this->getVars($this->request)}
Action Variables:
{$this->getVars($this->action)}
=== modified file 'src/lib/XmlGenerator.php'
--- src/lib/XmlGenerator.php 2008-12-09 23:12:48 +0000
+++ src/lib/XmlGenerator.php 2009-04-07 13:13:17 +0000
@@ -1,245 +1,225 @@
<?php
/**
- * Generates XML from PHP data structures.
- *
- * @version $Id: XmlGenerator.php 1552 2008-09-19 12:49:04Z frode $
+ * Generates XML from PHP data structures. Everything is automatically wrapped in a root element, named
+ * 'result' by default. After creating an instance of the XmlGenerator, you add all the data you want
+ * through the append() method. Everything from objects to arrays and pure scalar values are supported.
+ * The only PHP data type that is not supported, and probably won't be, is the abstract 'resource' data type.
+ * Finally you call getXml() to get a string representation of the XML version of your data, or getDom()
+ * to get the DOMDocument directly (useful for utilizing the result with other XML technologies like XSLT).
*/
class XmlGenerator {
private $document;
- private $data;
/**
- * Creates a new XML generator and creates a new DOM tree with the correct
- * DOM interface for the running PHP version.
+ * Creates a new XML generator. An XML document is immediately created with a root element.
*
- * @param mixed $data Optional data to generate XML from. See XmlGenerator::append().
+ * @param string $rootElement Name of the document's root element, defaults to 'result'.
*/
- public function __construct ($data = null) {
+ public function __construct ($rootElement = 'result') {
$this->document = new DOMDocument('1.0', 'utf-8');
- $this->data = array();
- if ($data !== null) {
- $this->append($data);
- }
- }
-
- /**
- * Appends data to the list of data for which the generator should build XML from.
- *
- * @param mixed $data The new data to append. If index is specified, the data is stored
- * under the same index internally to represent a specific child element
- * name. Otherwise, if the data is an array, it is merged with the
- * internal data array, if not it is appended sequentially.
- * The internal data array represents the children of the XML document's
- * root element.
- * @param string $index An optional index to store the data in, which will be used as the
- * element name for the data's containing element in the XML tree.
- * @param bool $collapse <code>TRUE</code> if the <code>data</code> should be flattened if it
- * is an object, <code>FALSE</<code> if not.
- */
- public function append ($data, $index = null, $collapse = false) {
- if ($collapse) {
- if (is_object($data)) {
- if (method_exists($data, 'expose')) {
- $data = $data->expose();
- }
- else {
- $objData = array();
- foreach ($data as $key => $value) {
- $objData[$key] = $value;
- }
-
- $data = $objData;
- }
- }
- }
-
- if ($index !== null) {
- $this->data[$index] = $data;
- }
- else {
- if (is_array($data)) {
- $this->data = array_merge($this->data, $data);
- }
- else {
- $this->data[] = $data;
- }
- }
- }
-
- /**
- * Builds the DOM tree and returns an XML representation of the data.
- *
- * @param mixed $data The PHP data variables to generate XML from.
- * @param string $rootElement The name of the generated documents root element.
- * If not supplied, the generator will make an educated guess
- * from the data variables, or use a default name.
- * @return string An XML representation of the PHP data variables, as a string.
- */
- public function build ($rootElement = 'result') {
- $root = $this->buildArray($this->data, $rootElement, true);
- $this->document->appendChild($root);
-
+ try {
+ $root = $this->document->createElement($rootElement);
+ $this->document->appendChild($root);
+ }
+ catch (DOMException $e) {
+ throw new Exception("Invalid name for the XML document's root element: $rootElement");
+ }
+ }
+
+ /**
+ * @return DOMDocument The DOMDocument for the generated XML structure.
+ */
+ public function getDom () {
+ return $this->document;
+ }
+
+ /**
+ * @return string The generated XML as a string.
+ */
+ public function getXml () {
return $this->document->saveXML();
}
/**
- * Builds an XML representation of a PHP array.
+ * Adds more data to the XML document. If you specify a container name, the data will be wrapped
+ * in an XML element of that name. Otherwise the element name for the data will be inferred from
+ * the type of data. An object will get it's element name from it's class name. An array will be
+ * wrapped in an <array> element, and scalar values will be wrapped in elements named after the scalar
+ * type, ie. <boolean> or <number>.
*
- * @param array $array The array to convert to a DOM fragment.
- * @param string $container Name of the containing XML element for the array elements.
- * @param bool $keepIndices Indicates whether to keep indices specified in the array, or
- * if object types takes precedence.
- * @return DOMNode An XML node representing the array for appending in a DOM tree.
+ * @param mixed $data The data to add. Any PHP data type can be added except for the abstract
+ * resource data type.
+ * @param string $container An optional name of the containing element for the data value. Defaults
+ * to a name inferred from the data type.
*/
- private function buildArray ($array, $container = null, $keepIndices = false) {
+ public function append ($data, $container = null) {
+ // If no container element name is specified, append directly to the root element
if ($container === null) {
- $container = 'data';
- }
-
- $node = $this->document->createElement($container);//strtolower($container));
-
- foreach ($array as $key => $value) {
- // Skip empty elements.
- if (!is_object($value) && !is_array($value) && !is_bool($value)
- && ($value === null || $value === '')) continue;
-
- // Set childs element name if key is non-numeric and indices are to be kept
- if ((!$keepIndices && is_object($value)) || is_numeric($key)) {
- $elementName = null;
- }
- else {
- $elementName = str_replace('::', '-', $key);//strtolower($key);
- }
-
- if (is_scalar($value)) {
- // Create a new child node from a scalar value: string, number or boolean
- $child = $this->buildAtomic($value, $elementName);
- }
+ $container = $this->document->documentElement;
+ }
+ else if (!is_string($container)) {
+ throw new Exception('Containing element name must be a string.');
+ }
+
+ $resultNode = $this->build($data, $container);
+
+ // When a container element is specified we need to append it to the root element after it's created
+ if ($resultNode !== null && $resultNode !== $container) {
+ $this->document->documentElement->appendChild($resultNode);
+ }
+ }
+
+ /**
+ * Main entry point for building the XML structure out of PHP data structures. Distinguishes between
+ * PHP data types as either scalar or complex and calls appropriate methods for building the XML.
+ *
+ * @return DOMElement A single DOMElement containing all non-NULL data in the data supplied, or NULL
+ * if the build resulted in an empty element.
+ */
+ private function build ($data, $container) {
+ // "Short circuit" if the data is scalar
+ if (is_scalar($data)) {
+ return $this->buildScalar($data, $container);
+ }
+
+ // Prepare the containing element
+ if (is_string($container)) {
+ $container = $this->createElement($container);
+ }
+
+ $dataIsObject = is_object($data);
+
+ // Extract data from a proxy explicitly
+ if ($dataIsObject && ($data instanceof Proxy)) {
+ $data = $data->extract();
+ // Re-evaluate type of data, extract() can return an array
+ $dataIsObject = is_object($data);
+ }
+
+ $this->buildComplex($data, $container, $dataIsObject);
+
+ return ($container->hasChildNodes() ? $container : null);
+ }
+
+ /**
+ * Builds arrays and objects, known as complex data types.
+ */
+ private function buildComplex ($data, $container, $isObject = false) {
+ // Iterate through the array values or object properties
+ foreach ($data as $key => $value) {
+ // Skip NULL values and empty strings
+ if ($value === null || $value === '') continue;
+
+ // Use property name as key when building an object
+ if ($isObject) {
+ $elementName = $this->normalizeElementName($key);
+ }
+ // Use class name as element name for objects in an array
else if (is_object($value)) {
- // Create a new child node from an object
- $child = $this->buildObject($value, $elementName);
- }
- else if (is_array($value)) {
- // Create a new child node from an array
- $child = $this->buildArray($value, $elementName);
- }
+ $elementName = get_class($value);
+ }
+ // Try to use array key if it is a string (not numeric)
+ else if (is_string($key)) {
+ $elementName = $key;
+ }
+ // Data is an array and we've found no fitting element name, use default
else {
- // Array item is of unsupported data type (i.e. resource or function)
- $child = null;
- }
-
- if (!empty($child)) {
- $node->appendChild($child);
- }
- }
-
- return ($node->hasChildNodes() ? $node : null);
- }
-
- /**
- * Builds an XML representation of a PHP object.
- *
- * @param object $object The object to convert to a DOM fragment.
- * @param string $container Name of the containing XML element for the objects attributes.
- * @return DOMNode An XML node representing the object for appending in a DOM tree.
- */
- private function buildObject ($object, $container = null) {
- // Default element name for the containing element is the objects class.
- if ($container === null) {
- $container = get_class($object);
- }
-
- if (method_exists($object, 'expose')) {
- // Object prefers to decide its own DOM structure
- $vars = $object->expose();
- }
- else {
- // Fetch all of the object's attributes
- $objData = array();
- foreach ($object as $key => $value) {
- $objData[$key] = $value;
- }
-
- $vars = $objData;
- }
-
- // If object was empty, don't build XML representation
- if (empty($vars)) {
- return null;
- }
-
- // Now we have a simple array to build
- return $this->buildArray($vars, $container, true);
+ $elementName = 'array';
+ }
+
+ $element = $this->build($value, $elementName);
+
+ if ($element !== null) {
+ $container->appendChild($element);
+ }
+ }
}
/**
* Builds an XML representation of an atomic PHP variable (number, boolean or string).
*
- * @param mixed $value A number, boolean or string.
- * @param string $name An optional name for the containing XML element, otherwise a generic
- * name is used to describe the content.
- * @return DOMElement An XML element representing the variable for appending in a DOM tree.
+ * @param mixed $value A number, boolean or string.
+ * @param string $name An optional name for the containing XML element, otherwise a generic
+ * name is used to describe the content.
+ * @return DOMElement An XML element representing the variable for appending in a DOM tree.
*/
- private function buildAtomic ($value, $name = null) {
- if ($name === null) {
- if (is_numeric($value)) {
- $name = 'number';
- }
- else if (is_bool($value)) {
- $name = 'boolean';
- }
- else {
- $name = 'string';
- }
+ private function buildScalar ($value, $name = null) {
+ if (is_string($name)) {
+ $name = $this->normalizeElementName($name);
+ }
+ else if (is_numeric($value)) {
+ $name = 'number';
+ }
+ else if (is_bool($value)) {
+ $name = 'boolean';
}
else {
- $name = str_replace('::', '-', $name);//$name;//strtolower($name);
+ $name = 'string';
}
- $element = $this->document->createElement($name);
-
- if ($this->isXml($value)) {
+ /**
+ * Perform a simple test on string values to see if they're likely to be XML data.
+ * If so we wrap in a CDATA section to prevent < and > from being escaped, keeping the
+ * XML data intact.
+ */
+ if (is_string($value) && $this->isXml($value)) {
$child = $this->document->createCDATASection($value);
}
else {
+ // We convert booleans to text values here, so they won't be subject to isXml tests
if (is_bool($value)) {
$value = ($value ? 'true' : 'false');
}
$child = $this->document->createTextNode($value);
}
-
+
+ $element = $this->createElement($name);
$element->appendChild($child);
return $element;
}
-
- /**
- * Checks if a string is XML data. The default is to do a complete parse of the string to see that it is
- * well formed as well. Otherwise it will just check to see if the string starts and ends with < and >
- * respectively.
- *
- * @param string $value The string value to check.
- * @param boolean $checkWellFormed If <code>TRUE</code> the string will also be tried
- * to parse as XML to see if it's also well formed. If
- * <code>FALSE</code> only a probability test is done to evaluate
- * if the string is XML. Default is <code>FALSE</code>.
- * @return bool <code>TRUE</code> if the string is XML data, <code>FALSE</code>
- * if not.
- */
- private function isXml ($value, $checkWellFormed = false) {
- if (is_string($value) && substr($value, 0, 1) == '<' && substr($value, -1) == '>') {
- if ($checkWellFormed) {
- $parser = xml_parser_create('utf-8');
- $retval = xml_parse($parser, $value, true);
- xml_parser_free($parser);
-
- return ($retval == 0);
- }
- else return true;
- }
-
- return false;
+
+ /**
+ * Wrapper for creating a DOM element and catching any exceptions for invalid characters in
+ * element name etc.
+ *
+ * @throws Exception Invalid characters in element name will throw exception.
+ * @param string $name The name of the element to create.
+ * @return DOMElement The created DOMElement.
+ */
+ private function createElement ($name) {
+ try {
+ $element = $this->document->createElement($name);
+ }
+ catch (DOMException $e) {
+ throw new Exception("Invalid character in XML element name: $name");
+ }
+
+ return $element;
+ }
+
+ /**
+ * Extremely simple normalization for now. Since we support :: in request parameter names for
+ * indicating object hierarchy we need to replace this with a valid XML element name character.
+ *
+ * @param string $name Name to normalize.
+ * @return string The normalized name.
+ */
+ private function normalizeElementName ($name) {
+ return str_replace('::', '-', $name);
+ }
+
+ /**
+ * Checks if a string is likely to be XML data. It simply checks to see if the string starts
+ * and ends with < and > respectively.
+ *
+ * @param string $value The string value to check.
+ * @return bool <code>TRUE</code> if the string is XML data, <code>FALSE</code> if not.
+ */
+ private function isXml ($value) {
+ $value = trim($value);
+ return (substr($value, 0, 1) == '<' && substr($value, -1) == '>');
}
}
?>
=== modified file 'src/lib/XslTransformer.php'
--- src/lib/XslTransformer.php 2008-12-17 15:50:47 +0000
+++ src/lib/XslTransformer.php 2009-04-07 13:13:17 +0000
@@ -1,13 +1,10 @@
<?php
-import('strings', 'util');
-
/**
* This class provides an abstraction of the XSL transformation capabilities in PHP 5.
*/
class XslTransformer {
private $stylesheet;
- private $xmlData;
- private $parameters;
+ private $processors;
/**
* Creates a new XSL transformer with a stylesheet to transform data with.
@@ -16,28 +13,13 @@
* @return XslTransformer
*/
public function __construct ($xsl) {
+ if (!file_exists($xsl)) {
+ throw new Exception("XSL template does not exist: $xsl");
+ }
+
$this->stylesheet = new DOMDocument();
$this->stylesheet->load($xsl);
- }
-
- /**
- * Adds XML data from a string or a file.
- *
- * @param string $xml XML data or path to XML file.
- * @param bool $isFile Is $xml a file name? Defaults to <code>FALSE</code>.
- */
- public function addXml ($xml, $isFile = false) {
- if ($isFile) {
- if (file_exists($xml)) {
- $xml = file_get_contents($xml);
- }
- else {
- throw new Exception("XML file ($xml) does not exist, no data to transform");
- }
- }
-
- $this->xmlData = new DOMDocument();
- $this->xmlData->loadXml($xml);
+ $this->processor = new XSLTProcessor();
}
/**
@@ -47,7 +29,7 @@
* @param string $value Value of the parameter to add.
*/
public function addParameter ($name, $value) {
- $this->parameters[$name] = $value;
+ $this->processor->setParameter('', $name, $value);
}
/**
@@ -55,15 +37,13 @@
*
* @return string The XML result from the XSL transformation as a string.
*/
- public function process () {
- $processor = new XSLTProcessor();
- $processor->importStyleSheet($this->stylesheet);
-
- if (is_array($this->parameters)) {
- $processor->setParameter('', $this->parameters);
+ public function process ($dom) {
+ if (!$dom instanceof DOMDocument) {
+ throw new Exception('Data to transform is not a DOMDocument.');
}
-
- return $processor->transformToXML($this->xmlData);
+
+ $this->processor->importStyleSheet($this->stylesheet);
+ return $this->processor->transformToXML($dom);
}
}
?>
=== modified file 'src/models/ModelProxy.php'
--- src/models/ModelProxy.php 2009-02-22 03:44:58 +0000
+++ src/models/ModelProxy.php 2009-04-03 16:04:34 +0000
@@ -24,7 +24,7 @@
* This class also implements <code>ArrayAccess</code> and <code>IteratorAggregates</code> which
* makes it possible to treat the collection of models in the proxy as if it was a regular array.
*/
-class ModelProxy implements ArrayAccess, IteratorAggregate, Countable {
+class ModelProxy implements ArrayAccess, IteratorAggregate, Countable, Proxy {
/**
* Provides access to the data access object of the model.
* @var DataAccessProxy
@@ -314,22 +314,6 @@
}
/**
- * Exposes the models.
- *
- * If only a single model is held, it is returned as a single object. Else the model array itself is
- * returned in its existing key-value structure.
- *
- * @return mixed One or more models for exposure.
- */
- public function expose () {
- if (isset($this->current)) {
- return $this->current;
- }
-
- return $this->models;
- }
-
- /**
* Extracts the models contained in this proxy. This is useful when you want to pass the models
* onto some other model or facility without the proxy functionality.
*
=== added file 'src/models/Proxy.php'
--- src/models/Proxy.php 1970-01-01 00:00:00 +0000
+++ src/models/Proxy.php 2009-04-03 16:04:34 +0000
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Interface to indicate that an object is a proxy for one or more objects.
+ * When a proxy proxies only one object, it's contents should not be treated
+ * as an array of objects. Even though iterating over the proxy will mean iterating
+ * over an array of one or more objects.
+ * See XmlGenerator for an example of how a single object proxy has it's proxied object extracted
+ * before iterating over properties, instead of iterating over the proxy itself directly.
+ */
+interface Proxy {
+ public function extract ();
+}
+?>
\ No newline at end of file
=== modified file 'src/results/AbstractResult.php'
--- src/results/AbstractResult.php 2008-12-10 01:54:56 +0000
+++ src/results/AbstractResult.php 2009-04-03 16:04:34 +0000
@@ -4,9 +4,9 @@
* request performed, and a response will usually be rendered to the client over HTTP.
*/
abstract class AbstractResult implements Result {
- private $action;
- private $contentType;
- private $charset;
+ protected $action;
+ protected $contentType;
+ protected $charset;
/**
* Constructor.
@@ -39,10 +39,6 @@
* @return array Data from the action.
*/
public function getActionData () {
- if (method_exists($this->action, 'expose')) {
- return $action->expose();
- }
-
$data = array();
foreach ($this->action as $key => $value) {
$data[$key] = $value;
=== modified file 'src/results/XsltResult.php'
--- src/results/XsltResult.php 2008-12-17 15:50:47 +0000
+++ src/results/XsltResult.php 2009-04-07 13:13:17 +0000
@@ -1,8 +1,8 @@
<?php
/**
- * Provides the implementation of a result set using XSLT to render the data as XHTML.
+ * Provides the implementation of a result using XSLT to render the data.
*
- * @version $Id: XsltResult.php 1538 2008-08-03 22:10:45Z anders $
+ * @version $Id$
*/
class XsltResult extends AbstractResult {
private $xslTemplate;
@@ -14,42 +14,33 @@
* @param string $xslTemplate Name of XSL file (excluding the extension) to use, relative to
* the views-directory.
*/
- public function __construct ($action, $xslTemplate, $title = null) {
+ public function __construct ($action, $xslTemplate) {
parent::__construct($action);
$this->xslTemplate = VIEW_PATH . "$xslTemplate.xsl";
- if (!file_exists($this->xslTemplate)) {
- throw new Exception("XSL template ({$this->xslTemplate}) does not exist");
- }
}
/**
* Performs the XSL transformations on the XML-data and outputs it.
*/
public function render ($request) {
+ // Convert the request and action data to XML for XSL transformation
$xmlGenerator = new XmlGenerator();
-
- /*
- * Append the action and request "flattened", because we don't want them wrapped in their own
- * elements.
- */
- $xmlGenerator->append($this->getAction(), null, true);
- $xmlGenerator->append($request, null, true);
-
- $xml = $xmlGenerator->build();
-
+ // Wrap request data in a containing element, <request />
+ $xmlGenerator->append($request, 'request');
+ // Append all action data directly to the root result element
+ $xmlGenerator->append($this->action);
+
$transformer = new XslTransformer($this->xslTemplate);
- $transformer->addXml($xml);
- // Add config params to XSLT as parameters
- $config = Config::get();
- foreach ($config as $key => $value) {
+ // Add scalar config params to XSLT as parameters
+ foreach (Config::get() as $key => $value) {
if (!is_array($value)) {
$transformer->addParameter($key, $value);
}
}
- echo $transformer->process();
+ echo $transformer->process($xmlGenerator->getDom());
}
}
?>
=== modified file 'src/views/error.php'
--- src/views/error.php 2009-02-22 02:42:02 +0000
+++ src/views/error.php 2009-04-03 16:04:34 +0000
@@ -51,7 +51,7 @@
</pre>
<h2>Request</h2>
<pre>
-<?php echo print_vars($request->expose()) ?>
+<?php echo print_vars($request) ?>
</pre>
<h2>Action Variables</h2>
<pre>
Follow ups