getRouting() public method

Retrieve the routing instance.
public getRouting ( ) : sfRouting
return sfRouting The current sfRouting implementation instance.
 /**
  * Attempts to return the theme for the current request
  * 
  * This first throws a sympal.theme.set_theme_from_request event, giving
  * anyone the opportunity to determine the theme. If this event is not
  * handled, we continue with some default rules for setting themes.
  * 
  * @param sfContext $context
  * @param array An array of valid themes, to be used for user-entered themes
  * 
  * @return string The theme (defaults to the default theme)
  */
 public function getThemeForRequest(sfContext $context, $validThemes)
 {
     $event = $context->getEventDispatcher()->notifyUntil(new sfEvent($this, 'theme.set_theme_from_request', array('context' => $context)));
     if ($event->isProcessed()) {
         return $event->getReturnValue();
     }
     if ($this->getOption('allow_changing_theme_by_url', true)) {
         $user = $context->getUser();
         $request = $context->getRequest();
         if ($theme = $request->getParameter($this->getOption('theme_request_parameter_name', 'sf_theme'))) {
             // make sure the theme is valid
             if (in_array($theme, $validThemes)) {
                 $user->setCurrentTheme($theme);
                 return $theme;
             } else {
                 // unset the user attribute
                 $user->setCurrentTheme(false);
             }
         }
         if ($theme = $user->getCurrentTheme()) {
             return $theme;
         }
     }
     // Get the theme from module/route. False is a valid response (don't set theme)
     $module = $context->getModuleName();
     $route = $context->getRouting()->getCurrentRouteName();
     $theme = $this->getThemeFromConfig($module, $route);
     if ($theme || $theme === false) {
         return $theme;
     }
     return $this->getOption('default_theme');
 }
 /**
  * Initializes the cache manager.
  *
  * @param sfContext $context  Current application context
  * @param sfCache   $cache    An sfCache instance
  */
 public function initialize($context, sfCache $cache)
 {
     $this->context = $context;
     $this->dispatcher = $context->getEventDispatcher();
     $this->controller = $context->getController();
     // empty configuration
     $this->cacheConfig = array();
     // cache instance
     $this->cache = $cache;
     // routing instance
     $this->routing = $context->getRouting();
 }
Exemplo n.º 3
0
 /**
  * Initializes the cache manager.
  *
  * @param sfContext $context  Current application context
  * @param sfCache   $cache    An sfCache instance
  */
 public function initialize($context, sfCache $cache)
 {
     $this->context = $context;
     $this->dispatcher = $context->getEventDispatcher();
     $this->controller = $context->getController();
     if (sfConfig::get('sf_web_debug')) {
         $this->dispatcher->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug'));
     }
     // empty configuration
     $this->cacheConfig = array();
     // cache instance
     $this->cache = $cache;
     // routing instance
     $this->routing = $context->getRouting();
 }
