Author: sb
Date: Fri Aug 3 08:26:04 2007
New Revision: 5811
Log:
- New ezcWorkflowDefinitionStorageXml implementation.
Modified:
trunk/Workflow/ChangeLog
trunk/Workflow/src/definition_storage/xml.php
trunk/Workflow/src/interfaces/node.php
trunk/Workflow/src/nodes/action.php
trunk/Workflow/src/nodes/sub_workflow.php
trunk/Workflow/src/nodes/variables/add.php
trunk/Workflow/src/nodes/variables/decrement.php
trunk/Workflow/src/nodes/variables/div.php
trunk/Workflow/src/nodes/variables/increment.php
trunk/Workflow/src/nodes/variables/input.php
trunk/Workflow/src/nodes/variables/mul.php
trunk/Workflow/src/nodes/variables/set.php
trunk/Workflow/src/nodes/variables/sub.php
trunk/Workflow/src/nodes/variables/unset.php
trunk/Workflow/tests/definition_xml_test.php
Modified: trunk/Workflow/ChangeLog
==============================================================================
--- trunk/Workflow/ChangeLog [iso-8859-1] (original)
+++ trunk/Workflow/ChangeLog [iso-8859-1] Fri Aug 3 08:26:04 2007
@@ -1,4 +1,9 @@
- Added ezcWorkflowNodeLoop class to conveniently express loops.
+- Refactored the XML definition storage.
+ - DOM is now used for both the loading and saving of workflows (issue
#10702).
+ - The marshalling of the node configuration is now handled in the individual
+ node classes. This makes it possible to have custom node classes handled by
+ the XML definition storage.
- Fixed issue #11068: Implement ezcWorkflowExecution::hasVariable().
1.0.1 - Monday 30 July 2007
Modified: trunk/Workflow/src/definition_storage/xml.php
==============================================================================
--- trunk/Workflow/src/definition_storage/xml.php [iso-8859-1] (original)
+++ trunk/Workflow/src/definition_storage/xml.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -59,9 +59,12 @@
}
$filename = $this->getFilename( $workflowName, $workflowVersion );
- $document = @simplexml_load_file( $filename );
-
- if ( $document === false )
+
+ // Load the document.
+ $document = new DOMDocument;
+ $loaded = @$document->load( $filename );
+
+ if ( $loaded === false )
{
throw new ezcWorkflowDefinitionStorageException(
sprintf(
@@ -73,135 +76,63 @@
);
}
+ // Create node objects.
$nodes = array();
- // Create node objects.
- foreach ( $document->node as $node )
- {
- $id = (int)$node['id'];
- $class = 'ezcWorkflowNode' . (string)$node['type'];
-
+ foreach ( $document->getElementsByTagName( 'node' ) as $node )
+ {
+ $id = (int)$node->getAttribute( 'id' );
+ $className = 'ezcWorkflowNode' . $node->getAttribute( 'type' );
$configuration = '';
- switch ( $class )
- {
- case 'ezcWorkflowNodeAction':
- {
- $configuration = array(
- 'class' => (string)$node['serviceObjectClass'],
- 'arguments' => array()
- );
-
- $arguments = $node->arguments->children();
-
- if ( @count( $arguments ) > 0 )
+ if ( class_exists( $className ) )
+ {
+ $configuration = call_user_func_array(
+ array( $className, 'configurationFromXML' ), array( $node )
+ );
+ }
+
+ $nodes[$id] = new $className( $configuration );
+ $nodes[$id]->setId( $id );
+
+ if ( $className == 'ezcWorkflowNodeStart' )
+ {
+ $startNode = $nodes[$id];
+ }
+
+ else if ( $className == 'ezcWorkflowNodeEnd' &&
+ !isset( $defaultEndNode ) )
+ {
+ $defaultEndNode = $nodes[$id];
+ }
+ }
+
+ // Connect node objects.
+ foreach ( $document->getElementsByTagName( 'node' ) as $node )
+ {
+ $id = (int)$node->getAttribute( 'id' );
+ $className = 'ezcWorkflowNode' . $node->getAttribute( 'type' );
+
+ foreach ( $node->getElementsByTagName( 'outNode' ) as $outNode )
+ {
+ $nodes[$id]->addOutNode( $nodes[(int)$outNode->getAttribute(
'id' )] );
+ }
+
+ if ( is_subclass_of( $className,
'ezcWorkflowNodeConditionalBranch' ) )
+ {
+ foreach ( $node->childNodes as $childNode )
+ {
+ if ( $childNode instanceof DOMElement &&
$childNode->tagName == 'condition' )
{
- foreach ( $arguments as $argument )
+ $condition = $this->xmlToCondition( $childNode );
+
+ foreach ( $childNode->getElementsByTagName( 'outNode'
) as $outNode )
{
- $configuration['arguments'][] =
$this->xmlToVariable( $argument );
+ $nodes[$id]->addConditionalOutNode(
+ $condition,
+ $nodes[(int)$outNode->getAttribute( 'id' )]
+ );
}
- }
- }
- break;
-
- case 'ezcWorkflowNodeInput':
- {
- $configuration = array();
-
- foreach ( $node->variable as $variable )
- {
- $configuration[(string)$variable['name']] =
$this->xmlToCondition( $variable->condition );
- }
- }
- break;
-
- case 'ezcWorkflowNodeSubWorkflow':
- {
- $configuration = (string)$node['subWorkflowName'];
- }
- break;
-
- case 'ezcWorkflowNodeVariableSet':
- {
- $configuration = array();
-
- foreach ( $node->variable as $variable )
- {
- $children = $variable->children();
- $configuration[(string)$variable['name']] =
$this->xmlToVariable( $children[0] );
- }
- }
- break;
-
- case 'ezcWorkflowNodeVariableUnset':
- {
- $configuration = array();
-
- foreach ( $node->variable as $variable )
- {
- $configuration[] = (string)$variable['name'];
- }
- }
- break;
-
- case 'ezcWorkflowNodeVariableAdd':
- case 'ezcWorkflowNodeVariableSub':
- case 'ezcWorkflowNodeVariableMul':
- case 'ezcWorkflowNodeVariableDiv':
- {
- $configuration = array(
- 'name' => (string)$node['variable'],
- 'operand' => (string)$node['operand']
- );
- }
- break;
-
- case 'ezcWorkflowNodeVariableIncrement':
- case 'ezcWorkflowNodeVariableDecrement':
- {
- $configuration = (string)$node['variable'];
- }
- break;
- }
-
- $nodes[$id] = new $class( $configuration );
- $nodes[$id]->setId( $id );
-
- if ( $class == 'ezcWorkflowNodeStart' )
- {
- $startNode = $nodes[$id];
- }
-
- else if ( $class == 'ezcWorkflowNodeEnd' &&
- !isset( $defaultEndNode ) )
- {
- $defaultEndNode = $nodes[$id];
- }
- }
-
- // Connect node objects.
- foreach ( $document->node as $node )
- {
- $class = 'ezcWorkflowNode' . (string)$node['type'];
- $id = (int)$node['id'];
-
- foreach ( $node->outNode as $outNode )
- {
- $nodes[$id]->addOutNode( $nodes[(int)$outNode['id']] );
- }
-
- if ( $class == 'ezcWorkflowNodeExclusiveChoice' || $class ==
'ezcWorkflowNodeMultiChoice' || $class == 'ezcWorkflowNodeLoop' )
- {
- foreach ( $node->condition as $conditionNode )
- {
- $condition = $this->xmlToCondition( $conditionNode );
-
- foreach ( $conditionNode->outNode as $outNode )
- {
- $nodes[$id]->addConditionalOutNode(
- $condition,
- $nodes[(int)$outNode['id']]
- );
}
}
}
@@ -210,14 +141,14 @@
// Create workflow object and add the node objects to it.
$workflow = new ezcWorkflow( $workflowName, $startNode,
$defaultEndNode );
$workflow->definitionStorage = $this;
- $workflow->version = (int)$workflowVersion;
+ $workflow->version = $workflowVersion;
// Handle the variable handlers.
- foreach ( $document->variableHandler as $node )
+ foreach ( $document->getElementsByTagName( 'variableHandler' ) as
$variableHandler )
{
$workflow->addVariableHandler(
- (string)$node['variable'],
- (string)$node['class']
+ $variableHandler->getAttribute( 'variable' ),
+ $variableHandler->getAttribute( 'class' )
);
}
@@ -255,117 +186,19 @@
for ( $i = 0; $i < $numNodes; $i++ )
{
- $id = $keys[$i];
- $node = $nodes[$id];
-
+ $id = $keys[$i];
+ $node = $nodes[$id];
$nodeClass = get_class( $node );
- $xmlNode = $root->appendChild( $document->createElement( 'node' )
);
+ $xmlNode = $document->createElement( 'node' );
$xmlNode->setAttribute( 'id', $id );
- $xmlNode->setAttribute( 'type', str_replace( 'ezcWorkflowNode',
'', $nodeClass ) );
-
- $configuration = $node->getConfiguration();
-
- switch ( $nodeClass )
- {
- case 'ezcWorkflowNodeAction':
- {
- $xmlNode->setAttribute( 'serviceObjectClass',
$configuration['class'] );
-
- if ( !empty( $configuration['arguments'] ) )
- {
- $xmlArguments = $xmlNode->appendChild(
- $document->createElement( 'arguments' )
- );
-
- foreach ( $configuration['arguments'] as $argument )
- {
- $xmlArguments->appendChild(
- $this->variableToXml(
- $argument,
- $document
- )
- );
- }
-
- $xmlNode->appendChild( $xmlArguments );
- }
- }
- break;
-
- case 'ezcWorkflowNodeInput':
- {
- foreach ( $configuration as $variable => $condition )
- {
- $xmlVariable = $xmlNode->appendChild(
- $document->createElement( 'variable' )
- );
-
- $xmlVariable->setAttribute( 'name', $variable );
-
- $xmlCondition = $this->conditionToXml(
- $condition,
- $document
- );
-
- $xmlVariable->appendChild( $xmlCondition );
- }
- }
- break;
-
- case 'ezcWorkflowNodeSubWorkflow':
- {
- $xmlNode->setAttribute( 'subWorkflowName', $configuration
);
- }
- break;
-
- case 'ezcWorkflowNodeVariableSet':
- {
- foreach ( $configuration as $variable => $value )
- {
- $xmlVariable = $xmlNode->appendChild(
- $document->createElement( 'variable' )
- );
-
- $xmlVariable->setAttribute( 'name', $variable );
-
- $xmlVariable->appendChild(
- $this->variableToXml( $value, $document )
- );
- }
- }
- break;
-
- case 'ezcWorkflowNodeVariableUnset':
- {
- foreach ( $configuration as $variable )
- {
- $xmlVariable = $xmlNode->appendChild(
- $document->createElement( 'variable' )
- );
-
- $xmlVariable->setAttribute( 'name', $variable );
- }
- }
- break;
-
- case 'ezcWorkflowNodeVariableAdd':
- case 'ezcWorkflowNodeVariableSub':
- case 'ezcWorkflowNodeVariableMul':
- case 'ezcWorkflowNodeVariableDiv':
- {
- $xmlNode->setAttribute( 'variable', $configuration['name']
);
- $xmlNode->setAttribute( 'operand',
$configuration['operand'] );
- }
- break;
-
- case 'ezcWorkflowNodeVariableIncrement':
- case 'ezcWorkflowNodeVariableDecrement':
- {
- $xmlNode->setAttribute( 'variable', $configuration );
- }
- break;
- }
+ $xmlNode->setAttribute(
+ 'type',
+ str_replace( 'ezcWorkflowNode', '', get_class( $node ) )
+ );
+
+ $node->configurationtoXML( $xmlNode );
+ $root->appendChild( $xmlNode );
foreach ( $node->getOutNodes() as $outNode )
{
@@ -380,12 +213,10 @@
$xmlOutNode = $document->createElement( 'outNode' );
$xmlOutNode->setAttribute( 'id', $outNodeId );
- if ( ( $nodeClass == 'ezcWorkflowNodeExclusiveChoice' ||
- $nodeClass == 'ezcWorkflowNodeMultiChoice' ||
- $nodeClass == 'ezcWorkflowNodeLoop' ) &&
- $condition = $node->getCondition( $outNode ) )
- {
- $xmlCondition = $this->conditionToXml(
+ if ( is_subclass_of( $nodeClass,
'ezcWorkflowNodeConditionalBranch' ) &&
+ $condition = $node->getCondition( $outNode ) )
+ {
+ $xmlCondition = self::conditionToXml(
$condition,
$document
);
@@ -420,7 +251,7 @@
* @param DOMDocument $document
* @return DOMElement
*/
- protected function conditionToXml( ezcWorkflowCondition $condition,
DOMDocument $document )
+ public static function conditionToXml( ezcWorkflowCondition $condition,
DOMDocument $document )
{
$xmlCondition = $document->createElement( 'condition' );
@@ -435,7 +266,7 @@
$xmlCondition->setAttribute( 'name',
$condition->getVariableName() );
$xmlCondition->appendChild(
- $this->conditionToXml( $condition->getCondition(),
$document )
+ self::conditionToXml( $condition->getCondition(), $document )
);
}
break;
@@ -446,7 +277,7 @@
foreach ( $condition->getConditions() as $childCondition )
{
$xmlCondition->appendChild(
- $this->conditionToXml( $childCondition, $document )
+ self::conditionToXml( $childCondition, $document )
);
}
}
@@ -454,7 +285,7 @@
case 'ezcWorkflowConditionNot': {
$xmlCondition->appendChild(
- $this->conditionToXml( $condition->getCondition(),
$document )
+ self::conditionToXml( $condition->getCondition(), $document )
);
}
break;
@@ -474,21 +305,21 @@
}
/**
- * "Convert" an SimpleXMLElement object into an ezcWorkflowCondition
object.
- *
- * @param SimpleXMLElement $node
+ * "Convert" an DOMElement object into an ezcWorkflowCondition object.
+ *
+ * @param DOMElement $element
* @return ezcWorkflowCondition
*/
- protected function xmlToCondition( SimpleXMLElement $node )
- {
- $class = 'ezcWorkflowCondition' . (string)$node['type'];
+ public static function xmlToCondition( DOMElement $element )
+ {
+ $class = 'ezcWorkflowCondition' . $element->getAttribute( 'type' );
switch ( $class )
{
case 'ezcWorkflowConditionVariable': {
return new $class(
- (string)$node['name'],
- $this->xmlToCondition( $node->condition )
+ $element->getAttribute( 'name' ),
+ self::xmlToCondition( $element->childNodes->item( 1 ) )
);
}
break;
@@ -498,9 +329,12 @@
case 'ezcWorkflowConditionXor': {
$conditions = array();
- foreach ( $node->condition as $condition )
- {
- $conditions[] = $this->xmlToCondition( $condition );
+ foreach ( $element->childNodes as $childNode )
+ {
+ if ( $childNode instanceof DOMElement &&
$childNode->tagName == 'condition' )
+ {
+ $conditions[] = self::xmlToCondition( $childNode );
+ }
}
return new $class( $conditions );
@@ -508,7 +342,7 @@
break;
case 'ezcWorkflowConditionNot': {
- return new $class( $this->xmlToCondition( $node->condition ) );
+ return new $class( self::xmlToCondition(
$element->childNodes->item( 1 ) ) );
}
break;
@@ -518,9 +352,7 @@
case 'ezcWorkflowConditionIsGreaterThan':
case 'ezcWorkflowConditionIsLessThan':
case 'ezcWorkflowConditionIsNotEqual': {
- $value = (string)$node['value'];
-
- return new $class( $value );
+ return new $class( $element->getAttribute( 'value' ) );
}
break;
@@ -538,7 +370,7 @@
* @param DOMDocument $document
* @return DOMElement
*/
- protected function variableToXml( $variable, DOMDocument $document )
+ public static function variableToXml( $variable, DOMDocument $document )
{
if ( is_array( $variable ) )
{
@@ -548,7 +380,7 @@
{
$element = $document->createElement( 'element' );
$element->setAttribute( 'key', $key );
- $element->appendChild( $this->variableToXml( $value, $document
) );
+ $element->appendChild( self::variableToXml( $value, $document
) );
$xmlResult->appendChild( $element );
}
@@ -581,40 +413,41 @@
}
/**
- * "Convert" an SimpleXMLElement object into a PHP variable.
- *
- * @param SimpleXMLElement $node
+ * "Convert" an DOMElement object into a PHP variable.
+ *
+ * @param DOMElement $element
* @return mixed
*/
- protected function xmlToVariable( SimpleXMLElement $node )
- {
- $type = $node->getName();
+ public static function xmlToVariable( DOMElement $element )
+ {
$variable = null;
- switch ( $type )
+ switch ( $element->tagName )
{
case 'array': {
$variable = array();
- foreach ( $node->element as $element )
- {
- $children = $element->children();
- $variable[(string)$element['key']] = $this->xmlToVariable(
$children[0] );
+ foreach ( $element->getElementsByTagName( 'element' ) as
$element )
+ {
+ $variable[(string)$element->getAttribute ('key') ] =
self::xmlToVariable( $element->childNodes->item( 1 ) );
}
}
break;
case 'object': {
- $className = (string)$node['class'];
-
- $arguments = $node->arguments->children();
- $constructorArgs = array();
-
- if ( @count( $arguments ) > 0 )
- {
+ $className = $element->getAttribute( 'class' );
+
+ if ( $element->hasChildNodes() )
+ {
+ $arguments = $element->childNodes->item( 1
)->childNodes;
+ $constructorArgs = array();
+
foreach ( $arguments as $argument )
{
- $constructorArgs[] = $this->xmlToVariable( $argument );
+ if ( $argument instanceof DOMElement )
+ {
+ $constructorArgs[] = self::xmlToVariable(
$argument );
+ }
}
$class = new ReflectionClass( $className );
@@ -630,18 +463,17 @@
break;
case 'boolean': {
- $variable = (string)$node == 'true' ? true : false;
+ $variable = $element->nodeValue == 'true' ? true : false;
}
break;
case 'integer':
case 'double':
case 'string': {
- $variable = (string)$node;
-
- settype( $variable, $type );
- }
- break;
+ $variable = $element->nodeValue;
+
+ settype( $variable, $element->tagName );
+ }
}
return $variable;
@@ -660,7 +492,7 @@
if ( !empty( $files ) )
{
- return str_replace(
+ return (int)str_replace(
array(
$this->directory . $workflowName . '_',
'.xml'
Modified: trunk/Workflow/src/interfaces/node.php
==============================================================================
--- trunk/Workflow/src/interfaces/node.php [iso-8859-1] (original)
+++ trunk/Workflow/src/interfaces/node.php [iso-8859-1] Fri Aug 3 08:26:04 2007
@@ -578,6 +578,24 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/action.php
==============================================================================
--- trunk/Workflow/src/nodes/action.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/action.php [iso-8859-1] Fri Aug 3 08:26:04 2007
@@ -125,6 +125,59 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ $configuration = array(
+ 'class' => $element->getAttribute( 'serviceObjectClass' ),
+ 'arguments' => array()
+ );
+
+ if ( $element->childNodes->item( 1 ) instanceof DOMElement &&
+ $element->childNodes->item( 1 )->tagName == 'arguments' )
+ {
+ foreach ( $element->childNodes->item( 1 )->childNodes as $argument
)
+ {
+ if ( $argument instanceof DOMElement )
+ {
+ $configuration['arguments'][] =
ezcWorkflowDefinitionStorageXml::xmlToVariable( $argument );
+ }
+ }
+ }
+
+ return $configuration;
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'serviceObjectClass',
$this->configuration['class'] );
+
+ if ( !empty( $this->configuration['arguments'] ) )
+ {
+ $xmlArguments = $element->appendChild(
+ $element->ownerDocument->createElement( 'arguments' )
+ );
+
+ foreach ( $this->configuration['arguments'] as $argument )
+ {
+ $xmlArguments->appendChild(
+ ezcWorkflowDefinitionStorageXml::variableToXml(
+ $argument, $element->ownerDocument
+ )
+ );
+ }
+ }
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/sub_workflow.php
==============================================================================
--- trunk/Workflow/src/nodes/sub_workflow.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/sub_workflow.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -115,6 +115,26 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return $element->getAttribute( 'subWorkflowName' );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'subWorkflowName', $this->configuration );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/add.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/add.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/add.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -38,6 +38,30 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return array(
+ 'name' => $element->getAttribute( 'variable' ),
+ 'operand' => $element->getAttribute( 'operand' )
+ );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration['name'] );
+ $element->setAttribute( 'operand', $this->configuration['operand'] );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/decrement.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/decrement.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/decrement.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -39,6 +39,26 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return $element->getAttribute( 'variable' );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/div.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/div.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/div.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -42,6 +42,30 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return array(
+ 'name' => $element->getAttribute( 'variable' ),
+ 'operand' => $element->getAttribute( 'operand' )
+ );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration['name'] );
+ $element->setAttribute( 'operand', $this->configuration['operand'] );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/increment.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/increment.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/increment.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -39,6 +39,26 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return $element->getAttribute( 'variable' );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/input.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/input.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/input.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -137,5 +137,45 @@
return false;
}
}
+
+ /**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ $configuration = array();
+
+ foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
+ {
+ $configuration[$variable->getAttribute( 'name' )] =
ezcWorkflowDefinitionStorageXml::xmlToCondition( $variable->childNodes->item( 1
) );
+ }
+
+ return $configuration;
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ foreach ( $this->configuration as $variable => $condition )
+ {
+ $xmlVariable = $element->appendChild(
+ $element->ownerDocument->createElement( 'variable' )
+ );
+
+ $xmlVariable->setAttribute( 'name', $variable );
+
+ $xmlVariable->appendChild(
+ ezcWorkflowDefinitionStorageXml::conditionToXml(
+ $condition, $element->ownerDocument
+ )
+ );
+ }
+ }
}
?>
Modified: trunk/Workflow/src/nodes/variables/mul.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/mul.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/mul.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -41,6 +41,30 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return array(
+ 'name' => $element->getAttribute( 'variable' ),
+ 'operand' => $element->getAttribute( 'operand' )
+ );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration['name'] );
+ $element->setAttribute( 'operand', $this->configuration['operand'] );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/set.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/set.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/set.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -65,6 +65,46 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ $configuration = array();
+
+ foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
+ {
+ $configuration[$variable->getAttribute( 'name' )] =
ezcWorkflowDefinitionStorageXml::xmlToVariable( $variable->childNodes->item( 1
) );
+ }
+
+ return $configuration;
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ foreach ( $this->configuration as $variable => $value )
+ {
+ $variableXml = $element->appendChild(
+ $element->ownerDocument->createElement( 'variable' )
+ );
+
+ $variableXml->setAttribute( 'name', $variable );
+
+ $variableXml->appendChild(
+ ezcWorkflowDefinitionStorageXml::variableToXml(
+ $value, $element->ownerDocument
+ )
+ );
+ }
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/sub.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/sub.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/sub.php [iso-8859-1] Fri Aug 3 08:26:04
2007
@@ -41,6 +41,30 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ return array(
+ 'name' => $element->getAttribute( 'variable' ),
+ 'operand' => $element->getAttribute( 'operand' )
+ );
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ $element->setAttribute( 'variable', $this->configuration['name'] );
+ $element->setAttribute( 'operand', $this->configuration['operand'] );
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/src/nodes/variables/unset.php
==============================================================================
--- trunk/Workflow/src/nodes/variables/unset.php [iso-8859-1] (original)
+++ trunk/Workflow/src/nodes/variables/unset.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -72,6 +72,40 @@
}
/**
+ * Generate node configuration from XML representation.
+ *
+ * @param DOMElement $element
+ */
+ public static function configurationFromXML( DOMElement $element )
+ {
+ $configuration = array();
+
+ foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
+ {
+ $configuration[] = $variable->getAttribute( 'name' );
+ }
+
+ return $configuration;
+ }
+
+ /**
+ * Generate XML representation of this node's configuration.
+ *
+ * @param DOMElement $element
+ */
+ public function configurationToXML( DOMElement $element )
+ {
+ foreach ( $this->configuration as $variable )
+ {
+ $variableXml = $element->appendChild(
+ $element->ownerDocument->createElement( 'variable' )
+ );
+
+ $variableXml->setAttribute( 'name', $variable );
+ }
+ }
+
+ /**
* Returns a textual representation of this node.
*
* @return string
Modified: trunk/Workflow/tests/definition_xml_test.php
==============================================================================
--- trunk/Workflow/tests/definition_xml_test.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/definition_xml_test.php [iso-8859-1] Fri Aug 3
08:26:04 2007
@@ -353,8 +353,6 @@
public function
testLoadExclusiveChoiceWithUnconditionalOutNodeSimpleMerge()
{
- $this->markTestIncomplete();
-
$this->workflow = $this->definition->loadByName(
'ExclusiveChoiceWithUnconditionalOutNodeSimpleMerge' );
$this->definition->save( $this->workflow );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components