Returns the default configuration for a node class.
public static getDefaultConfiguration ( string $className ) : mixed | ||
$className | string | |
리턴 | mixed |
/** * 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; }
/** * * @param int $workflowId * @param string $workflowName * @param int $workflowVersion * @return \ezcWorkflow */ protected function loadWorkflow($workflowId, $workflowName, $workflowVersion) { $workflowId = (int) $workflowId; $sql = "SELECT node_id, node_class, node_configuration FROM " . $this->options->nodeTable() . " WHERE workflow_id = ?"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(1, $workflowId); $stmt->execute(); $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); $this->workflowNodeIds[$workflowId] = array(); // Create node objects. foreach ($result as $node) { $node = array_change_key_case($node, \CASE_LOWER); $configuration = $this->options->getSerializer()->unserialize($node['node_configuration'], null); if (is_null($configuration)) { $configuration = \ezcWorkflowUtil::getDefaultConfiguration($node['node_class']); } $nodes[$node['node_id']] = $this->options->getWorkflowFactory()->createNode($node['node_class'], $configuration); $nodes[$node['node_id']]->setId($node['node_id']); $this->nodeMap[spl_object_hash($nodes[$node['node_id']])] = $node['node_id']; $this->workflowNodeIds[$workflowId][] = $node['node_id']; 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.'); } $sql = "SELECT nc.outgoing_node_id, nc.incoming_node_id FROM " . $this->options->nodeConnectionTable() . " nc " . "INNER JOIN " . $this->options->nodeTable() . " n ON n.node_id = nc.incoming_node_id WHERE n.workflow_id = ?"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(1, $workflowId); $stmt->execute(); $connections = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($connections as $connection) { $connection = array_change_key_case($connection, \CASE_LOWER); $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. $workflowClassName = $this->options->workflowClassName(); $workflow = new $workflowClassName($workflowName, $startNode, $defaultEndNode, $finallyNode); $workflow->definitionStorage = $this; $workflow->id = (int) $workflowId; $workflow->version = (int) $workflowVersion; $sql = "SELECT variable, class FROM " . $this->options->variableHandlerTable() . " WHERE workflow_id = ?"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(1, $workflowId); $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; }
/** * 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; }