| src/Pluf/HTTP/URL.php |
| 89 | 89 | function Pluf_HTTP_URL_urlForView($view, $params=array(), |
| 90 | 90 | $get_params=array(), $encoded=true) |
| 91 | 91 | { |
| 92 | | $action = Pluf_HTTP_URL_reverse($view, $params); |
| 93 | | if (!is_array($get_params)) { |
| 94 | | throw new Exception('Bad call to urlForView.'); |
| 95 | | } |
| 96 | | return Pluf_HTTP_URL::generate($action, $get_params, $encoded); |
| 92 | return Pluf_HTTP_URL::generate(Pluf_HTTP_URL_reverse($view, $params), |
| 93 | $get_params, $encoded); |
| 97 | 94 | } |
| 98 | 95 | |
| 99 | 96 | /** |
| ... | ... | |
| 172 | 169 | */ |
| 173 | 170 | function Pluf_HTTP_URL_buildReverseUrl($url_regex, $params=array()) |
| 174 | 171 | { |
| 175 | | $url_regex = str_replace('\\.', '.', $url_regex); |
| 176 | | $url_regex = str_replace('\\-', '-', $url_regex); |
| 177 | | $url = $url_regex; |
| 178 | | $groups = '#\(([^)]+)\)#'; |
| 179 | | $matches = array(); |
| 180 | | preg_match_all($groups, $url_regex, $matches); |
| 181 | | reset($params); |
| 182 | | if (count($matches[0]) && count($matches[0]) == count($params)) { |
| 183 | | // Test the params against the pattern |
| 184 | | foreach ($matches[0] as $pattern) { |
| 185 | | $in = current($params); |
| 186 | | if (0 === preg_match('#'.$pattern.'#', $in)) { |
| 187 | | throw new Exception('Error, param: '.$in.' is not matching the pattern: '.$pattern); |
| 188 | | } |
| 189 | | next($params); |
| 190 | | } |
| 191 | | $func = create_function('$matches', |
| 192 | | 'static $p = '.var_export($params, true).'; '. |
| 193 | | '$a = current($p); '. |
| 194 | | 'next($p); '. |
| 195 | | 'return $a;'); |
| 196 | | $url = preg_replace_callback($groups, $func, $url_regex); |
| 172 | $url = str_replace(array('\\.', '\\-'), array('.', '-'), $url_regex); |
| 173 | if (count($params)) { |
| 174 | $groups = array_fill(0, count($params), '#\(([^)]+)\)#'); |
| 175 | $url = preg_replace($groups, $params, $url, 1); |
| 197 | 176 | } |
| 198 | 177 | preg_match('/^#\^?([^#\$]+)/', $url, $matches); |
| 199 | 178 | return $matches[1]; |