Пример #1
0
 /**
  * Executes each action in a given branch, starting at $start.
  *
  * @param array $flowPath directions to the current position in the flow tree
  * @param array $flowItems the items in this branch
  * @param array &$params an associative array of params, usually including 'model'=>$model,
  * @param integer $start the position in the branch to start at, defaults to 0
  */
 public function executeBranch(&$flowItems, &$params, $triggerLogId = null)
 {
     $results = array();
     for ($i = 0; $i < count($flowItems); $i++) {
         $item =& $flowItems[$i];
         if (!isset($item['type']) || !class_exists($item['type'])) {
             continue;
         }
         $node = X2FlowItem::create($item);
         if ($item['type'] === 'X2FlowSwitch') {
             $validateRetArr = $node->validate($params, $this->id);
             if ($validateRetArr[0]) {
                 $checkRetArr = $node->check($params);
                 if ($checkRetArr[0] && isset($item['trueBranch'])) {
                     $results[] = array($item['type'], true, $this->executeBranch($item['trueBranch'], $params, $triggerLogId));
                 } elseif (isset($item['falseBranch'])) {
                     $results[] = array($item['type'], false, $this->executeBranch($item['falseBranch'], $params, $triggerLogId));
                 }
             }
         } elseif ($item['type'] === 'X2FlowSplitter') {
             $validateRetArr = $node->validate($params, $this->id);
             if ($validateRetArr[0]) {
                 // right to left pre-order traversal
                 $branchVal = true;
                 if (isset($item[X2FlowSplitter::getRightChildName()])) {
                     $results[] = array($item['type'], true, $this->executeBranch($item[X2FlowSplitter::getRightChildName()], $params, $triggerLogId));
                 }
                 if (isset($item[X2FlowSplitter::getLeftChildName()])) {
                     $results[] = array($item['type'], false, $this->executeBranch($item[X2FlowSplitter::getLeftChildName()], $params, $triggerLogId));
                 }
             }
         } else {
             $flowAction = X2FlowAction::create($item);
             if ($item['type'] === 'X2FlowWait') {
                 $node->flowId = $this->id;
                 $results[] = $this->validateAndExecute($item, $node, $params, $triggerLogId);
                 break;
             } else {
                 $results[] = $this->validateAndExecute($item, $node, $params, $triggerLogId);
             }
         }
     }
     return $results;
 }
Пример #2
0
 /**
  * Generalized mass-instantiation method.
  *
  * Loads and instantiates all X2Flow items of a given type (i.e. actions,
  * triggers).
  * 
  * @param type $type
  * @param type $excludeClasses
  * @return type
  */
 public static function getInstances($type, $excludeClasses = array())
 {
     if (!isset(self::$_instances)) {
         self::$_instances = array();
     }
     if (!isset(self::$_instances[$type])) {
         $excludeFiles = array();
         foreach ($excludeClasses as $class) {
             $excludedFiles[] = "{$class}.php";
         }
         $excludedFiles[] = '.';
         $excludedFiles[] = '..';
         self::$_instances[$type] = array();
         foreach (scandir(Yii::getPathOfAlias('application.components.x2flow.' . $type)) as $file) {
             if (!preg_match('/\\.php$/', $file) || in_array($file, $excludedFiles)) {
                 continue;
             }
             $class = self::create(array('type' => substr($file, 0, -4)));
             if ($class !== null) {
                 self::$_instances[$type][] = $class;
             }
         }
     }
     return self::$_instances[$type];
 }
Пример #3
0
 /**
  * Executes each action in a given branch, starting at $start.
  *
  * @param array $flowPath directions to the current position in the flow tree
  * @param array $flowItems the items in this branch
  * @param array &$params an associative array of params, usually including 'model'=>$model,
  * @param integer $start the position in the branch to start at, defaults to 0
  */
 public function executeBranch($flowPath, &$flowItems, &$params, $start = 0, $triggerLogId = null)
 {
     $results = array();
     for ($i = $start; $i < count($flowItems); $i++) {
         $item =& $flowItems[$i];
         if (!isset($item['type']) || !class_exists($item['type'])) {
             continue;
         }
         if ($item['type'] === 'X2FlowSwitch') {
             $switch = X2FlowItem::create($item);
             $validateRetArr = $switch->validate($params, $this->id);
             if ($validateRetArr[0]) {
                 // flowPath only contains switch decisions and the index on the current branch
                 array_pop($flowPath);
                 // now that we're at another switch, we can throw out the previous branch index
                 // eg: $flowPath = array(true,false,3) means go to true at the first fork,
                 // go to false at the second fork, then go to item 3
                 $checkRetArr = $switch->check($params);
                 if ($checkRetArr[0] && isset($item['trueBranch'])) {
                     $flowPath[] = true;
                     $flowPath[] = 0;
                     // they're now on
                     $results[] = array($item['type'], true, $this->executeBranch($flowPath, $item['trueBranch'], $params, 0, $triggerLogId));
                 } elseif (isset($item['falseBranch'])) {
                     $flowPath[] = false;
                     $flowPath[] = 0;
                     $results[] = array($item['type'], false, $this->executeBranch($flowPath, $item['falseBranch'], $params, 0, $triggerLogId));
                 }
             }
         } else {
             $flowAction = X2FlowAction::create($item);
             if ($item['type'] === 'X2FlowWait') {
                 $flowAction->flowPath = $flowPath;
                 $flowAction->flowId = $this->id;
                 $results[] = $this->validateAndExecute($item, $flowAction, $params, $triggerLogId);
                 break;
             } else {
                 $flowPath[count($flowPath) - 1]++;
                 // increment the index in the current branch
                 $results[] = $this->validateAndExecute($item, $flowAction, $params, $triggerLogId);
             }
         }
     }
     return $results;
 }
Пример #4
0
 /**
  * Executes each action in a given branch, starting at $start.
  *
  * @param array $flowPath directions to the current position in the flow tree
  * @param array $flowItems the items in this branch
  * @param array &$params an associative array of params, usually including 'model'=>$model,
  * @param integer $start the position in the branch to start at, defaults to 0
  */
 public function executeBranch(&$flowItems, &$params, $triggerLogId = null)
 {
     $results = array();
     for ($i = 0; $i < count($flowItems); $i++) {
         $item =& $flowItems[$i];
         if (!isset($item['type']) || !class_exists($item['type'])) {
             continue;
         }
         if ($item['type'] === 'X2FlowSwitch') {
             $switch = X2FlowItem::create($item);
             $validateRetArr = $switch->validate($params, $this->id);
             if ($validateRetArr[0]) {
                 $checkRetArr = $switch->check($params);
                 if ($checkRetArr[0] && isset($item['trueBranch'])) {
                     $results[] = array($item['type'], true, $this->executeBranch($item['trueBranch'], $params, $triggerLogId));
                 } elseif (isset($item['falseBranch'])) {
                     $results[] = array($item['type'], false, $this->executeBranch($item['falseBranch'], $params, $triggerLogId));
                 }
             }
         } else {
             $flowAction = X2FlowAction::create($item);
             if ($item['type'] === 'X2FlowWait') {
                 $flowAction->flowId = $this->id;
                 $results[] = $this->validateAndExecute($item, $flowAction, $params, $triggerLogId);
                 break;
             } else {
                 $results[] = $this->validateAndExecute($item, $flowAction, $params, $triggerLogId);
             }
         }
     }
     return $results;
 }