本文整理汇总了PHP中request_methods函数的典型用法代码示例。如果您正苦于以下问题:PHP request_methods函数的具体用法?PHP request_methods怎么用?PHP request_methods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request_methods函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_main_env
function test_main_env()
{
$env = env();
assert_true(is_array($env));
$vars = request_methods();
$vars[] = "SERVER";
foreach ($vars as $var) {
assert_true(array_key_exists($var, $env));
assert_true(is_array($env[$var]));
}
$_POST['_method'] = "PUT";
$_POST['my_var1'] = "value1";
$_POST['my_var2'] = "value2";
$env = env(null);
assert_equal($env['PUT']['my_var1'], "value1");
assert_equal($env['PUT']['my_var2'], "value2");
}
示例2: test_request_method
function test_request_method()
{
$env = env();
$env['SERVER']['REQUEST_METHOD'] = null;
assert_trigger_error("request_method");
$methods = request_methods();
foreach ($methods as $method) {
$env['SERVER']['REQUEST_METHOD'] = $method;
assert_equal(request_method($env), $method);
}
$env['SERVER']['REQUEST_METHOD'] = "POST";
$env['POST']['_method'] = "PUT";
assert_equal(request_method($env), "PUT");
$env['POST']['_method'] = "DELETE";
assert_equal(request_method($env), "DELETE");
$env['POST']['_method'] = "UNKOWN";
assert_trigger_error('request_method', array($env));
assert_false(request_method());
}
示例3: route_build
/**
* Build a route and return it
*
* @access private
* @param string $method
* @param string $path_or_array
* @param string $func
* @return array
*/
function route_build($method, $path_or_array, $func)
{
$method = strtoupper($method);
if (!in_array($method, request_methods())) {
trigger_error("'{$method}' request method is unkown or unavailable.", E_USER_WARNING);
}
if (is_array($path_or_array)) {
$path = array_shift($path_or_array);
$names = $path_or_array[0];
} else {
$path = $path_or_array;
$names = array();
}
$single_asterisk_subpattern = "(?:/([^\\/]*))?";
$double_asterisk_subpattern = "(?:/(.*))?";
$optionnal_slash_subpattern = "(?:/*?)";
$no_slash_asterisk_subpattern = "(?:([^\\/]*))?";
if ($path[0] == "^") {
if ($path[strlen($path) - 1] != "\$") {
$path .= "\$";
}
$pattern = "#" . $path . "#i";
} else {
if (empty($path) || $path == "/") {
$pattern = "#^" . $optionnal_slash_subpattern . "\$#";
} else {
$parsed = array();
$elts = explode('/', $path);
$parameters_count = 0;
foreach ($elts as $elt) {
if (empty($elt)) {
continue;
}
$name = null;
# extracting double asterisk **
if ($elt == "**") {
$parsed[] = $double_asterisk_subpattern;
$name = $parameters_count;
# extracting single asterisk *
} elseif ($elt == "*") {
$parsed[] = $single_asterisk_subpattern;
$name = $parameters_count;
# extracting named parameters :my_param
} elseif ($elt[0] == ":") {
if (preg_match('/^:([^\\:]+)$/', $elt, $matches)) {
$parsed[] = $single_asterisk_subpattern;
$name = $matches[1];
}
} elseif (strpos($elt, '*') !== false) {
$sub_elts = explode('*', $elt);
$parsed_sub = array();
foreach ($sub_elts as $sub_elt) {
$parsed_sub[] = preg_quote($sub_elt, "#");
$name = $parameters_count;
}
//
$parsed[] = "/" . implode($no_slash_asterisk_subpattern, $parsed_sub);
} else {
$parsed[] = "/" . preg_quote($elt, "#");
}
/* set parameters names */
if (is_null($name)) {
continue;
}
if (!array_key_exists($parameters_count, $names) || is_null($names[$parameters_count])) {
$names[$parameters_count] = $name;
}
$parameters_count++;
}
$pattern = "#^" . implode('', $parsed) . $optionnal_slash_subpattern . "?\$#i";
}
}
return array("method" => $method, "pattern" => $pattern, "names" => $names, "function" => $func);
}
示例4: route_build
/**
* Build a route and return it.
*
* @param string $method allowed http method (one of those returned by {@link request_methods()})
* @param string|array $path_or_array
* @param callback $callback callback called when route is found. It can be
* a function, an object method, a static method or a closure.
* See {@link http://php.net/manual/en/language.pseudo-types.php#language.types.callback php documentation}
* to learn more about callbacks.
* @param array $options (optional). Available options:
* - 'params' key with an array of parameters: for parametrized routes.
* those parameters will be merged with routes parameters.
*
* @return array array with keys "method", "pattern", "names", "callback", "options"
*/
function route_build($method, $path_or_array, $callback, $options = [])
{
$method = strtoupper($method);
if (!in_array($method, request_methods())) {
trigger_error("'{$method}' request method is unkown or unavailable.", E_USER_WARNING);
}
if (is_array($path_or_array)) {
$path = array_shift($path_or_array);
$names = $path_or_array[0];
} else {
$path = $path_or_array;
$names = [];
}
$single_asterisk_subpattern = "(?:/([^\\/]*))?";
$double_asterisk_subpattern = '(?:/(.*))?';
$optionnal_slash_subpattern = '(?:/*?)';
$no_slash_asterisk_subpattern = "(?:([^\\/]*))?";
if ($path[0] == '^') {
if ($path[strlen($path) - 1] != '$') {
$path .= '$';
}
$pattern = '#' . $path . '#i';
} elseif (empty($path) || $path == '/') {
$pattern = '#^' . $optionnal_slash_subpattern . '$#';
} else {
$parsed = [];
$elts = explode('/', $path);
$parameters_count = 0;
foreach ($elts as $elt) {
if (empty($elt)) {
continue;
}
$name = null;
# extracting double asterisk **
if ($elt == '**') {
$parsed[] = $double_asterisk_subpattern;
$name = $parameters_count;
# extracting single asterisk *
} elseif ($elt == '*') {
$parsed[] = $single_asterisk_subpattern;
$name = $parameters_count;
# extracting named parameters :my_param
} elseif ($elt[0] == ':') {
if (preg_match('/^:([^\\:]+)$/', $elt, $matches)) {
$parsed[] = $single_asterisk_subpattern;
$name = $matches[1];
}
} elseif (strpos($elt, '*') !== false) {
$sub_elts = explode('*', $elt);
$parsed_sub = [];
foreach ($sub_elts as $sub_elt) {
$parsed_sub[] = preg_quote($sub_elt, '#');
$name = $parameters_count;
}
//
$parsed[] = '/' . implode($no_slash_asterisk_subpattern, $parsed_sub);
} else {
$parsed[] = '/' . preg_quote($elt, '#');
}
/* set parameters names */
if (is_null($name)) {
continue;
}
if (!array_key_exists($parameters_count, $names) || is_null($names[$parameters_count])) {
$names[$parameters_count] = $name;
}
$parameters_count++;
}
$pattern = '#^' . implode('', $parsed) . $optionnal_slash_subpattern . '?$#i';
}
return ['method' => $method, 'pattern' => $pattern, 'names' => $names, 'callback' => $callback, 'options' => $options];
}