addVariableHandler() публичный Метод

$className must be the name of a class implementing the ezcWorkflowVariableHandler interface.
public addVariableHandler ( string $variableName, string $className )
$variableName string
$className string
 public function testDeleteWorkflow()
 {
     $variableHandler = $this->getMock('ezcWorkflowVariableHandler');
     $workflow = new \ezcWorkflow('IdentityTest');
     $workflow->startNode->addOutNode($workflow->endNode);
     $workflow->addVariableHandler('foo', get_class($variableHandler));
     $manager = new WorkflowManager($this->conn, $this->options);
     $manager->save($workflow);
     $manager->deleteWorkflow($workflow->id);
     $this->setExpectedException('ezcWorkflowDefinitionStorageException', 'Could not load workflow definition.');
     $manager->loadWorkflowById($workflow->id);
 }
Пример #2
0
 /**
  * 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();
     $xmlNodes = $document->getElementsByTagName('node');
     foreach ($xmlNodes as $xmlNode) {
         $id = (int) $xmlNode->getAttribute('id');
         $className = 'ezcWorkflowNode' . $xmlNode->getAttribute('type');
         if (class_exists($className)) {
             $configuration = call_user_func_array(array($className, 'configurationFromXML'), array($xmlNode));
             if (is_null($configuration)) {
                 $configuration = ezcWorkflowUtil::getDefaultConfiguration($className);
             }
         }
         $node = new $className($configuration);
         $node->setId($id);
         if ($node instanceof ezcWorkflowNodeFinally && !isset($finallyNode)) {
             $finallyNode = $node;
         } else {
             if ($node instanceof ezcWorkflowNodeEnd && !isset($defaultEndNode)) {
                 $defaultEndNode = $node;
             } else {
                 if ($node instanceof ezcWorkflowNodeStart) {
                     $startNode = $node;
                 }
             }
         }
         $nodes[$id] = $node;
     }
     if (!isset($startNode) || !isset($defaultEndNode)) {
         throw new ezcWorkflowDefinitionStorageException('Could not load workflow definition.');
     }
     // Connect node objects.
     foreach ($xmlNodes as $xmlNode) {
         $id = (int) $xmlNode->getAttribute('id');
         $className = 'ezcWorkflowNode' . $xmlNode->getAttribute('type');
         foreach ($xmlNode->getElementsByTagName('outNode') as $outNode) {
             $nodes[$id]->addOutNode($nodes[(int) $outNode->getAttribute('id')]);
         }
         if (is_subclass_of($className, 'ezcWorkflowNodeConditionalBranch')) {
             foreach (ezcWorkflowUtil::getChildNodes($xmlNode) as $childNode) {
                 if ($childNode->tagName == 'condition') {
                     foreach ($childNode->getElementsByTagName('else') as $elseNode) {
                         foreach ($elseNode->getElementsByTagName('outNode') as $outNode) {
                             $elseId = (int) $outNode->getAttribute('id');
                         }
                     }
                     $condition = self::xmlToCondition($childNode);
                     foreach ($childNode->getElementsByTagName('outNode') as $outNode) {
                         if (!isset($elseId)) {
                             $nodes[$id]->addConditionalOutNode($condition, $nodes[(int) $outNode->getAttribute('id')]);
                         } else {
                             $nodes[$id]->addConditionalOutNode($condition, $nodes[(int) $outNode->getAttribute('id')], $nodes[$elseId]);
                             unset($elseId);
                         }
                     }
                 }
             }
         }
     }
     if (!isset($finallyNode) || count($finallyNode->getInNodes()) > 0) {
         $finallyNode = null;
     }
     // Create workflow object and add the node objects to it.
     $workflow = new ezcWorkflow($workflowName, $startNode, $defaultEndNode, $finallyNode);
     $workflow->definitionStorage = $this;
     $workflow->version = $workflowVersion;
     // Handle the variable handlers.
     foreach ($document->getElementsByTagName('variableHandler') as $variableHandler) {
         $workflow->addVariableHandler($variableHandler->getAttribute('variable'), $variableHandler->getAttribute('class'));
     }
     // Verify the loaded workflow.
     $workflow->verify();
     return $workflow;
 }
 /**
  * Load a workflow definition by ID.
  *
  * Providing the name of the workflow that is to be loaded as the
  * optional second parameter saves a database query.
  *
  * @param  int $workflowId
  * @param  string  $workflowName
  * @param  int $workflowVersion
  * @return ezcWorkflow
  * @throws ezcWorkflowDefinitionStorageException
  * @throws ezcDbException
  */
 public function loadById($workflowId, $workflowName = '', $workflowVersion = 0)
 {
     // Query the database for the name and version of the workflow.
     if (empty($workflowName) || $workflowVersion == 0) {
         $query = $this->db->createSelectQuery();
         $query->select($this->db->quoteIdentifier('workflow_name'))->select($this->db->quoteIdentifier('workflow_version'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'workflow'))->where($query->expr->eq($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflowId)));
         $stmt = $query->prepare();
         $stmt->execute();
         $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
         if ($result !== false && isset($result[0])) {
             $workflowName = $result[0]['workflow_name'];
             $workflowVersion = $result[0]['workflow_version'];
         } else {
             throw new ezcWorkflowDefinitionStorageException('Could not load workflow definition.');
         }
     }
     // Query the database for the nodes of the workflow to be loaded.
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('node_id'))->select($this->db->quoteIdentifier('node_class'))->select($this->db->quoteIdentifier('node_configuration'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'node'))->where($query->expr->eq($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflowId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $nodes = array();
     // Create node objects.
     foreach ($result as $node) {
         $configuration = ezcWorkflowDatabaseUtil::unserialize($node['node_configuration'], null);
         if (is_null($configuration)) {
             $configuration = ezcWorkflowUtil::getDefaultConfiguration($node['node_class']);
         }
         $nodes[$node['node_id']] = new $node['node_class']($configuration);
         if ($nodes[$node['node_id']] instanceof ezcWorkflowNodeFinally && !isset($finallyNode)) {
             $finallyNode = $nodes[$node['node_id']];
         } else {
             if ($nodes[$node['node_id']] instanceof ezcWorkflowNodeEnd && !isset($defaultEndNode)) {
                 $defaultEndNode = $nodes[$node['node_id']];
             } else {
                 if ($nodes[$node['node_id']] instanceof ezcWorkflowNodeStart && !isset($startNode)) {
                     $startNode = $nodes[$node['node_id']];
                 }
             }
         }
     }
     if (!isset($startNode) || !isset($defaultEndNode)) {
         throw new ezcWorkflowDefinitionStorageException('Could not load workflow definition.');
     }
     // Connect node objects.
     $query = $this->db->createSelectQuery();
     $query->select($query->alias('node_connection.incoming_node_id', $this->db->quoteIdentifier('incoming_node_id')))->select($query->alias('node_connection.outgoing_node_id', $this->db->quoteIdentifier('outgoing_node_id')))->from($query->innerJoin($this->db->quoteIdentifier($this->options['prefix'] . 'node_connection'), $this->db->quoteIdentifier($this->options['prefix'] . 'node'), 'node_connection.incoming_node_id', 'node.node_id'))->where($query->expr->eq('node.workflow_id', $query->bindValue((int) $workflowId)))->orderBy($this->db->quoteIdentifier('node_connection_id'));
     $stmt = $query->prepare();
     $stmt->execute();
     $connections = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($connections as $connection) {
         $nodes[$connection['incoming_node_id']]->addOutNode($nodes[$connection['outgoing_node_id']]);
     }
     if (!isset($finallyNode) || count($finallyNode->getInNodes()) > 0) {
         $finallyNode = null;
     }
     // Create workflow object and add the node objects to it.
     $workflow = new ezcWorkflow($workflowName, $startNode, $defaultEndNode, $finallyNode);
     $workflow->definitionStorage = $this;
     $workflow->id = (int) $workflowId;
     $workflow->version = (int) $workflowVersion;
     // Query the database for the variable handlers.
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('variable'))->select($this->db->quoteIdentifier('class'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'variable_handler'))->where($query->expr->eq($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflowId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $nodes = array();
     if ($result !== false) {
         foreach ($result as $variableHandler) {
             $workflow->addVariableHandler($variableHandler['variable'], $variableHandler['class']);
         }
     }
     // Verify the loaded workflow.
     $workflow->verify();
     return $workflow;
 }