public static function loadView($view_code) { try { $url = unserialize(base64_decode($view_code)); $request = __RequestFactory::getInstance()->createRequest(REQUEST_TYPE_HTTP); $response = __ResponseFactory::getInstance()->createResponse(REQUEST_TYPE_HTTP); $url_components = parse_url($url); if (is_array($url_components) && key_exists('query', $url_components)) { $query = $url_components['query']; $get_pairs = explode('&', $query); foreach ($get_pairs as $get_pair) { $get_pair_array = explode('=', $get_pair); $request->addParameter($get_pair_array[0], $get_pair_array[1], REQMETHOD_GET); } } $uri = __UriFactory::getInstance()->createUri($url_components['path']); $request->setUri($uri); $request->setRequestMethod(REQMETHOD_GET); $front_controller = new __ComponentLazyLoaderFrontController(); $front_controller->dispatch($request, $response); //dispatch the request } catch (Exception $e) { __ExceptionFactory::getInstance()->createException('Can not load view for view code ' . $view_code . ': ' . $e->getMessage()); } }
public function &getRequest() { if ($this->_request == null) { $request = __RequestFactory::getInstance()->createRequest(); if ($request instanceof __IRequest) { $this->_request =& $request; $this->_request->readClientRequest(); } } return $this->_request; }
/** * Forward the web flow to the given uri. * This method is similar to redirect, but performs the redirection internally (without http redirection codes) * * @param __Uri|string the uri (or an string representing the url) to redirect to * @param __IRequest &$request The request instance to use in the forward * */ public function forward($uri, __IRequest &$request = null) { if (is_string($uri)) { $uri = __UriFactory::getInstance()->createUri($uri); } else { if (!$uri instanceof __Uri) { throw __ExceptionFactory::getInstance()->createException('Unexpected type for uri parameter: ' . get_class($uri)); } } if ($request == null) { $request = __RequestFactory::getInstance()->createRequest(); } $request->setUri($uri); $request->setRequestMethod(REQMETHOD_ALL); $response = __Client::getInstance()->getResponse(); $response->clear(); //clear the response $this->dispatch($request, $response); //dispatch the request $response->flush(); //flush the response exit; }
protected function _executeControllerAssociatedToState(__FlowState $state, __FlowExecutor &$flow_executor, $flow_execution_key) { try { $action_identity = $state->getActionIdentity(); $response = __ActionDispatcher::getInstance()->dispatch($action_identity); if ($response instanceof __IResponse) { $flow_executor->setResponse($response); $response->clear(); //redirect via 303 because of the redirect after submit pattern (alwaysRedirectOnPause) $request = __FrontController::getInstance()->getRequest(); $uri = $request->getUri(); //add the flow execution key parameter: $application_context = __ApplicationContext::getInstance(); $request_flow_execution_key = $application_context->getPropertyContent('REQUEST_FLOW_EXECUTION_KEY'); $request_flow_state_id = $application_context->getPropertyContent('REQUEST_FLOW_STATE_ID'); $uri->addParameter($request_flow_execution_key, $flow_execution_key); $uri->addParameter($request_flow_state_id, $state->getId()); $empty_request = __RequestFactory::getInstance()->createRequest(); __FrontController::getInstance()->redirect($uri, $empty_request, 303); } else { if ($response instanceof __FlowEvent) { $fc_response = __FrontController::getInstance()->getResponse(); $fc_response->clear(); //clear the response content (to avoid decorator lateral issues) $state = $flow_executor->resume($flow_execution_key, $response->getEventName()); if ($state != null) { $application_context = __ApplicationContext::getInstance(); $action_identity = $state->getActionIdentity(); $this->_executeControllerAssociatedToState($state, $flow_executor, $flow_execution_key); } } } } catch (Exception $e) { if ($flow_executor->isExceptionHandled($e)) { //$state = $flow_executor->handleException($flow_execution_key, $e); //if($state != null) { // $this->_executeControllerAssociatedToState($flow_executor, $state); //} } else { throw $e; } } return $response; }
public function readClientRequest() { $this->_readGlobalRequestParameters(); $request_url = $this->_getRequestUrl(); if ($request_url != null) { $uri = __UriFactory::getInstance()->createUri($request_url); $this->setUri($uri); if ($uri instanceof __Uri) { $route = $uri->getRoute(); if ($route != null && $route instanceof __Route) { $route_id_to_redirect_to = $route->getRouteIdToRedirectTo(); //check if need to redirect to any route: if (!empty($route_id_to_redirect_to)) { $uri = __UriFactory::getInstance()->createUri()->setRoute($route_id_to_redirect_to)->setParameters($this->toArray(REQMETHOD_GET)); $empty_request = __RequestFactory::getInstance()->createRequest(); $redirection_code = $route->getRedirectionCode(); __FrontController::getInstance()->redirect($uri, $empty_request, $redirection_code); } //also check if the current route allowes only SSL: if ($route->getOnlySSL() && HTTP_PROTOCOL != 'https') { $empty_request = __RequestFactory::getInstance()->createRequest(); $url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; __FrontController::getInstance()->redirect($url, $empty_request, 302); } } } } }