[李景山php]每天laravel-20161021|Request.php-2

来源:互联网 发布:整形医院网络咨询收入 编辑:程序博客网 时间:2024/05/21 07:11
    /**     * Determine if the current request URL and query string matches a pattern.     *     * @param  mixed  string     * @return bool     */    public function fullUrlIs()    {// check string like URL        $url = $this->fullUrl();        foreach (func_get_args() as $pattern) {            if (Str::is($pattern, $url)) {                return true;            }        }// foreach like loop it        return false;    }//Determine if the current request URL and query string matches a pattern.    /**     * Determine if the request is the result of an AJAX call.     *     * @return bool     */    public function ajax()    {        return $this->isXmlHttpRequest();    }//Determine if the request is the result of an AJAX call.    /**     * Determine if the request is the result of an PJAX call.     *     * @return bool     */    public function pjax()    {        return $this->headers->get('X-PJAX') == true;    }//Determine if the request is the result of an PJAX call.    /**     * Determine if the request is over HTTPS.     *     * @return bool     */    public function secure()    {        return $this->isSecure();    }//Determine if the request is over HTTPS.    /**     * Returns the client IP address.     *     * @return string     */    public function ip()    {        return $this->getClientIp();    }// Returns the client IP address.    /**     * Returns the client IP addresses.     *     * @return array     */    public function ips()    {        return $this->getClientIps();    }//Returns the client IP address.    /**     * Determine if the request contains a given input item key.     *     * @param  string|array  $key     * @return bool     */    public function exists($key)    {//Determine if the request contains a given input item key.        $keys = is_array($key) ? $key : func_get_args();// $key get the key        $input = $this->all();// get all input request        foreach ($keys as $value) {            if (! array_key_exists($value, $input)) {                return false;            }        }        return true;    }    /**     * Determine if the request contains a non-empty value for an input item.     *     * @param  string|array  $key     * @return bool     */    public function has($key)    {// Determine if the request contains a non-empty value for an input item.        $keys = is_array($key) ? $key : func_get_args();        foreach ($keys as $value) {            if ($this->isEmptyString($value)) {                return false;            }        }        return true;    }    /**     * Determine if the given input key is an empty string for "has".     *     * @param  string  $key     * @return bool     */    protected function isEmptyString($key)    {        $value = $this->input($key);        $boolOrArray = is_bool($value) || is_array($value);        return ! $boolOrArray && trim((string) $value) === '';    }//Determine if the given input key is an empty string for "has"    /**     * Get all of the input and files for the request.     *     * @return array     */    public function all()    {        return array_replace_recursive($this->input(), $this->allFiles());    }// Get all of the input and files for the request.    /**     * Retrieve an input item from the request.     *     * @param  string  $key     * @param  string|array|null  $default     * @return string|array     */    public function input($key = null, $default = null)    {        $input = $this->getInputSource()->all() + $this->query->all();        return data_get($input, $key, $default);    }//Retrieve an input item from the request.    /**     * Get a subset of the items from the input data.     *     * @param  array|mixed  $keys     * @return array     */    public function only($keys)    {//Get a subset of the items from the input data.        $keys = is_array($keys) ? $keys : func_get_args();// keys        $results = [];// get result        $input = $this->all();// get the input        foreach ($keys as $key) {// loop keys            Arr::set($results, $key, data_get($input, $key));        }        return $results;    }    /**     * Get all of the input except for a specified array of items.     *     * @param  array|mixed  $keys     * @return array     */    public function except($keys)    {        $keys = is_array($keys) ? $keys : func_get_args();        $results = $this->all();        Arr::forget($results, $keys);        return $results;    }//Get all of the input except for a specified array of items.    /**     * Retrieve a query string item from the request.     *     * @param  string  $key     * @param  string|array|null  $default     * @return string|array     */    public function query($key = null, $default = null)    {        return $this->retrieveItem('query', $key, $default);    }// Retrieve a query string item from the request.    /**     * Determine if a cookie is set on the request.     *     * @param  string  $key     * @return bool     */    public function hasCookie($key)    {        return ! is_null($this->cookie($key));// is_null    }//Determine if a cookie is set on the request.    /**     * Retrieve a cookie from the request.     *     * @param  string  $key     * @param  string|array|null  $default     * @return string|array     */    public function cookie($key = null, $default = null)    {        return $this->retrieveItem('cookies', $key, $default);    }//Retrieve a cookie from the request.    /**     * Get an array of all of the files on the request.     *     * @return array     */    public function allFiles()    {        $files = $this->files->all();        return $this->convertedFiles                    ? $this->convertedFiles                    : $this->convertedFiles = $this->convertUploadedFiles($files);    }//get allFiles    /**     * Convert the given array of Symfony UploadedFiles to custom Laravel UploadedFiles.     *     * @param  array  $files     * @return array     */    protected function convertUploadedFiles(array $files)    {//convert the given array of Smfony UploadedFiles to custom laravel UploadedFiles.        return array_map(function ($file) {            if (is_null($file) || (is_array($file) && empty(array_filter($file)))) {                return $file;            }            return is_array($file)                        ? $this->convertUploadedFiles($file)                        : UploadedFile::createFromBase($file);        }, $files);//return array_map    }    /**     * Retrieve a file from the request.     *     * @param  string  $key     * @param  mixed  $default     * @return \Symfony\Component\HttpFoundation\File\UploadedFile|array|null     */    public function file($key = null, $default = null)    {        return data_get($this->allFiles(), $key, $default);    }//Retrieve a file from the request.    /**     * Determine if the uploaded data contains a file.     *     * @param  string  $key     * @return bool     */    public function hasFile($key)    {//Determine if the uploaded data contains a file.        if (! is_array($files = $this->file($key))) {            $files = [$files];        }        foreach ($files as $file) {            if ($this->isValidFile($file)) {                return true;            }        }        return false;    }
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 喜用神为土应该怎么办 喜用神互相克害怎么办? 姓名总格不好怎么办 姓名学里人格不好怎么办 买家订单下不了怎么办 公积金不够月供怎么办 房贷担保费没交怎么办 营业执照过期1年怎么办 营业执照和公章丢失怎么办 个体户怎么办对公账户 公章法人章丢失怎么办 广州买房没有社保怎么办 辞职后计生关系怎么办 广州换工作社保怎么办 学校更名了盖章怎么办 工商注册资金没有交怎么办 住公司宿舍怎么办居住证 住在公司宿舍怎么办居住证 滴滴没有的车型怎么办 假的租房合同怎么办 代注册公司被骗怎么办 公司跨区迁址怎么办 公司搬走注册地怎么办 注册公司没有房产证怎么办 公司不运营了怎么办 公司注销了账户怎么办 租户不变更地址怎么办 营业执照忘审了怎么办 工商营业执照年检过期怎么办 个体营业执照没有年报怎么办? 个体工商户一年没有申报怎么办 个体工商户逾期未申报怎么办 个体户没报税过怎么办 农业银行证书过期了怎么办 ca证书丢了怎么办 ca证书被锁怎么办 上个月忘记清卡怎么办 财务人员进入税务黑名单怎么办 社保本丢了怎么办 贷款车辆登记证书怎么办 发票薄丢了怎么办?