Author: sb
Date: Sun Jan 20 08:59:09 2008
New Revision: 7191

Log:
- Separate file i/o from XML processing.

Modified:
    trunk/Workflow/ChangeLog
    trunk/Workflow/src/definition_storage/xml.php

Modified: trunk/Workflow/ChangeLog
==============================================================================
--- trunk/Workflow/ChangeLog [iso-8859-1] (original)
+++ trunk/Workflow/ChangeLog [iso-8859-1] Sun Jan 20 08:59:09 2008
@@ -1,3 +1,6 @@
+- Implemented issue #12404: Separate file i/o from XML processing in
+  ezcWorkflowDefinitionStorageXml.
+
 1.1 - Monday 17 December 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] Sun Jan 20 
08:59:09 2008
@@ -41,12 +41,13 @@
     }
 
     /**
-     * Load a workflow definition by name.
-     *
-     * If the parameter $workflowVersion is omitted the most recent version is 
loaded.
-     *
-     * @param  string  $workflowName
-     * @param  int $workflowVersion
+     * Load a workflow definition from a file.
+     *
+     * When the $workflowVersion argument is omitted,
+     * the most recent version is loaded.
+     *
+     * @param  string $workflowName
+     * @param  int    $workflowVersion
      * @return ezcWorkflow
      * @throws ezcWorkflowDefinitionStorageException
      */
@@ -99,6 +100,20 @@
               )
             );
         }
+
+        return $this->loadFromDocument( $document );
+    }
+
+    /**
+     * Load a workflow definition from a DOMDocument.
+     *
+     * @param  DOMDocument $document
+     * @return ezcWorkflow
+     */
+    public function loadFromDocument( DOMDocument $document )
+    {
+        $workflowName    = $document->documentElement->getAttribute('name');
+        $workflowVersion = 
(int)$document->documentElement->getAttribute('version');
 
         // Create node objects.
         $nodes = array();
@@ -160,7 +175,7 @@
                             }
                         }
 
-                        $condition = $this->xmlToCondition( $childNode );
+                        $condition = self::xmlToCondition( $childNode );
 
                         foreach ( $childNode->getElementsByTagName( 'outNode' 
) as $outNode )
                         {
@@ -208,7 +223,7 @@
     }
 
     /**
-     * Save a workflow definition.
+     * Save a workflow definition to a file.
      *
      * @param  ezcWorkflow $workflow
      * @throws ezcWorkflowDefinitionStorageException
@@ -216,8 +231,21 @@
     public function save( ezcWorkflow $workflow )
     {
         $workflowVersion = $this->getCurrentVersion( $workflow->name ) + 1;
-        $filename = $this->getFilename( $workflow->name, $workflowVersion );
-
+        $filename        = $this->getFilename( $workflow->name, 
$workflowVersion );
+        $document        = $this->saveToDocument( $workflow, $workflowVersion 
);
+
+        file_put_contents( $filename, $document->saveXML() );
+    }
+
+    /**
+     * Save a workflow definition to a DOMDocument.
+     *
+     * @param  ezcWorkflow $workflow
+     * @param  int         $workflowVersion
+     * @return DOMDocument
+     */
+    public function saveToDocument( ezcWorkflow $workflow, $workflowVersion )
+    {
         $document = new DOMDocument( '1.0', 'UTF-8' );
         $document->formatOutput = true;
 
@@ -302,7 +330,7 @@
             $variableHandler->setAttribute( 'class', $class );
         }
 
-        file_put_contents( $filename, $document->saveXML() );
+        return $document;
     }
 
     /**


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to