Pluf Framework

Pluf Framework Commit Details


Date:2009-04-25 07:22:38 (15 years 7 months ago)
Author:Loic d'Anterroches
Branch:develop, master
Commit:d5c95dc2751d97ecf05e576ad106168f47bc02eb
Parents: 7809b1ae1138252f1cad5c0d9a3b8a9705a6ad6d
Message:Optimized the reverse URL generation.

Changes:

File differences

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

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.06920s using 13 queries.