コード例 #1
0
 /**
  * Updates client end-point with values received from request:
  *
  * @param __IRequest $request
  * @param __IResponse $response
  */
 public function preFilter(__IRequest &$request, __IResponse &$response)
 {
     //update client end-points with values received from request:
     $request_component_values = __ContextManager::getInstance()->getApplicationContext()->getPropertyContent('REQUEST_CLIENT_ENDPOINT_VALUES');
     if ($request->hasParameter($request_component_values)) {
         $values = $request->getParameter($request_component_values);
         if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
             $scape_chars = array('\\n', '\\r', '\\t');
             $double_scape_chars = array('\\\\n', '\\\\r', '\\\\t');
             $values = str_replace($scape_chars, $double_scape_chars, $values);
             $values = stripslashes($values);
         }
         $client_values = json_decode($values, true);
         if (is_array($client_values)) {
             $ui_binding_manager = __UIBindingManager::getInstance();
             foreach ($client_values as $id => $value) {
                 if ($ui_binding_manager->hasUIBinding($id)) {
                     $ui_binding_manager->getUIBinding($id)->getClientEndPoint()->setValue($value);
                 } else {
                     if ($request->hasParameter('viewCode')) {
                         $view_code = $request->getParameter('viewCode');
                         __ComponentLazyLoader::loadView($view_code);
                         if ($ui_binding_manager->hasUIBinding($id)) {
                             $ui_binding_manager->getUIBinding($id)->getClientEndPoint()->setValue($value);
                         } else {
                             throw __ExceptionFactory::getInstance()->createException('Can not sync component status between client and server');
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Switch the context to lion admin application, just in case the REQUEST_LION_ADMIN_AREA parameter is present within the request
  *
  * @param __IRequest $request
  * @param __IResponse $response
  */
 public function preFilter(__IRequest &$request, __IResponse &$response)
 {
     $admin_area_parameter = __ApplicationContext::getInstance()->getPropertyContent('REQUEST_LION_ADMIN_AREA');
     if ($request->hasParameter($admin_area_parameter) && __ApplicationContext::getInstance()->getPropertyContent('LION_ADMIN_ENABLED') == true) {
         __ContextManager::getInstance()->createContext("LION_ADMIN_AREA", ADMIN_DIR);
         __ContextManager::getInstance()->switchContext("LION_ADMIN_AREA");
     }
 }
コード例 #3
0
 /**
  * Change the currency in session by a given one if the 
  * currency parameter is present within the request.
  *
  */
 public function preFilter(__IRequest &$request, __IResponse &$response)
 {
     if ($request->hasParameter('currency')) {
         $currency_iso_code = $request->getParameter('currency');
         //set the currency iso code within the CurrencyManager
         //singleton instance:
         CurrencyManager::getInstance()->setCurrencyIsoCode($currency_iso_code);
     }
 }
コード例 #4
0
 public function dispatch(__IRequest &$request, __IResponse &$response)
 {
     //set the current request and response:
     $this->_request =& $request;
     $this->_response =& $response;
     //dispatch the request:
     if ($request->hasFilterChain()) {
         $filter_chain = $request->getFilterChain();
         $filter_chain->reset();
         $filter_chain->setFrontControllerCallback($this, 'processRequest');
         $filter_chain->execute($request, $response);
     } else {
         $this->processRequest($request, $response);
     }
 }
コード例 #5
0
 /**
  * This method dispatch the current request
  *
  */
 public function processRequest(__IRequest &$request, __IResponse &$response)
 {
     $action_identity = $request->getActionIdentity();
     $controller_code = $action_identity->getControllerCode();
     //in case we haven't define any controller, will use the commandline controller from lion admin:
     if (empty($controller_code)) {
         //switch to lion admin area:
         __ContextManager::getInstance()->createContext("LION_ADMIN_AREA", ADMIN_DIR);
         __ContextManager::getInstance()->switchContext("LION_ADMIN_AREA");
         //execute the commandline controller:
         $action_identity->setControllerCode('commandline');
     }
     $controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($action_identity->getControllerCode());
     //check if action controller is requestable
     if ($controller_definition instanceof __ActionControllerDefinition && $controller_definition->isRequestable()) {
         __ActionDispatcher::getInstance()->dispatch($action_identity);
     } else {
         throw __ExceptionFactory::getInstance()->createException('ERR_ACTION_NON_REQUESTABLE');
     }
 }
コード例 #6
0
 protected function _setResponseToCache(__IRequest &$request, __IResponse &$response)
 {
     $uri = $request->getUri();
     if ($uri != null) {
         $route = $uri->getRoute();
         if ($route != null) {
             if ($route->getCache()) {
                 //only cache anonymous view:
                 if ($response->isCacheable()) {
                     $response_snapshot = new __ResponseSnapshot($response);
                     $cache = __ApplicationContext::getInstance()->getCache();
                     $cache->setData('responseSnapshot::' . $request->getUniqueCode(), $response_snapshot, $route->getCacheTtl());
                 }
             } else {
                 if ($route->getSuperCache()) {
                     //only cache anonymous view:
                     if ($response->isCacheable()) {
                         $target_url_components = parse_url($uri->getAbsoluteUrl());
                         $path = $target_url_components['path'];
                         $dir = dirname($path);
                         $file = basename($path);
                         $response_content = $response->getContent() . "\n<!-- supercached -->";
                         $cache_ttl = $route->getCacheTtl();
                         $server_dir = $_SERVER['DOCUMENT_ROOT'] . $dir;
                         if (is_dir($server_dir) && is_writable($server_dir)) {
                             $file_handler = fopen($server_dir . DIRECTORY_SEPARATOR . $file, "w+");
                             fputs($file_handler, $response_content);
                             fclose($file_handler);
                         } else {
                             $exception = __ExceptionFactory::getInstance()->createException('Directory not found to supercache: ' . $server_dir);
                             __ErrorHandler::getInstance()->logException($exception);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
 /**
  * Redirects to the given uri.
  * This method uses an HTTP redirection to force the client browser to be redirected to
  * 
  * @see __HttpFrontController::forward()
  *
  * @param __Uri|string the uri (or an string representing the uri) to redirect to
  * @param __IRequest &$request The request associated to the redirection
  * @param integer $redirection_code The HTTP redirection code
  */
 public function redirect($url, __IRequest &$request = null, $redirection_code = null)
 {
     if ($url instanceof __Uri) {
         $url = $url->getUrl();
     } else {
         if (!is_string($url)) {
             throw __ExceptionFactory::getInstance()->createException('Unexpected type for url parameter: ' . get_class($url));
         }
     }
     if ($request != null) {
         $parameters = $request->getParameters(REQMETHOD_GET);
         if (count($parameters) > 0) {
             $query_string = http_build_query($parameters);
             if (!empty($query_string)) {
                 if (strpos($url, '?') === false) {
                     $url .= '?';
                 } else {
                     $url .= '&';
                 }
                 $url .= $query_string;
             }
         }
     }
     //Now will redirect the user to show the error:
     if (!headers_sent()) {
         switch ($redirection_code) {
             case 300:
                 header("HTTP/1.1 300 Multiple Choices");
                 break;
             case 301:
                 header("HTTP/1.1 301 Moved Permanently");
                 break;
             case 302:
                 header("HTTP/1.1 302 Found");
                 break;
             case 303:
                 header("HTTP/1.1 303 See Other");
                 break;
             case 304:
                 header("HTTP/1.1 304 Not Modified");
                 break;
             case 305:
                 header("HTTP/1.1 305 Use Proxy");
                 break;
             case 306:
                 header("HTTP/1.1 306 Switch Proxy");
                 break;
             case 307:
                 header("HTTP/1.1 307 Temporary Redirect");
                 break;
             default:
                 //nothing to do
                 break;
         }
         header('Location: ' . $url);
     } else {
         print '
 <SCRIPT LANGUAGE=JAVASCRIPT>
   document.location.href = "' . $url . '";
 </SCRIPT>
     ';
     }
     exit;
 }
コード例 #8
0
 public function &callAsRemoteService(__IRequest &$request)
 {
     $mapped_parameters = array();
     foreach ($this->_arguments as $argument) {
         $argument_name = $argument->getName();
         if ($request->hasParameter($argument_name)) {
             $parameter_value = $request->getParameter($argument_name);
             if ($argument->isJson()) {
                 $parameter_value = json_decode($parameter_value, true);
             }
             $mapped_parameters[$argument->getIndex()] = $parameter_value;
         } else {
             if ($argument->isOptional()) {
                 $mapped_parameters[$argument->getIndex()] = null;
             } else {
                 throw __ExceptionFactory::getInstance()->createException('Error calling remote service ' . $this->_service . ': missing argument ' . $argument_name);
             }
         }
     }
     ksort($mapped_parameters);
     return $this->call($mapped_parameters);
 }