Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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: sfRequestRoute.class.php 20784 2009-08-04 20:53:57Z Kris.Wallsmith $
20
 */
21
class sfRequestRoute extends sfRoute
22
{
23
  /**
24
   * Constructor.
25
   *
26
   * Applies a default sf_method requirements of GET or HEAD.
27
   *
28
   * @see sfRoute
29
   */
30
  public function __construct($pattern, $defaults = array(), $requirements = array(), $options = array())
31
  {
32
    if (!isset($requirements['sf_method']))
33
    {
34
      $requirements['sf_method'] = array('get', 'head');
35
    }
36
    else
37
    {
38
      $requirements['sf_method'] = array_map('strtolower', (array) $requirements['sf_method']);
39
    }
40
 
41
    parent::__construct($pattern, $defaults, $requirements, $options);
42
  }
43
 
44
  /**
45
   * Returns true if the URL matches this route, false otherwise.
46
   *
47
   * @param  string  $url     The URL
48
   * @param  array   $context The context
49
   *
50
   * @return array   An array of parameters
51
   */
52
  public function matchesUrl($url, $context = array())
53
  {
54
    if (false === $parameters = parent::matchesUrl($url, $context))
55
    {
56
      return false;
57
    }
58
 
59
    // enforce the sf_method requirement
60
    if (in_array(strtolower($context['method']), $this->requirements['sf_method']))
61
    {
62
      return $parameters;
63
    }
64
 
65
    return false;
66
  }
67
 
68
  /**
69
   * Returns true if the parameters match this route, false otherwise.
70
   *
71
   * @param  mixed   $params The parameters
72
   * @param  array   $context The context
73
   *
74
   * @return Boolean true if the parameters match this route, false otherwise.
75
   */
76
  public function matchesParameters($params, $context = array())
77
  {
78
    if (isset($params['sf_method']))
79
    {
80
      // enforce the sf_method requirement
81
      if (!in_array(strtolower($params['sf_method']), $this->requirements['sf_method']))
82
      {
83
        return false;
84
      }
85
 
86
      unset($params['sf_method']);
87
    }
88
 
89
    return parent::matchesParameters($params, $context);
90
  }
91
 
92
  /**
93
   * Generates a URL from the given parameters.
94
   *
95
   * @param  mixed   $params    The parameter values
96
   * @param  array   $context   The context
97
   * @param  Boolean $absolute  Whether to generate an absolute URL
98
   *
99
   * @return string The generated URL
100
   */
101
  public function generate($params, $context = array(), $absolute = false)
102
  {
103
    unset($params['sf_method']);
104
 
105
    return parent::generate($params, $context, $absolute);
106
  }
107
}