本文整理汇总了PHP中Bluz\Proxy\Request::getMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getMethod方法的具体用法?PHP Request::getMethod怎么用?PHP Request::getMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bluz\Proxy\Request
的用法示例。
在下文中一共展示了Request::getMethod方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Prepare request for processing
*/
public function __construct()
{
// rewrite REST with "_method" param
// this is workaround
$this->method = strtoupper(Request::getParam('_method', Request::getMethod()));
// get all params
$query = Request::getQuery();
if (is_array($query) && !empty($query)) {
unset($query['_method']);
$this->params = $query;
}
$this->data = Request::getParams();
}
示例2: sendBody
/**
* Send body
*
* @return void
*/
protected function sendBody()
{
// Nobody for HEAD and OPTIONS
if (Request::METHOD_HEAD == ProxyRequest::getMethod() || Request::METHOD_OPTIONS == ProxyRequest::getMethod()) {
return;
}
// Body can be Closures
$content = $this->body;
if ($content instanceof \Closure) {
$content();
} else {
echo $content;
}
}
示例3: __construct
/**
* Prepare request for processing
*/
public function __construct()
{
// HTTP method
$method = Request::getMethod();
$this->method = strtoupper($method);
// get path
// %module% / %controller% / %id% / %relation% / %id%
$path = Router::getCleanUri();
$this->params = explode('/', rtrim($path, '/'));
// module
$this->module = array_shift($this->params);
// controller
$this->controller = array_shift($this->params);
$data = Request::getParams();
unset($data['_method'], $data['_module'], $data['_controller']);
$this->data = $data;
}
示例4: readSet
/**
* {@inheritdoc}
*
* @param int $offset
* @param int $limit
* @param array $params
* @return array|int|mixed
*/
public function readSet($offset = 0, $limit = 10, $params = array())
{
$select = Db::select('*')->from('test', 't');
if ($limit) {
$selectPart = $select->getQueryPart('select');
$selectPart = 'SQL_CALC_FOUND_ROWS ' . current($selectPart);
$select->select($selectPart);
$select->setLimit($limit);
$select->setOffset($offset);
}
$result = $select->execute('\\Application\\Test\\Row');
if ($limit) {
$total = Db::fetchOne('SELECT FOUND_ROWS()');
} else {
$total = sizeof($result);
}
if (sizeof($result) < $total && Request::METHOD_GET == Request::getMethod()) {
Response::setStatusCode(206);
Response::setHeader('Content-Range', 'items ' . $offset . '-' . ($offset + sizeof($result)) . '/' . $total);
}
return $result;
}
示例5:
break;
case 401:
$title = __("Unauthorized");
$description = __("You are not authorized to view this page, please sign in");
break;
case 403:
$title = __("Forbidden");
$description = __("You don't have permissions to access this page");
break;
case 404:
$title = __("Not Found");
$description = __("The page you requested was not found");
break;
case 405:
$title = __("Method Not Allowed");
$description = __("The server is not support method `%s`", Request::getMethod());
Response::setHeader('Allow', $message);
break;
case 406:
$title = __("Not Acceptable");
$description = __("The server is not acceptable generating content type described at `Accept` header");
break;
case 500:
$title = __("Internal Server Error");
$description = __("The server encountered an unexpected condition");
break;
case 501:
$title = __("Not Implemented");
$description = __("The server does not understand or does not support the HTTP method");
break;
case 503:
示例6: doProcess
/**
* Do process
* @return void
*/
protected function doProcess()
{
Logger::info("app:process:do");
$module = Request::getModule();
$controller = Request::getController();
$params = Request::getAllParams();
// try to dispatch controller
try {
// get reflection of requested controller
$controllerFile = $this->getControllerFile($module, $controller);
$reflection = $this->reflection($controllerFile);
// check header "accept" for catch JSON(P) or XML requests, and switch presentation
// it's some magic for AJAX and REST requests
if ($produces = $reflection->getAccept() and $accept = $this->getRequest()->getAccept()) {
// switch statement for $accept
switch ($accept) {
case Request::ACCEPT_HTML:
// with layout
// without additional presentation
break;
case Request::ACCEPT_JSON:
$this->useJson();
break;
case Request::ACCEPT_JSONP:
$this->useJsonp();
break;
case Request::ACCEPT_XML:
$this->useXml();
break;
default:
// not acceptable MIME type
throw new NotAcceptableException();
break;
}
}
// check call method(s)
if ($reflection->getMethod() && !in_array(Request::getMethod(), $reflection->getMethod())) {
throw new NotAllowedException(join(',', $reflection->getMethod()));
}
// check HTML cache
if ($reflection->getCacheHtml() && Request::getMethod() == Request::METHOD_GET) {
$htmlKey = 'html:' . $module . ':' . $controller . ':' . http_build_query($params);
if ($cachedHtml = Cache::get($htmlKey)) {
Response::setBody($cachedHtml);
return;
}
}
// dispatch controller
$dispatchResult = $this->dispatch($module, $controller, $params);
} catch (RedirectException $e) {
Response::setException($e);
if (Request::isXmlHttpRequest()) {
// 204 - No Content
Response::setStatusCode(204);
Response::setHeader('Bluz-Redirect', $e->getMessage());
} else {
Response::setStatusCode($e->getCode());
Response::setHeader('Location', $e->getMessage());
}
return null;
} catch (ReloadException $e) {
Response::setException($e);
if (Request::isXmlHttpRequest()) {
// 204 - No Content
Response::setStatusCode(204);
Response::setHeader('Bluz-Reload', 'true');
} else {
Response::setStatusCode($e->getCode());
Response::setHeader('Refresh', '0; url=' . Request::getRequestUri());
}
return null;
} catch (\Exception $e) {
Response::setException($e);
// cast to valid HTTP error code
// 500 - Internal Server Error
$statusCode = 100 <= $e->getCode() && $e->getCode() <= 505 ? $e->getCode() : 500;
Response::setStatusCode($statusCode);
$dispatchResult = $this->dispatch(Router::getErrorModule(), Router::getErrorController(), array('code' => $e->getCode(), 'message' => $e->getMessage()));
}
if ($this->hasLayout()) {
Layout::setContent($dispatchResult);
$dispatchResult = Layout::getInstance();
}
if (isset($htmlKey, $reflection)) {
// @TODO: Added ETag header
Cache::set($htmlKey, $dispatchResult(), $reflection->getCacheHtml());
Cache::addTag($htmlKey, $module);
Cache::addTag($htmlKey, 'html');
Cache::addTag($htmlKey, 'html:' . $module);
Cache::addTag($htmlKey, 'html:' . $module . ':' . $controller);
}
Response::setBody($dispatchResult);
}
示例7: function
namespace Application;
use Bluz\Application\Exception\BadRequestException;
use Bluz\Application\Exception\NotImplementedException;
use Bluz\Proxy\Messages;
use Bluz\Proxy\Request;
use Bluz\Validator\Exception\ValidatorException;
/**
* @accept HTML
* @accept JSON
* @method PUT
*
* @param \Bluz\Crud\Table $crud
* @param mixed $primary
* @param array $data
* @return void|array
* @throws BadRequestException
* @throws NotImplementedException
*/
return function ($crud, $primary, $data) {
try {
// Result is numbers of affected rows
$crud->updateOne($primary, $data);
Messages::addSuccess("Record was updated");
return ['row' => $crud->readOne($primary), 'method' => Request::getMethod()];
} catch (ValidatorException $e) {
$row = $crud->readOne($primary);
$row->setFromArray($data);
return ['row' => $row, 'errors' => $e->getErrors(), 'method' => Request::getMethod()];
}
};
示例8: checkMethod
/**
* Check `Method`
*
* @throws NotAllowedException
*/
public function checkMethod()
{
if ($this->getReflection()->getMethod() && !in_array(Request::getMethod(), $this->getReflection()->getMethod())) {
Response::setHeader('Allow', join(',', $this->getReflection()->getMethod()));
throw new NotAllowedException();
}
}
示例9: function
<?php
/**
* Test AJAX
*
* @author Anton Shevchuk
* @created 26.09.11 17:41
* @return closure
*/
namespace Application;
use Bluz\Proxy\Messages;
use Bluz\Proxy\Request;
return function ($messages = false) use($view) {
/**
* @var Bootstrap $this
* @var \Bluz\View\View $view
*/
if ($messages) {
Messages::addNotice('Notice for AJAX call');
Messages::addSuccess('Success for AJAX call');
Messages::addError('Error for AJAX call');
$view->baz = 'qux';
}
Messages::addNotice('Method ' . Request::getMethod());
$view->foo = 'bar';
};