/** * Reverse an URL. * * @param string View in the form 'class::method' or string of the name. * @param array Possible parameters for the view (array()). * @return string URL. */ function Pluf_HTTP_URL_reverse($view, $params = array()) { $model = ''; $method = ''; if (false !== strpos($view, '::')) { list($model, $method) = explode('::', $view); } $vdef = array($model, $method, $view); $regbase = array('', array()); $regbase = Pluf_HTTP_URL_find($GLOBALS['_PX_views'], $vdef, $regbase); if ($regbase === false) { throw new Exception(sprintf('Error, the view: %s has not been found.', $view)); } $url = ''; foreach ($regbase[1] as $regex) { $url .= Pluf_HTTP_URL_buildReverseUrl($regex, $params); } if (!defined('IN_UNIT_TESTS')) { $url = $regbase[0] . $url; } return $url; }
public function testReverseMultipleArgUrlFailure() { $url_regex = '#^/toto/(\\s+)/asd/(.*)/$#'; $params = array('23', 'titi'); try { $url = Pluf_HTTP_URL_buildReverseUrl($url_regex, $params); } catch (Exception $e) { return; } $this->fail('An exception as not been raised, regex:' . $url_regex . ' should not match params: ' . var_export($params, true)); }