/**
  * @see sfRequestRoute
  */
 public function generate($params, $context = array(), $absolute = false)
 {
     if (!isset($this->options['host_route'])) {
         return parent::generate($params, $context, $absolute);
     }
     $hostParams = $this->extractHostParams($params);
     $protocol = isset($context['is_secure']) && $context['is_secure'] ? 'https' : 'http';
     $host = $this->options['host_route']->generate($hostParams, $context, false);
     $prefix = isset($context['prefix']) ? $context['prefix'] : '';
     $uri = parent::generate($params, $context, false);
     return $protocol . ':/' . $host . $prefix . $uri;
 }
 public function matchesUrl($url, $context = array())
 {
     $parameters = parent::matchesUrl($url, $context);
     if (!$parameters) {
         return false;
     }
     $queryParameters = $this->getQueryParameters($context);
     $sfContext = sfContext::getInstance();
     if ($this->shouldThisRouteBeSigned()) {
         $urlSigner = new UrlSigner();
         $urlSigner->redirectIfUrlIsNotSigned($queryParameters, $sfContext, $this->getSecretKey());
         return $parameters;
     }
     return $parameters;
 }
예제 #3
0
 /**
  * Generates a URL from the given parameters.
  *
  * @param  mixed   $params    The parameter values
  * @param  array   $context   The context
  * @param  Boolean $absolute  Whether to generate an absolute URL
  *
  * @return string The generated URL
  */
 public function generate($params, $context = array(), $absolute = false)
 {
     return parent::generate('object' == $this->options['type'] ? $this->convertObjectToArray($params) : $params, $context, $absolute);
 }
예제 #4
0
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(8);
// ->__construct()
$t->diag('->__construct()');
$route = new sfRequestRoute('/');
$requirements = $route->getRequirements();
$t->is_deeply($requirements['sf_method'], array('get', 'head'), '->__construct() applies a default "sf_method" requirement of GET or HEAD');
$route = new sfRequestRoute('/', array(), array('sf_method' => array('post')));
$requirements = $route->getRequirements();
$t->is_deeply($requirements['sf_method'], array('post'), '->__construct() does not apply a default "sf_method" requirement if one is already set');
$route = new sfRequestRoute('/', array(), array('sf_method' => 'get'));
$requirements = $route->getRequirements();
$t->is_deeply($requirements['sf_method'], array('get'), '->__construct() converts a string "sf_method" requirement to an array');
// ->matchesParameters()
$t->diag('->matchesParameters()');
$route = new sfRequestRoute('/', array(), array('sf_method' => array('get', 'head')));
$t->ok($route->matchesParameters(array('sf_method' => 'get')), '->matchesParameters() matches the "sf_method" parameter');
$route = new sfRequestRoute('/', array(), array('sf_method' => array('get')));
$t->ok($route->matchesParameters(array('sf_method' => 'GET')), '->matchesParameters() checks "sf_method" requirement case-insensitively');
$route = new sfRequestRoute('/', array(), array('sf_method' => array('GET')));
$t->ok($route->matchesParameters(array('sf_method' => 'get')), '->matchesParameters() checks "sf_method" requirement case-insensitively');
// ->matchesUrl()
$t->diag('->matchesUrl()');
$route = new sfRequestRoute('/', array(), array('sf_method' => 'GET'));
$t->isa_ok($route->matchesUrl('/', array('method' => 'get')), 'array', '->matchesUrl() check "sf_method" requirement case-insensitively');
$route = new sfRequestRoute('/', array(), array('sf_method' => 'get'));
$t->isa_ok($route->matchesUrl('/', array('method' => 'GET')), 'array', '->matchesUrl() check "sf_method" requirement case-insensitively');
예제 #5
0
 protected function doConvertObjectToArray($object)
 {
     if (isset($this->options['convert']) || method_exists($object, 'toParams')) {
         return parent::doConvertObjectToArray($object);
     }
     $peerName = constant($this->options['model'] . '::PEER');
     $parameters = array();
     foreach ($this->getRealVariables() as $variable) {
         try {
             $method = 'get' . call_user_func(array($peerName, 'translateFieldName'), $variable, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $method = 'get' . sfInflector::camelize($variable);
         }
         $parameters[$variable] = $object->{$method}();
     }
     return $parameters;
 }
 /**
  * Generates a URL from the given parameters.
  *
  * @param  mixed   $params    The parameter values
  * @param  array   $context   The context
  * @param  Boolean $absolute  Whether to generate an absolute URL
  *
  * @return string The generated URL
  */
 public function generate($params, $context = array(), $absolute = false)
 {
     return urldecode(parent::generate($this->convertObjectToArray($params), $context, $absolute));
 }
예제 #7
0
 public function matchesParameters($params, $context = array())
 {
     $params = array_merge(array('username' => $this->getUserId()), $params);
     return parent::matchesParameters($params, $context);
 }