Skip to content

Commit

Permalink
Merge branch 'contributions' into 0.5
Browse files Browse the repository at this point in the history
Conflicts:
	lib/limonade.php
  • Loading branch information
Fabrice Luraine committed Nov 21, 2009
2 parents f6cf295 + 78d42db commit 96334e5
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions lib/limonade.php
Expand Up @@ -385,7 +385,7 @@ function route_missing($request_method, $request_uri)
call_if_exists('before');

# 6.4 Call matching controller function and output result
if($output = call_user_func($route['function']))
if($output = call_user_func_array($route['function'], array_values($route['params'])))
{
echo after(error_notices_render() . $output);
}
Expand Down Expand Up @@ -1031,9 +1031,9 @@ function request_uri($env = null)
*
* @return void
*/
function dispatch($path_or_array, $function)
function dispatch($path_or_array, $function, $params = array())
{
dispatch_get($path_or_array, $function);
dispatch_get($path_or_array, $function, $params);
}

/**
Expand All @@ -1043,10 +1043,10 @@ function dispatch($path_or_array, $function)
* @param string $function
* @return void
*/
function dispatch_get($path_or_array, $function)
function dispatch_get($path_or_array, $function, $params = array())
{
route("GET", $path_or_array, $function);
route("HEAD", $path_or_array, $function);
route("GET", $path_or_array, $function, $params);
route("HEAD", $path_or_array, $function, $params);
}

/**
Expand All @@ -1056,9 +1056,9 @@ function dispatch_get($path_or_array, $function)
* @param string $function
* @return void
*/
function dispatch_post($path_or_array, $function)
function dispatch_post($path_or_array, $function, $params = array())
{
route("POST", $path_or_array, $function);
route("POST", $path_or_array, $function, $params);
}

/**
Expand All @@ -1068,9 +1068,9 @@ function dispatch_post($path_or_array, $function)
* @param string $function
* @return void
*/
function dispatch_put($path_or_array, $function)
function dispatch_put($path_or_array, $function, $params = array())
{
route("PUT", $path_or_array, $function);
route("PUT", $path_or_array, $function, $params);
}

/**
Expand All @@ -1080,9 +1080,9 @@ function dispatch_put($path_or_array, $function)
* @param string $function
* @return void
*/
function dispatch_delete($path_or_array, $function)
function dispatch_delete($path_or_array, $function, $params = array())
{
route("DELETE", $path_or_array, $function);
route("DELETE", $path_or_array, $function, $params);
}


Expand Down Expand Up @@ -1111,8 +1111,9 @@ function route()
$method = $args[0];
$path_or_array = $args[1];
$func = $args[2];
$params = @$args[3];

$routes[] = route_build($method, $path_or_array, $func);
$routes[] = route_build($method, $path_or_array, $func, $params);
}
}
return $routes;
Expand All @@ -1138,7 +1139,7 @@ function route_reset()
* @param string $func
* @return array
*/
function route_build($method, $path_or_array, $func)
function route_build($method, $path_or_array, $func, $params = array())
{
$method = strtoupper($method);
if(!in_array($method, request_methods()))
Expand Down Expand Up @@ -1191,7 +1192,7 @@ function route_build($method, $path_or_array, $func)
elseif($elt == "*"):
$parsed[] = $single_asterisk_subpattern;
$name = $parameters_count;

# extracting named parameters :my_param
elseif($elt[0] == ":"):
if(preg_match('/^:([^\:]+)$/', $elt, $matches))
Expand Down Expand Up @@ -1229,7 +1230,8 @@ function route_build($method, $path_or_array, $func)
return array( "method" => $method,
"pattern" => $pattern,
"names" => $names,
"function" => $func );
"function" => $func,
"params" => $params );
}

/**
Expand All @@ -1250,7 +1252,7 @@ function route_find($method, $path)
{
if($method == $route["method"] && preg_match($route["pattern"], $path, $matches))
{
$params = array();
$params = $route["params"];
if(count($matches) > 1)
{
array_shift($matches);
Expand Down Expand Up @@ -2266,7 +2268,7 @@ function file_read($filename, $return = false)
*/
function file_list_dir($dir)
{
$files = array();
$files = array();
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
Expand All @@ -2285,4 +2287,4 @@ function file_list_dir($dir)



# ================================= END ================================== #
# ================================= END ================================== #

0 comments on commit 96334e5

Please sign in to comment.