本文整理汇总了PHP中Q::fromRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::fromRequest方法的具体用法?PHP Q::fromRequest怎么用?PHP Q::fromRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q
的用法示例。
在下文中一共展示了Q::fromRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
public static function request($name = null)
{
if ($name === null) {
return Q::fromRequest('post', 'get');
}
if (isset(self::$_POST[$name])) {
return self::$_POST[$name];
}
if (isset(self::$_GET[$name])) {
return self::$_GET[$name];
}
self::$_POST[$name] = isset($_POST[$name]) ? self::clean($_POST[$name]) : null;
self::$_GET[$name] = isset($_GET[$name]) ? self::clean($_GET[$name]) : null;
return self::$_POST[$name] ? self::$_POST[$name] : self::$_GET[$name];
}
示例2: __construct
public function __construct($fromRequest, $path = null, $method = null, $get = array(), $post = array(), $cookies = array(), $headers = array(), $body = null)
{
if (!count(self::$dirs)) {
throw new Exception('No controller directories have been registered! (Use Controller::registerDirectory(...))');
}
$sep = DIRECTORY_SEPARATOR;
if (is_array($path)) {
$path = $sep . Saffyre::cleanPath($path, true);
}
$this->path = Saffyre::cleanPath($path);
$max = null;
foreach (self::$dirs as $dir) {
$info = ['dir' => $dir['dir'] . $sep, 'args' => [], 'file' => $this->path];
do {
$file = implode($sep, $info['file']);
if (is_file("{$info['dir']}{$sep}{$file}{$sep}_default.php") && ($info['file'][] = '_default')) {
break;
}
if (is_file("{$info['dir']}{$sep}{$file}.php")) {
break;
}
array_unshift($info['args'], $slug = array_pop($info['file']));
} while ($slug);
if (count(Util::array_clean($info['file'], '_default')) > count(Util::array_clean($max['file'], '_default'))) {
$max = $info;
}
}
if (!$max || !$max['file']) {
throw new Exception('Invalid controller path. Maybe you don\'t have a _default.php file.');
}
$this->dir = $max['dir'];
$this->args = $max['args'];
$this->file = $max['file'];
$this->get = $fromRequest ? Q::fromRequest('get') : new Q();
$this->post = $fromRequest ? Q::fromRequest('post') : new Q();
$this->cookie = $fromRequest ? Q::fromRequest('cookie') : new Q();
$this->headers = new Q();
if ($fromRequest) {
$this->uri = $_SERVER['REQUEST_URI'];
$this->method = strtoupper($_SERVER['REQUEST_METHOD']);
foreach ($_SERVER as $key => $value) {
if (strpos($key, 'HTTP_') === 0) {
$this->headers->{strtolower(str_replace(array('HTTP_', '_'), array('', '-'), $key))} = $value;
}
}
}
if ($path !== null) {
$this->uri = $path;
}
if ($method !== null) {
$this->method = strtoupper($method);
}
$this->get->__import($get);
$this->post->__import($post);
$this->cookie->__import($cookies);
$this->headers->__import($headers);
if ($body !== null) {
if (is_object($body)) {
$body = json_encode($body);
}
$this->body = $body;
}
}