Development

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

You must first sign up to be able to contribute.

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

Revision 20566, 2.6 kB (checked in by fabien, 5 years ago)

[1.3] deprecated sfNoRouting and sfPathInfoRouting classes

  • 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(), $absolute = false)
43   {
44     $parameters = $this->mergeArrays($this->defaultParameters, $params);
45     if ($this->getDefaultParameter('module') == $parameters['module'])
46     {
47       unset($parameters['module']);
48     }
49     if ($this->getDefaultParameter('action') == $parameters['action'])
50     {
51       unset($parameters['action']);
52     }
53
54     $url = '';
55     foreach ($parameters as $key => $value)
56     {
57       $url .= '/'.$key.'/'.$value;
58     }
59
60     return $this->fixGeneratedUrl($url ? $url : '/', $absolute);
61   }
62
63  /**
64   * @see sfRouting
65   */
66   public function parse($url)
67   {
68     $this->currentRouteParameters = $this->defaultParameters;
69     $array = explode('/', trim($url, '/'));
70     $count = count($array);
71
72     for ($i = 0; $i < $count; $i++)
73     {
74       // see if there's a value associated with this parameter, if not we're done with path data
75       if ($count > ($i + 1))
76       {
77         $this->currentRouteParameters[$array[$i]] = $array[++$i];
78       }
79     }
80
81     return $this->currentRouteParameters;
82   }
83
84   /**
85    * @see sfRouting
86    */
87   public function getRoutes()
88   {
89     return array();
90   }
91
92   /**
93    * @see sfRouting
94    */
95   public function setRoutes($routes)
96   {
97     return array();
98   }
99
100   /**
101    * @see sfRouting
102    */
103   public function hasRoutes()
104   {
105     return false;
106   }
107
108   /**
109    * @see sfRouting
110    */
111   public function clearRoutes()
112   {
113   }
114
115   protected function mergeArrays($arr1, $arr2)
116   {
117     foreach ($arr2 as $key => $value)
118     {
119       $arr1[$key] = $value;
120     }
121
122     return $arr1;
123   }
124 }
125
Note: See TracBrowser for help on using the browser.