Development

Changeset 7518

You must first sign up to be able to contribute.

Changeset 7518

Show
Ignore:
Timestamp:
02/16/08 22:57:54 (1 year ago)
Author:
fabien
Message:

moved default_module and default_action configuration to factories.yml

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/UPGRADE

    r7516 r7518  
    413413          timeout:     1800     # session timeout in seconds 
    414414 
    415 Routing default suffix 
    416 ---------------------- 
    417  
    418 The `sf_suffix` setting is not used anymore. To change the default suffix, 
    419 you now have to edit `factories.yml` instead of `settings.yml`, 
    420 and change the parameters of the `routing` factory: 
     415Routing configuration 
     416--------------------- 
     417 
     418The `sf_suffix`, `sf_default_module`, and `sf_default_action` settings are not 
     419used anymore. To change the default suffix, module, or action, you now have 
     420to edit `factories.yml` instead of `settings.yml`, and change the parameters 
     421of the `routing` factory: 
    421422 
    422423    [yml] 
     
    426427        param: 
    427428          load_configuration: true 
    428           suffix:             .     # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
     429          suffix:             .       # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
     430          default_module:     default # Default module and action to be called when 
     431          default_action:     index   # A routing rule doesn't set it 
    429432 
    430433`php.yml` configuration file 
  • branches/1.1/lib/config/config/factories.yml

    r7516 r7518  
    4747      load_configuration: true 
    4848      suffix:             . 
     49      default_module:     default 
     50      default_action:     index 
    4951 
    5052  logger: 
  • branches/1.1/lib/config/config/settings.yml

    r7516 r7518  
    11default: 
    22  .actions: 
    3     default_module:         default   # Default module and action to be called when 
    4     default_action:         index     # A routing rule doesn't set it 
    5  
    63    error_404_module:       default   # To be called when a 404 error is raised 
    74    error_404_action:       error404  # Or when the requested URL doesn't match any route 
  • branches/1.1/lib/config/sfFactoryConfigHandler.class.php

    r7516 r7518  
    162162 
    163163        case 'routing': 
    164           $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action'), 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
     164          $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
    165165          if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 
    166166          { 
  • branches/1.1/lib/controller/sfFrontWebController.class.php

    r5139 r7518  
    4545      $actionName = $request->getParameter('action'); 
    4646 
     47      if (empty($moduleName) || empty($actionName)) 
     48      { 
     49        throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $request->getPathInfo(), $moduleName, $actionName)); 
     50      } 
     51 
    4752      // make the first request 
    4853      $this->forward($moduleName, $actionName); 
  • branches/1.1/lib/controller/sfWebController.class.php

    r7273 r7518  
    8282    } 
    8383 
    84     // default module 
    85     if (!isset($parameters['module'])) 
    86     { 
    87       $parameters['module'] = sfConfig::get('sf_default_module'); 
    88     } 
    89  
    90     // default action 
    91     if (!isset($parameters['action'])) 
    92     { 
    93       $parameters['action'] = sfConfig::get('sf_default_action'); 
    94     } 
    95  
    9684    // routing to generate path 
    9785    $url .= $this->context->getRouting()->generate($route_name, $parameters, $querydiv, $divider, $equals); 
     
    155143    else 
    156144    { 
    157       $tmp = explode('/', $url); 
    158  
    159       $params['module'] = $tmp[0]; 
    160       $params['action'] = isset($tmp[1]) ? $tmp[1] : sfConfig::get('sf_default_action'); 
     145      list($params['module'], $params['action']) = explode('/', $url); 
    161146    } 
    162147 
     
    169154        (.*?)               # value 
    170155        (?: 
    171           (?=&[^&=]+=) | $  # followed by another key= or the end of the string 
     156          (?=&[^&=]+=) | $  # followed by another key= or the end of the string 
    172157        ) 
    173158      /x', $query_string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); 
  • branches/1.1/lib/request/sfWebRequest.class.php

    r6975 r7518  
    908908  protected function parseRequestParameters() 
    909909  { 
    910     $parameters = array(); 
    911     $parameters = $this->dispatcher->filter(new sfEvent($this, 'request.filter_parameters', array('path_info' => $this->getPathInfo())), $parameters)->getReturnValue(); 
    912  
    913     if (!isset($parameters['module'])) 
    914     { 
    915       $parameters['module'] = sfConfig::get('sf_default_module', 'default'); 
    916     } 
    917  
    918     if (!isset($parameters['action'])) 
    919     { 
    920       $parameters['action'] = sfConfig::get('sf_default_action', 'index'); 
    921     } 
    922  
    923     if (empty($parameters['module']) || empty($parameters['action'])) 
    924     { 
    925       throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $this->getPathInfo(), $parameters['module'], $parameters['action'])); 
    926     } 
    927  
    928     return $parameters; 
     910    return $this->dispatcher->filter(new sfEvent($this, 'request.filter_parameters', array('path_info' => $this->getPathInfo())), array())->getReturnValue(); 
    929911  } 
    930912 
  • branches/1.1/lib/routing/sfNoRouting.class.php

    r6817 r7518  
    2020{ 
    2121  /** 
    22    * Gets the internal URI for the current request. 
    23    * 
    24    * @param boolean Whether to give an internal URI with the route name (@route) 
    25    *                or with the module/action pair 
    26    * 
    27    * @return string The current internal URI 
     22   * @see sfRouting 
    2823   */ 
    2924  public function getCurrentInternalUri($with_route_name = false) 
    3025  { 
    31     $parameters = $_GET; 
    32  
    33     // module/action 
    34     $module = isset($parameters['module']) ? $parameters['module'] : $this->options['default_module']; 
    35     $action = isset($parameters['action']) ? $parameters['action'] : $this->options['default_action']; 
     26    $parameters = $this->fixDefaults(array_merge($this->defaultParameters, $_GET)); 
     27    $action = sprintf('%s/%s', $parameters['module'], $parameters['action']); 
    3628 
    3729    // other parameters 
     
    4032    $parameters = count($parameters) ? '?'.http_build_query($parameters, null, '&') : ''; 
    4133 
    42     return sprintf('%s/%s%s', $module, $action, $parameters); 
     34    return sprintf('%s%s', $action, $parameters); 
    4335  } 
    4436 
    4537 /** 
    46   * Generates a valid URLs for parameters. 
    47   * 
    48   * @param  array  The parameter values 
    49   * @param  string The divider between key/value pairs 
    50   * @param  string The equal sign to use between key and value 
    51   * 
    52   * @return string The generated URL 
     38  * @see sfRouting 
    5339  */ 
    5440  public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/') 
     
    6046 
    6147 /** 
    62   * Parses a URL to find a matching route. 
    63   * 
    64   * Returns null if no route match the URL. 
    65   * 
    66   * @param  string URL to be parsed 
    67   * 
    68   * @return array  An array of parameters 
     48  * @see sfRouting 
    6949  */ 
    7050  public function parse($url) 
     
    7454 
    7555  /** 
    76    * Gets the current compiled route array. 
    77    * 
    78    * @return array The route array 
     56   * @see sfRouting 
    7957   */ 
    8058  public function getRoutes() 
     
    8462 
    8563  /** 
    86    * Sets the compiled route array. 
    87    * 
    88    * @param array The route array 
    89    * 
    90    * @return array The route array 
     64   * @see sfRouting 
    9165   */ 
    9266  public function setRoutes($routes) 
     
    9670 
    9771  /** 
    98    * Returns true if this instance has some routes. 
    99    * 
    100    * @return  boolean 
     72   * @see sfRouting 
    10173   */ 
    10274  public function hasRoutes() 
     
    10678 
    10779  /** 
    108    * Clears all current routes. 
     80   * @see sfRouting 
    10981   */ 
    11082  public function clearRoutes() 
  • branches/1.1/lib/routing/sfPathInfoRouting.class.php

    r6817 r7518  
    2323 
    2424  /** 
    25    * Gets the internal URI for the current request. 
    26    * 
    27    * @param boolean Whether to give an internal URI with the route name (@route) 
    28    *                or with the module/action pair 
    29    * 
    30    * @return string The current internal URI 
     25   * @see sfRouting 
    3126   */ 
    3227  public function getCurrentInternalUri($with_route_name = false) 
    3328  { 
    3429    $parameters = $this->currentRouteParameters; 
    35     $module = isset($parameters['module']) ? $parameters['module'] : $this->options['default_module']; 
    36     $action = isset($parameters['action']) ? $parameters['action'] : $this->options['default_action']; 
    3730 
    3831    // other parameters 
     
    4134    $parameters = count($parameters) ? '?'.http_build_query($parameters, null, '&') : ''; 
    4235 
    43     return sprintf('%s/%s%s', $module, $action, $parameters); 
     36    return sprintf('%s/%s%s', $this->currentRouteParameters['module'], $this->currentRouteParameters['action'], $parameters); 
    4437  } 
    4538 
    4639 /** 
    47   * Generates a valid URLs for parameters. 
    48   * 
    49   * @param  array  The parameter values 
    50   * @param  string The divider between key/value pairs 
    51   * @param  string The equal sign to use between key and value 
    52   * 
    53   * @return string The generated URL 
     40  * @see sfRouting 
    5441  */ 
    5542  public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/') 
    5643  { 
    5744    $url = ''; 
    58     $params = array_merge($this->defaultParameters, $params); 
    59     foreach ($params as $key => $value) 
     45    foreach (array_merge($this->defaultParameters, $params) as $key => $value) 
    6046    { 
    6147      $url .= '/'.$key.'/'.$value; 
     
    6652 
    6753 /** 
    68   * Parses a URL to find a matching route. 
    69   * 
    70   * Returns null if no route match the URL. 
    71   * 
    72   * @param  string URL to be parsed 
    73   * 
    74   * @return array  An array of parameters 
     54  * @see sfRouting 
    7555  */ 
    7656  public function parse($url) 
    7757  { 
    78     $this->currentRouteParameters = array()
     58    $this->currentRouteParameters = $this->defaultParameters
    7959    $array = explode('/', trim($url, '/')); 
    8060    $count = count($array); 
     
    8969    } 
    9070 
     71    $this->currentRouteParameters = $this->fixDefaults($this->currentRouteParameters); 
     72 
    9173    return $this->currentRouteParameters; 
    9274  } 
    9375 
    9476  /** 
    95    * Gets the current compiled route array. 
    96    * 
    97    * @return array The route array 
     77   * @see sfRouting 
    9878   */ 
    9979  public function getRoutes() 
     
    10383 
    10484  /** 
    105    * Sets the compiled route array. 
    106    * 
    107    * @param array The route array 
    108    * 
    109    * @return array The route array 
     85   * @see sfRouting 
    11086   */ 
    11187  public function setRoutes($routes) 
     
    11591 
    11692  /** 
    117    * Returns true if this instance has some routes. 
    118    * 
    119    * @return  boolean 
     93   * @see sfRouting 
    12094   */ 
    12195  public function hasRoutes() 
     
    12599 
    126100  /** 
    127    * Clears all current routes. 
     101   * @see sfRouting 
    128102   */ 
    129103  public function clearRoutes() 
  • branches/1.1/lib/routing/sfPatternRouting.class.php

    r7517 r7518  
    5454 
    5555  /** 
    56    * Gets the internal URI for the current request. 
    57    * 
    58    * @param boolean Whether to give an internal URI with the route name (@route) 
    59    *                or with the module/action pair 
    60    * 
    61    * @return string The current internal URI 
    62    */ 
    63  
     56   * @see sfRouting 
     57   */ 
    6458  public function getCurrentInternalUri($withRouteName = false) 
    6559  { 
     
    6963    } 
    7064 
    71     $typeId = ($withRouteName) ? 0 : 1; 
     65    $typeId = $withRouteName ? 0 : 1; 
    7266 
    7367    if (!isset($this->currentInternalUri[$typeId])) 
     
    7771      list($url, $regexp, $names, $namesHash, $defaults, $requirements, $suffix) = $this->routes[$this->currentRouteName]; 
    7872 
    79       if ($withRouteName) 
    80       { 
    81         $internalUri = '@'.$this->currentRouteName; 
    82       } 
    83       else 
    84       { 
    85         $module = isset($parameters['module']) && $parameters['module'] ? $parameters['module'] : $this->options['default_module']; 
    86         $action = isset($parameters['action']) && $parameters['action'] ? $parameters['action'] : $this->options['default_action']; 
    87  
    88         $internalUri = $module.'/'.$action; 
    89       } 
     73      $internalUri = $withRouteName ? '@'.$this->currentRouteName : $parameters['module'].'/'.$parameters['action']; 
    9074 
    9175      $params = array(); 
     
    136120 
    137121  /** 
    138    * Gets the current compiled route array. 
    139    * 
    140    * @return array The route array 
     122   * @see sfRouting 
    141123   */ 
    142124  public function getRoutes() 
     
    146128 
    147129  /** 
    148    * Sets the compiled route array. 
    149    * 
    150    * @param array The route array 
    151    * 
    152    * @return array The route array 
     130   * @see sfRouting 
    153131   */ 
    154132  public function setRoutes($routes) 
     
    158136 
    159137  /** 
    160    * Returns true if this instance has some routes. 
    161    * 
    162    * @return  boolean 
     138   * @see sfRouting 
    163139   */ 
    164140  public function hasRoutes() 
     
    168144 
    169145  /** 
    170    * Clears all current routes. 
     146   * @see sfRouting 
    171147   */ 
    172148  public function clearRoutes() 
     
    346322 
    347323  /** 
    348    * Generates a valid URLs for parameters. 
    349    * 
    350    * @param  array  The parameter values 
    351    * @param  string The divider between key/value pairs 
    352    * @param  string The equal sign to use between key and value 
    353    * 
    354    * @return string The generated URL 
     324   * @see sfRouting 
    355325   */ 
    356326  public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/') 
    357327  { 
     328    $params = $this->fixDefaults($params); 
     329 
    358330    // named route? 
    359331    if ($name) 
     
    477449 
    478450  /** 
    479    * Parses a URL to find a matching route. 
    480    * 
    481    * Returns null if no route match the URL. 
    482    * 
    483    * @param  string URL to be parsed 
    484    * 
    485    * @return array  An array of parameters 
     451   * @see sfRouting 
    486452   */ 
    487453  public function parse($url) 
     
    509475 
    510476      list($route, $regexp, $names, $namesHash, $defaults, $requirements, $suffix) = $route; 
     477      $defaults = array_merge($defaults, $this->defaultParameters); 
    511478 
    512479      $break = false; 
     
    617584    } 
    618585 
    619     $this->currentRouteParameters = $out
     586    $this->currentRouteParameters = $this->fixDefaults($out)
    620587 
    621588    return $this->currentRouteParameters; 
  • branches/1.1/lib/routing/sfRouting.class.php

    r7517 r7518  
    2222    $dispatcher        = null, 
    2323    $defaultParameters = array(), 
     24    $defaultModule     = 'default', 
     25    $defaultAction     = 'index', 
    2426    $options           = array(); 
    2527 
     
    4951    $this->dispatcher = $dispatcher; 
    5052 
    51     if (!isset($options['default_module'])) 
    52     { 
    53       $options['default_module'] = 'default'
    54     } 
    55  
    56     if (!isset($options['default_action'])) 
    57     { 
    58       $options['default_action'] = 'index'
     53    if (isset($options['default_module'])) 
     54    { 
     55      $this->defaultModule = $options['default_module']
     56    } 
     57 
     58    if (isset($options['default_action'])) 
     59    { 
     60      $this->defaultAction = $options['default_action']
    5961    } 
    6062 
     
    143145 
    144146  /** 
    145    * Sets a default parameter for URL generation
     147   * Sets a default parameter
    146148   * 
    147149   * @param string The key 
     
    163165  } 
    164166 
     167  protected function fixDefaults($arr) 
     168  { 
     169    if (empty($arr['module'])) 
     170    { 
     171      $arr['module'] = $this->defaultModule; 
     172    } 
     173 
     174    if (empty($arr['action'])) 
     175    { 
     176      $arr['action'] = $this->defaultAction; 
     177    } 
     178 
     179    return $arr; 
     180  } 
     181 
    165182  /** 
    166183   * Listens to the user.change_culture event. 
  • branches/1.1/lib/task/generator/skeleton/app/app/config/settings.yml

    r7516 r7518  
    2222#all: 
    2323#  .actions: 
    24 #    default_module:         default   # Default module and action to be called when 
    25 #    default_action:         index     # A routing rule doesn't set it 
    26 # 
    2724#    error_404_module:       default   # To be called when a 404 error is raised 
    2825#    error_404_action:       error404  # Or when the requested URL doesn't match any route 
  • branches/1.1/test/unit/controller/sfWebControllerTest.php

    r4957 r7518  
    158158$controller->redirect('module/action?id=1#photos'); 
    159159$content = ob_get_clean(); 
    160 $t->like($content, '~http\://localhost/index.php/\?module=module&action=action&id=1#photos~', '->redirect() adds a refresh meta in the content'); 
    161 $t->like($context->getResponse()->getHttpHeader('Location'), '~http\://localhost/index.php/\?module=module&action=action&id=1#photos~', '->redirect() adds a Location HTTP header'); 
     160$t->like($content, '~http\://localhost/index.php/\?action=action&module=module&id=1#photos~', '->redirect() adds a refresh meta in the content'); 
     161$t->like($context->getResponse()->getHttpHeader('Location'), '~http\://localhost/index.php/\?action=action&module=module&id=1#photos~', '->redirect() adds a Location HTTP header'); 
    162162 
    163163// ->genUrl() 
     
    165165 
    166166$r = $context->getRouting(); 
    167 $t->is($controller->genUrl('module/action?id=4'), $controller->genUrl(array('module' => 'module', 'action' => 'action', 'id' => 4)), '->genUrl() accepts a string or an array as its first argument'); 
     167$t->is($controller->genUrl('module/action?id=4'), $controller->genUrl(array('action' => 'action', 'module' => 'module', 'id' => 4)), '->genUrl() accepts a string or an array as its first argument'); 
  • branches/1.1/test/unit/routing/sfPathInfoRoutingTest.php

    r4957 r7518  
    3232// ->parse() 
    3333$t->diag('parse'); 
    34 $t->is($routing->parse(''), array(), '->parse() parses a URL'); 
    35 $t->is($routing->parse('/foo/bar'), array('foo' => 'bar'), '->parse() parses a URL'); 
     34$t->is($routing->parse(''), array('module' => 'default', 'action' => 'index'), '->parse() parses a URL'); 
     35$t->is($routing->parse('/foo/bar'), array('module' => 'default', 'action' => 'index', 'foo' => 'bar'), '->parse() parses a URL'); 
    3636$t->is($routing->parse('/module/foo/action/bar'), array('module' => 'foo', 'action' => 'bar'), '->parse() parses a URL'); 
    3737$t->is($routing->parse('/module/foo/action/bar/foo/bar'), array('foo' => 'bar', 'module' => 'foo', 'action' => 'bar'), '->parse() parses a URL'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.