Exemplo n.º 4
0
 /**
  * Initializes the cache manager.
  *
  * @param sfContext $context  Current application context
  * @param sfCache   $cache    An sfCache instance
  */
 public function initialize($context, sfCache $cache, $options = array())
 {
     $this->context = $context;
     $this->dispatcher = $context->getEventDispatcher();
     $this->controller = $context->getController();
     $this->request = $context->getRequest();
     $this->options = array_merge(array('cache_key_use_vary_headers' => true, 'cache_key_use_host_name' => true), $options);
     if (sfConfig::get('sf_web_debug')) {
         $this->dispatcher->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug'));
     }
     // empty configuration
     $this->cacheConfig = array();
     // cache instance
     $this->cache = $cache;
     // routing instance
     $this->routing = $context->getRouting();
 }
 /**
  * extracts the sfRoute from the item if exists
  *
  * @param array $item
  * @return mixed
  */
 protected function getRouteFromItem(&$item)
 {
     $config = $this->context->getConfiguration();
     $routing = $this->context->getRouting();
     $routeName = $item['route'];
     $routeName = self::replaceConstants($routeName);
     $item['route'] = $routeName;
     if (strpos($item['route'], '://') || strpos($item['route'], 'ww.') || strpos($item['route'], '#') !== false) {
         return false;
     } elseif (strpos($routeName, '/')) {
         $config = $routing->parse($routeName);
         return $config['_sf_route'];
     } else {
         $routeName = str_replace('@', '', $routeName);
         if (strpos($routeName, '?')) {
             $routeName = substr($routeName, 0, strpos($routeName, '?'));
         }
         $routes = $routing->getRoutes();
         return isset($routes[$routeName]) ? $routes[$routeName] : false;
     }
 }
 /**
  * Check if the supplied route exists
  *
  * @param string $route
  * @param sfContext $context
  *
  * @return boolean
  */
 public static function routeExists($route, sfContext $context)
 {
     try {
         $context->getRouting()->generate($route);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Exemplo n.º 7
0
 public function getPathAfterLoggingIn(sfContext $context)
 {
     $logger = Logger::getLogger('core.homepageservice');
     $redirectToReferer = true;
     $request = $context->getRequest();
     $referer = $request->getReferer();
     $host = $request->getHost();
     // get base url: ie something like: http://host:port/symfony/web/index.php
     $baseUrl = $request->getUriPrefix() . $request->getPathInfoPrefix();
     if ($logger->isDebugEnabled()) {
         $logger->debug("referer: {$referer}, host: {$host}, base url: {$baseUrl}");
     }
     if (strpos($referer, $this->loginPath)) {
         // Check whether referer is login page
         $redirectToReferer = false;
         if ($logger->isDebugEnabled()) {
             $logger->debug("referrer is the login page. Skipping redirect:" . $this->loginPath);
         }
     } elseif (strpos($referer, $this->validatePath)) {
         // Check whether referer is validate action
         $redirectToReferer = false;
         if ($logger->isDebugEnabled()) {
             $logger->debug("referrer is the validate action. Skipping redirect:" . $this->validatePath);
         }
     } else {
         if (false === strpos($referer, $baseUrl)) {
             // Check whether from same host
             $redirectToReferer = false;
             if ($logger->isDebugEnabled()) {
                 $logger->debug("referrer does not have same base url. Skipping redirect");
             }
         }
     }
     /* 
      * Try to get action and module, skip redirecting to referrer and show homepage if:
      * 1) Action is not secure (probably a login related url we should not redirect to)
      * 2) Action is not accessible to current user.
      */
     if ($redirectToReferer) {
         try {
             $moduleAndAction = str_replace($baseUrl, '', $referer);
             if ($logger->isDebugEnabled()) {
                 $logger->debug('referrer module and action: ' . $moduleAndAction);
             }
             $params = $context->getRouting()->parse($moduleAndAction);
             if ($params && isset($params['module']) && isset($params['action'])) {
                 $moduleName = $params['module'];
                 $actionName = $params['action'];
                 if ($logger->isDebugEnabled()) {
                     $logger->debug("module: {$moduleName}, action: {$actionName}");
                 }
                 if ($context->getController()->actionExists($moduleName, $actionName)) {
                     $action = $context->getController()->getAction($moduleName, $actionName);
                     if ($action instanceof sfAction) {
                         if ($action->isSecure()) {
                             $permissions = UserRoleManagerFactory::getUserRoleManager()->getScreenPermissions($moduleName, $actionName);
                             if ($permissions instanceof ResourcePermission) {
                                 if ($permissions->canRead()) {
                                     return $referer;
                                 }
                             } else {
                                 $logger->debug("action does not exist");
                             }
                         } else {
                             $logger->debug("action is not secure");
                         }
                     } else {
                         $logger->debug("action not an instance of sfAction");
                     }
                 } else {
                     $logger->debug("action does not exist");
                 }
             } else {
                 $logger->debug("referrer does not match a route");
             }
         } catch (Exception $e) {
             $logger->warn('Error when trying to get referrer action: ' . $e);
         }
     }
     return $this->getHomePagePath();
 }
 /**
  * Initialize cache manager
  *
  * @param sfContext $context
  * @param sfCache   $taggingCache
  * @param array     $options
  *
  * @see sfViewCacheManager::initialize()
  */
 public function initialize($context, sfCache $taggingCache, $options = array())
 {
     if (!$taggingCache instanceof sfTaggingCache) {
         throw new InvalidArgumentException(sprintf('Cache "%s" is not instanceof sfTaggingCache', get_class($taggingCache)));
     }
     if (!sfConfig::get('sf_cache')) {
         $taggingCache = new sfNoTaggingCache();
     }
     $this->setTaggingCache($taggingCache);
     $this->cache = $this->getTaggingCache()->getCache();
     $this->setEventDispatcher($context->getEventDispatcher());
     $this->context = $context;
     $this->controller = $context->getController();
     $this->request = $context->getRequest();
     $this->routing = $context->getRouting();
     $this->setOptions(array_merge(array('cache_key_use_vary_headers' => true, 'cache_key_use_host_name' => true), $options));
     if (sfConfig::get('sf_web_debug')) {
         $this->getEventDispatcher()->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug'));
     }
     // empty configuration
     $this->cacheConfig = array();
 }