为了账号安全,请及时绑定邮箱和手机立即绑定

Request.php-1

标签:
PHP

<?php

 

namespace Illuminate\Http;

 

use Closure;

use ArrayAccess;

use SplFileInfo;

use RuntimeException;

use Illuminate\Support\Arr;

use Illuminate\Support\Str;

use Illuminate\Support\Traits\Macroable;

use Illuminate\Contracts\Support\Arrayable;

use Symfony\Component\HttpFoundation\ParameterBag;

use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

// long namespace

class Request extends SymfonyRequest implements Arrayable, ArrayAccess

{// Request

    use Macroable;// use trait

 

    /**

     * The decoded JSON content for the request.

     *

     * @var string

     */

    protected $json;// The decoded JSON content for the request.

 

    /**

     * All of the converted files for the request.

     *

     * @var array

     */

    protected $convertedFiles;//converted file

 

    /**

     * The user resolver callback.

     *

     * @var \Closure

     */

    protected $userResolver;//The user resolver callback.

 

    /**

     * The route resolver callback.

     *

     * @var \Closure

     */

    protected $routeResolver;// The route resolver callback.

 

    /**

     * Create a new Illuminate HTTP request from server variables.

     *

     * @return static

     */

    public static function capture()

    {

        static::enableHttpMethodParameterOverride();// static::

 

        return static::createFromBase(SymfonyRequest::createFromGlobals());

    }// Create a new Illuminate HTTP request from server variables.

 

    /**

     * Return the Request instance.

     *

     * @return $this

     */

    public function instance()

    {

        return $this;

    }//Return the Request instance

 

    /**

     * Get the request method.

     *

     * @return string

     */

    public function method()

    {

        return $this->getMethod();

    }// get the request method.

 

    /**

     * Get the root URL for the application.

     *

     * @return string

     */

    public function root()

    {

        return rtrim($this->getSchemeAndHttpHost().$this->getBaseUrl(), '/');

    }// Get the root URL for the application.

 

    /**

     * Get the URL (no query string) for the request.

     *

     * @return string

     */

    public function url()

    {

        return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');

    }// Get the URL (no query string) for the request.

 

    /**

     * Get the full URL for the request.

     *

     * @return string

     */

    public function fullUrl()

    {

        $query = $this->getQueryString();// query ,get Query String

 

        $question = $this->getBaseUrl().$this->getPathInfo() == '/' ? '/?' : '?';// question

 

        return $query ? $this->url().$question.$query : $this->url();// query

    }// Get the full URL for the request.

 

    /**

     * Get the current path info for the request.

     *

     * @return string

     */

    public function path()

    {

        $pattern = trim($this->getPathInfo(), '/');

 

        return $pattern == '' ? '/' : $pattern;

    }//get Path

 

    /**

     * Get the current encoded path info for the request.

     *

     * @return string

     */

    public function decodedPath()

    {

        return rawurldecode($this->path());

    }//decode Path get the path

 

    /**

     * Get a segment from the URI (1 based index).

     *

     * @param  int  $index

     * @param  string|null  $default

     * @return string|null

     */

    public function segment($index, $default = null)

    {

        return Arr::get($this->segments(), $index - 1, $default);

    }//Get a segment from the URI (1 based index).

 

    /**

     * Get all of the segments for the request path.

     *

     * @return array

     */

    public function segments()

    {

        $segments = explode('/', $this->path());

 

        return array_values(array_filter($segments, function ($v) {

            return $v != '';

        }));// array_values.

    }// Get all of the segments for the request path

 

    /**

     * Determine if the current request URI matches a pattern.

     *

     * @param  mixed  string

     * @return bool

     */

    public function is()

    {

        foreach (func_get_args() as $pattern) {

            if (Str::is($pattern, urldecode($this->path()))) {

                return true;

            }

        }

 

        return false;

    }// check current request.


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

举报

0/150
提交
取消