Development

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

You must first sign up to be able to contribute.

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

Revision 17403, 2.6 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3] made $params an optional argument in sfRoute::generate() as not all routes require parameters

  • 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) 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  * sfRequestRoute represents a route that is request aware.
13  *
14  * It implements the sf_method requirement.
15  *
16  * @package    symfony
17  * @subpackage routing
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfRequestRoute extends sfRoute
22 {
23   /**
24    * Returns true if the URL matches this route, false otherwise.
25    *
26    * @param  string  $url     The URL
27    * @param  array   $context The context
28    *
29    * @return array   An array of parameters
30    */
31   public function matchesUrl($url, $context = array())
32   {
33     if (false === $parameters = parent::matchesUrl($url, $context))
34     {
35       return false;
36     }
37
38     if (!isset($this->requirements['sf_method']))
39     {
40       $this->requirements['sf_method'] = array('get', 'head');
41     }
42
43     // enforce the sf_method requirement
44     $methods = is_array($this->requirements['sf_method']) ? $this->requirements['sf_method'] : array($this->requirements['sf_method']);
45     foreach ($methods as $method)
46     {
47       if (0 == strcasecmp($method, $context['method']))
48       {
49         return $parameters;
50       }
51     }
52
53     return false;
54   }
55
56   /**
57    * Returns true if the parameters matches this route, false otherwise.
58    *
59    * @param  mixed   $params The parameters
60    * @param  array   $context The context
61    *
62    * @return Boolean         true if the parameters matches this route, false otherwise.
63    */
64   public function matchesParameters($params, $context = array())
65   {
66     if (isset($params['sf_method']))
67     {
68       if (!isset($this->requirements['sf_method']))
69       {
70         $this->requirements['sf_method'] = 'get';
71       }
72
73       // enforce the sf_method requirement
74       if ($this->requirements['sf_method'] != $params['sf_method'])
75       {
76         return false;
77       }
78
79       unset($params['sf_method']);
80     }
81
82     return parent::matchesParameters($params, $context);
83   }
84
85   /**
86    * Generates a URL from the given parameters.
87    *
88    * @param  mixed   $params    The parameter values
89    * @param  array   $context   The context
90    * @param  Boolean $absolute  Whether to generate an absolute URL
91    *
92    * @return string The generated URL
93    */
94   public function generate($params = array(), $context = array(), $absolute = false)
95   {
96     unset($params['sf_method']);
97
98     return parent::generate($params, $context, $absolute);
99   }
100 }
101
Note: See TracBrowser for help on using the browser.