예제 #1
0
 /**
  * Invokes a flow and returns a flow execution ticket.
  *
  * @param mixed   &$payload
  * @param boolean $bindActionsWithFlowExecution
  * @return string
  */
 function invoke(&$payload, $bindActionsWithFlowExecution = false)
 {
     if ($this->_enableGC) {
         $this->_gc->setGCCallback(array(&$this->_flowExecution, 'disableFlowExecution'));
         $this->_gc->mark();
     }
     $this->_prepare();
     if (Piece_Flow_Error::hasErrors()) {
         return;
     }
     if (!$this->_isFirstTime) {
         $this->_continue($payload, $bindActionsWithFlowExecution);
     } else {
         $this->_start($payload);
     }
     if (Piece_Flow_Error::hasErrors()) {
         return;
     }
     if ($this->_enableGC && !$this->_isExclusive()) {
         $this->_gc->update($this->_activeFlowExecutionTicket);
     }
     if ($bindActionsWithFlowExecution) {
         $flow =& $this->_flowExecution->getActiveFlow();
         $flow->clearPayload();
         $this->_prepareContext();
         $flow->setAttribute('_actionInstances', Piece_Flow_Action_Factory::getInstances());
     }
     $GLOBALS['PIECE_FLOW_Continuation_Server_ActiveInstances'][] =& $this;
     if (!$GLOBALS['PIECE_FLOW_Continuation_Server_ShutdownRegistered']) {
         $GLOBALS['PIECE_FLOW_Continuation_Server_ShutdownRegistered'] = true;
         register_shutdown_function(array(__CLASS__, 'shutdown'));
     }
     return $this->_activeFlowExecutionTicket;
 }
예제 #2
0
 /**
  * Invokes the plugin specific code.
  *
  * @return string
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function invoke()
 {
     $this->_prepareContinuation();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     Piece_Flow_Error::disableCallback();
     $flowExecutionTicket = $this->_continuationServer->invoke($this->_context, $this->_getConfiguration('bindActionsWithFlowExecution'));
     Piece_Flow_Error::enableCallback();
     if (Piece_Flow_Error::hasErrors()) {
         $error = Piece_Flow_Error::pop();
         if ($error['code'] == PIECE_FLOW_ERROR_FLOW_EXECUTION_EXPIRED) {
             if ($this->_getConfiguration('useGCFallback')) {
                 $session =& $this->_context->getSession();
                 $session->setAttribute('_flowExecutionExpired', true);
                 $this->_context->sendHTTPStatus(302);
                 return $this->_getConfiguration('gcFallbackURI');
             }
         }
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed to invoke the plugin [ {$this->_name} ] for any reasons.", 'exception', array(), $error);
         return;
     }
     Piece_Flow_Error::disableCallback();
     $viewString = $this->_continuationServer->getView();
     Piece_Flow_Error::enableCallback();
     if (Piece_Flow_Error::hasErrors()) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed to invoke the plugin [ {$this->_name} ] for any reasons.", 'exception', array(), Piece_Flow_Error::pop());
         return;
     }
     $viewElement =& $this->_context->getViewElement();
     $viewElement->setElement('__flowExecutionTicket', $flowExecutionTicket);
     $session =& $this->_context->getSession();
     $session->setPreloadCallback('_Dispatcher_Continuation_ActionLoader', array(__CLASS__, 'loadAction'));
     foreach (array_keys(Piece_Flow_Action_Factory::getInstances()) as $actionClass) {
         $session->addPreloadClass('_Dispatcher_Continuation_ActionLoader', $actionClass, $this->_continuationServer->getActiveFlowID());
     }
     if (!$this->_getConfiguration('useFlowMappings')) {
         return $viewString;
     }
     return $this->_prefixFlowNameToViewString($viewString);
 }
예제 #3
0
 /**
  * Invokes the plugin specific code.
  *
  * @return string
  * @throws Stagehand_LegacyError_PEARErrorStack_Exception
  */
 public function invoke()
 {
     $this->_prepareContinuation();
     Piece_Unity_Service_Continuation::setFlowExecutionTicketKey($this->flowExecutionTicketKey);
     self::$_flowID = $this->context->getOriginalScriptName();
     Piece_Flow_Action_Factory::setActionDirectory($this->actionDirectory);
     $viewElement = $this->context->viewElement;
     $viewElement->setElement('__flowExecutionTicketKey', Piece_Unity_Service_Continuation::getFlowExecutionTicketKey());
     try {
         $flowExecutionTicket = $this->_continuationServer->invoke($this->context, $this->bindActionsWithFlowExecution);
         $viewString = $this->_continuationServer->getView();
     } catch (Stagehand_LegacyError_PEARErrorStack_Exception $e) {
         if ($e->getCode() == PIECE_FLOW_ERROR_FLOW_EXECUTION_EXPIRED) {
             if ($this->useGCFallback) {
                 $session = $this->context->getSession();
                 $session->setAttribute('_flowExecutionExpired', true);
                 $this->context->sendHTTPStatus(302);
                 return $this->gcFallbackURI;
             }
         }
         throw $e;
     }
     $this->context->viewElement->setElement('__flowExecutionTicket', $flowExecutionTicket);
     $session = $this->context->getSession();
     $session->setPreloadCallback('_Dispatcher_Continuation_ActionLoader', array(__CLASS__, 'loadAction'));
     foreach (array_keys(Piece_Flow_Action_Factory::getInstances()) as $actionClass) {
         $session->addPreloadClass('_Dispatcher_Continuation_ActionLoader', $actionClass, $this->_continuationServer->getActiveFlowID());
     }
     return $this->_prefixFlowNameToViewString($viewString);
 }