本文整理汇总了PHP中Request::method方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::method方法的具体用法?PHP Request::method怎么用?PHP Request::method使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _send_message
/**
* Sends the HTTP message [Request] to a remote server and processes
* the response.
*
* @param Request $request request to send
* @param Response $request response to send
* @return Response
*/
public function _send_message(Request $request, Response $response)
{
$http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
// Create an http request object
$http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
if ($this->_options) {
// Set custom options
$http_request->setOptions($this->_options);
}
// Set headers
$http_request->setHeaders($request->headers()->getArrayCopy());
// Set cookies
$http_request->setCookies($request->cookie());
// Set query data (?foo=bar&bar=foo)
$http_request->setQueryData($request->query());
// Set the body
if ($request->method() == HTTP_Request::PUT) {
$http_request->addPutData($request->body());
} else {
$http_request->setBody($request->body());
}
try {
$http_request->send();
} catch (HTTPRequestException $e) {
throw new Request_Exception($e->getMessage());
} catch (HTTPMalformedHeaderException $e) {
throw new Request_Exception($e->getMessage());
} catch (HTTPEncodingException $e) {
throw new Request_Exception($e->getMessage());
}
// Build the response
$response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
return $response;
}
示例2: testMethodReturnsTheHTTPRequestMethod
/**
* Test the Request::method method.
*
* @group laravel
*/
public function testMethodReturnsTheHTTPRequestMethod()
{
$this->setServerVar('REQUEST_METHOD', 'POST');
$this->assertEquals('POST', Request::method());
$this->setPostVar(Request::spoofer, 'PUT');
$this->assertEquals('PUT', Request::method());
}
示例3: on_header_location
/**
* The default handler for following redirects, triggered by the presence of
* a Location header in the response.
*
* The client's follow property must be set TRUE and the HTTP response status
* one of 201, 301, 302, 303 or 307 for the redirect to be followed.
*
* @param Request $request
* @param Response $response
* @param Request_Client $client
*/
public static function on_header_location(Request $request, Response $response, Request_Client $client)
{
// Do we need to follow a Location header ?
if ($client->follow() and in_array($response->status(), [201, 301, 302, 303, 307])) {
// Figure out which method to use for the follow request
switch ($response->status()) {
default:
case 301:
case 307:
$follow_method = $request->method();
break;
case 201:
case 303:
$follow_method = Request::GET;
break;
case 302:
// Cater for sites with broken HTTP redirect implementations
if ($client->strict_redirect()) {
$follow_method = $request->method();
} else {
$follow_method = Request::GET;
}
break;
}
// Prepare the additional request, copying any follow_headers that were present on the original request
$orig_headers = $request->headers()->getArrayCopy();
$follow_headers = array_intersect_assoc($orig_headers, array_fill_keys($client->follow_headers(), true));
$follow_request = Request::factory($response->headers('Location'))->method($follow_method)->headers($follow_headers);
if ($follow_method !== Request::GET) {
$follow_request->body($request->body());
}
return $follow_request;
}
return null;
}
示例4: signPacket
/**
* Generates a signature for a packet request response
*
* @param array $packet
* @param int|null $code
* @param string|\Exception|null $message
*
* @return array
*
*/
protected static function signPacket(array $packet, $code = null, $message = null)
{
$_ex = false;
if ($code instanceof \Exception) {
$_ex = $code;
$code = null;
} elseif ($message instanceof \Exception) {
$_ex = $message;
$message = null;
}
!$code && ($code = Response::HTTP_OK);
$code = $code ?: ($_ex ? $_ex->getCode() : Response::HTTP_OK);
$message = $message ?: ($_ex ? $_ex->getMessage() : null);
$_startTime = \Request::server('REQUEST_TIME_FLOAT', \Request::server('REQUEST_TIME', $_timestamp = microtime(true)));
$_elapsed = $_timestamp - $_startTime;
$_id = sha1($_startTime . \Request::server('HTTP_HOST') . \Request::server('REMOTE_ADDR'));
// All packets have this
$_packet = array_merge($packet, ['error' => false, 'status_code' => $code, 'request' => ['id' => $_id, 'version' => static::PACKET_VERSION, 'signature' => base64_encode(hash_hmac(config('dfe.signature-method'), $_id, $_id, true)), 'verb' => \Request::method(), 'request-uri' => \Request::getRequestUri(), 'start' => date('c', $_startTime), 'elapsed' => (double) number_format($_elapsed, 4)]]);
// Update the error entry if there was an error
if (!array_get($packet, 'success', false) && !array_get($packet, 'error', false)) {
$_packet['error'] = ['code' => $code, 'message' => $message, 'exception' => $_ex ? Json::encode($_ex) : false];
} else {
array_forget($_packet, 'error');
}
return $_packet;
}
示例5: format
/**
* @param \Exception $exception
* @return \Illuminate\Http\JsonResponse
*/
public function format($exception)
{
// Define the response
$result = ['errors' => trans('messages.sorry')];
// Default response of 400
$statusCode = 400;
$addDebugData = $this->isDebugEnabled();
switch (true) {
case $exception instanceof HttpException:
$statusCode = $exception->getStatusCode();
$result['errors'] = $exception->getMessage();
break;
case $exception instanceof ValidationException:
$result['errors'] = $exception->errors();
$addDebugData = false;
break;
}
// Prepare response
$response = ['success' => false, 'result' => $result, 'meta' => ['version' => config('app.version.api'), 'request' => \Request::method() . ' ' . \Request::url(), 'debug' => $this->isDebugEnabled()]];
// If the app is in debug mode && not Validation exception
if ($addDebugData) {
$response['debug'] = ['exception' => get_class($exception), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace()];
}
// Return a JSON response with the response array and status code
return response()->json($response, $statusCode);
}
示例6: my_schedule
public function my_schedule()
{
if (Auth::check()) {
$data["inside_url"] = Config::get('app.inside_url');
$data["user"] = Session::get('user');
$data["actions"] = Session::get('actions');
if (in_array('side_mi_horario', $data["actions"])) {
$current_ay = AcademicYear::getCurrentAcademicYear();
if (!$current_ay) {
return View::make('schedule/academic_year_error', $data);
}
$student = $data["user"]->student;
$data["enrollment_info"] = $student->getCurrentEnrollment();
$data["level"] = $data["enrollment_info"]->level;
$data["schedules_data"] = $data["level"]->schedules()->orderBy('initial_hour')->get();
return View::make('schedule/my_schedule', $data);
} else {
// Llamo a la función para registrar el log de auditoria
$log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
Helpers::registerLog(10, $log_description);
Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
return Redirect::to('/dashboard');
}
} else {
return View::make('error/error');
}
}
示例7: readDbObjectForInjection
/**
* @param $parameters
*/
protected function readDbObjectForInjection($parameters)
{
/** @var Route $route */
$route = \Request::route();
$object = null;
foreach ($parameters as $key => $value) {
if ($value instanceof CmfDbObject) {
// get only last object in params
$object = $value;
}
}
if (!empty($object)) {
$id = $route->parameter('id', false);
if ($id === false && \Request::method() !== 'GET') {
$id = \Request::get('id', false);
}
if (empty($id)) {
$this->sendRecordNotFoundResponse();
}
$conditions = ['id' => $id];
$this->addConditionsForDbObjectInjection($route, $object, $conditions);
$this->addParentIdsConditionsForDbObjectInjection($route, $object, $conditions);
$object->find($conditions);
if (!$object->exists()) {
$this->sendRecordNotFoundResponse();
}
}
}
示例8: action_edit
public function action_edit($id)
{
$post = \Blog\Models\Post::find($id);
if ($post === null) {
return Event::first('404');
}
if (Str::lower(Request::method()) == "post") {
$validator = Validator::make(Input::all(), self::$rules);
if ($validator->passes()) {
$post->title = Input::get('title');
if (Input::get('slug')) {
$post->slug = Str::slug(Input::get('slug'));
} else {
$post->slug = Str::slug(Input::get('title'));
}
$post->intro = Input::get('intro');
$post->content = Input::get('content');
$post->author_id = Input::get('author_id');
$post->category_id = Input::get('category_id');
$post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time');
$post->save();
return Redirect::to_action('blog::admin.post@list');
} else {
return Redirect::back()->with_errors($validator)->with_input();
}
} else {
$categories = array();
$originalCategories = \Blog\Models\Category::all();
foreach ($originalCategories as $cat) {
$categories[$cat->id] = $cat->name;
}
return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories);
}
}
示例9: instance
public static function instance(&$uri = TRUE)
{
if (!Request::$instance) {
if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
Request::$protocol = 'https';
}
if (isset($_SERVER['REQUEST_METHOD'])) {
Request::$method = $_SERVER['REQUEST_METHOD'];
}
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
Request::$is_ajax = TRUE;
}
Request::$client_ip = self::get_client_ip();
if (Request::$method !== 'GET' and Request::$method !== 'POST') {
parse_str(file_get_contents('php://input'), $_POST);
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
}
if (isset($_SERVER['HTTP_REFERER'])) {
Request::$referrer = $_SERVER['HTTP_REFERER'];
}
if ($uri === TRUE) {
$uri = Request::detect_uri();
}
$uri = preg_replace('#//+#', '/', $uri);
$uri = preg_replace('#\\.[\\s./]*/#', '', $uri);
Request::$instance = new Request($uri);
}
return Request::$instance;
}
示例10: start
public static function start($path_info)
{
$path_info = "/" . ltrim($path_info, "/");
$failed = true;
$args;
switch (Request::method()) {
case "GET":
$map = self::$map_get;
break;
case "POST":
$map = self::$map_post;
break;
default:
$map = $map_other_methods;
}
foreach ($map as $re => $fn) {
if (preg_match("/" . str_replace("/", "\\/", $re) . "/", $path_info, $args)) {
array_shift($args);
$args = array_map(function ($arg) {
return urldecode($arg);
}, $args);
try {
call_user_func_array($fn, $args);
$failed = false;
break;
} catch (NextRoute $e) {
}
}
}
if ($failed) {
not_found();
}
}
示例11: validate
/**
* @param Request $request
* @return RouteResult
*/
public function validate(Request $request)
{
$parameters = [];
$matched = $this->method === $request->method();
$matched = $matched && preg_match($this->path, $request->path(), $parameters);
return new RouteResult($matched, $parameters, $this->response_factory);
}
示例12: onAfterInitialise
/**
* Converting the site URL to fit to the HTTP request
*
* @return void
*/
public function onAfterInitialise()
{
if (App::isAdmin() || Config::get('debug')) {
return;
}
if (Notify::any()) {
return;
}
if (User::isGuest() && Request::method() == 'GET') {
$id = $this->getId();
if ($data = App::get('cache')->get($id)) {
App::get('response')->setContent($data);
App::get('response')->compress(App::get('config')->get('gzip', false));
if ($this->params->get('browsercache', false)) {
App::get('response')->headers->set('HTTP/1.x 304 Not Modified', true);
}
App::get('response')->headers->set('ETag', $id);
App::get('response')->send();
if ($profiler = App::get('profiler')) {
$profiler->mark('afterCache');
echo implode('', $profiler->marks());
}
App::close();
}
}
}
示例13: _send_message
/**
* Sends the HTTP message [Request] to a remote server and processes
* the response.
*
* @param Request request to send
* @return Response
* @uses [PHP cURL](http://php.net/manual/en/book.curl.php)
*/
public function _send_message(Request $request)
{
// Calculate stream mode
$mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+';
// Process cookies
if ($cookies = $request->cookie()) {
$request->headers('cookie', http_build_query($cookies, NULL, '; '));
}
// Get the message body
$body = $request->body();
if (is_resource($body)) {
$body = stream_get_contents($body);
}
// Set the content length
$request->headers('content-length', (string) strlen($body));
list($protocol) = explode('/', $request->protocol());
// Create the context
$options = array(strtolower($protocol) => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $body));
// Create the context stream
$context = stream_context_create($options);
stream_context_set_option($context, $this->_options);
$uri = $request->uri();
if ($query = $request->query()) {
$uri .= '?' . http_build_query($query, NULL, '&');
}
$stream = fopen($uri, $mode, FALSE, $context);
$meta_data = stream_get_meta_data($stream);
// Get the HTTP response code
$http_response = array_shift($meta_data['wrapper_data']);
if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) {
$protocol = $matches[1][0];
$status = (int) $matches[2][0];
} else {
$protocol = NULL;
$status = NULL;
}
// Create a response
$response = $request->create_response();
$response_header = $response->headers();
// Process headers
array_map(array($response_header, 'parse_header_string'), array(), $meta_data['wrapper_data']);
$response->status($status)->protocol($protocol)->body(stream_get_contents($stream));
// Close the stream after use
fclose($stream);
return $response;
}
示例14: __construct
/**
* Constructor
*
* @param Request $request
* @param Response $response
*/
public function __construct(Request $request, Response $response)
{
// Ajax-like request setting if HMVC call or POST request with param `is_ajax` == `true`
if ($request->is_ajax() or $request !== Request::initial() or $request->method() === HTTP_Request::POST and $request->post('is_ajax') === 'true') {
$request->requested_with('xmlhttprequest');
}
parent::__construct($request, $response);
}
示例15: test_is_method_allowed
/**
* @dataProvider data_is_method_allowed
*/
public function test_is_method_allowed($route_method, $requested_method, $expected_result)
{
$this->markTestSkipped();
$route = Route::set('route_check', 'uri', NULL, array('method' => $route_method))->defaults(array('controller' => 'uri'));
$request = new Request('uri');
$request->method($requested_method);
$this->assertEquals($expected_result, $route->is_method_allowed($route, array(), $request));
}