Development

/branches/1.1/lib/routing/sfPathInfoRouting.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/routing/sfPathInfoRouting.class.php

Revision 7779, 2.3 kB (checked in by fabien, 6 years ago)

change sfRouting::generate() signature to allow optional parameter value

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfPathInfoRouting class is a very simple routing class that uses PATH_INFO.
13  *
14  * @package    symfony
15  * @subpackage routing
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfPathInfoRouting extends sfRouting
20 {
21   protected
22     $currentRouteParameters = array();
23
24   /**
25    * @see sfRouting
26    */
27   public function getCurrentInternalUri($with_route_name = false)
28   {
29     $parameters = $this->currentRouteParameters;
30
31     // other parameters
32     unset($parameters['module'], $parameters['action']);
33     ksort($parameters);
34     $parameters = count($parameters) ? '?'.http_build_query($parameters, null, '&') : '';
35
36     return sprintf('%s/%s%s', $this->currentRouteParameters['module'], $this->currentRouteParameters['action'], $parameters);
37   }
38
39  /**
40   * @see sfRouting
41   */
42   public function generate($name, $params = array(), $querydiv = '/', $divider = '/', $equals = '/')
43   {
44     $url = '';
45     foreach ($this->mergeArrays($this->defaultParameters, $params) as $key => $value)
46     {
47       $url .= '/'.$key.'/'.$value;
48     }
49
50     return $url ? $url : '/';
51   }
52
53  /**
54   * @see sfRouting
55   */
56   public function parse($url)
57   {
58     $this->currentRouteParameters = $this->defaultParameters;
59     $array = explode('/', trim($url, '/'));
60     $count = count($array);
61
62     for ($i = 0; $i < $count; $i++)
63     {
64       // see if there's a value associated with this parameter, if not we're done with path data
65       if ($count > ($i + 1))
66       {
67         $this->currentRouteParameters[$array[$i]] = $array[++$i];
68       }
69     }
70
71     $this->currentRouteParameters = $this->fixDefaults($this->currentRouteParameters);
72
73     return $this->currentRouteParameters;
74   }
75
76   /**
77    * @see sfRouting
78    */
79   public function getRoutes()
80   {
81     return array();
82   }
83
84   /**
85    * @see sfRouting
86    */
87   public function setRoutes($routes)
88   {
89     return array();
90   }
91
92   /**
93    * @see sfRouting
94    */
95   public function hasRoutes()
96   {
97     return false;
98   }
99
100   /**
101    * @see sfRouting
102    */
103   public function clearRoutes()
104   {
105   }
106 }
107
Note: See TracBrowser for help on using the browser.