/**
* Main pipe callback. Executes an array of steps.
* @param $steps
* Either an array of steps, or the id of a pipe to load.
* @param $reorder
* Defaults to FALSE. If set to TRUE, will cause the steps to be re-ordered.
* @return
* Return value of the pipe. Unknown.
*/
function pipes_execute($steps, $reorder = FALSE) {
// It's a pid, so load the pipe.
$steps = pipes_load($steps);
}
// Convert to an array of necessary.
// Reorder the pipes if called for.
if ($reorder) {
$steps = pipes_order_steps($steps);
}
// Trim irrelevant data from the steps array in order to protect it during foreach() loop.
pipes_trim_steps($steps);
$advance = TRUE;
// Cycle through each of the steps in the pipe.
while ($sid) {
foreach ($info['step_data']['defaults'] as $key => $var) {
$info['step_data']['defaults'][$key] =
arg($var);
}
}
$value =
call_user_func_array($info['class'],
($values[$sid] +
$info['settings'] +
$info['step_data']['defaults']));
$result = FALSE;
if (isset($info['step_data']['decision'])) {
foreach ($info['step_data']['decision'] as $evaluator => $doer) {
switch ($evaluator) {
// empty() and isset() are language constructs, not functions, so they cannot be called the same way.
case 'empty':
break;
case 'isset':
break;
default:
$result = $evaluator($value);
break;
}
if ($result) {
// First, determine whether $doer is a function or a value.
if ($matches[2] == '()') {
// It's a function.
$function = $matches[1];
// Pass it all the information it wants.
$doer = $function($value, $steps, $values);
}
// Now it's definitely a value, so could either be (1) the sid of a step to go to, or (2) a return value.
// It's an sid. Set the appropriate step as the current step.
while ((list($sid,
$info) =
each($steps)) &&
$sid !=
$doer);
$advance = FALSE;
}
else {
// It's just a simple value to return.
return $doer;
}
if ($advance) {
// We need to advance the array.
}
break;
}
}
}
// Terminate if this is a terminating step.
if (isset($info['terminate'])) {
if (!$info['terminate']) {
return $value;
}
}
if (!
is_null($info['destination'])) {
foreach ($info['destination'] as $destination_data) {
$values[$destination_data['step']][$destination_data['param']] = $value;
}
}
}
// Return final value, if we reach here.
return $value;
}