栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

Request.php-2

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Request.php-2

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.

 

public function ajax()

{

    return $this->isXmlHttpRequest();

}//Determine if the request is the result of an AJAX call.

 

public function pjax()

{

    return $this->headers->get('X-PJAX') == true;

}//Determine if the request is the result of an PJAX call.

 

public function secure()

{

    return $this->isSecure();

}//Determine if the request is over HTTPS.

 

public function ip()

{

    return $this->getClientIp();

}// Returns the client IP address.

 

public function ips()

{

    return $this->getClientIps();

}//Returns the client IP address.

 

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;

}

 

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;

}

 

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"

 

public function all()

{

    return array_replace_recursive($this->input(), $this->allFiles());

}// Get all of the input and files for the request.

 

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.

 

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;

}

 

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.

 

public function query($key = null, $default = null)

{

    return $this->retrieveItem('query', $key, $default);

}// Retrieve a query string item from the request.

 

public function hascookie($key)

{

    return ! is_null($this->cookie($key));// is_null

}//Determine if a cookie is set on the request.

 

public function cookie($key = null, $default = null)

{

    return $this->retrieveItem('cookies', $key, $default);

}//Retrieve a cookie from the request.

 

public function allFiles()

{

    $files = $this->files->all();

 

    return $this->convertedFiles

                ? $this->convertedFiles

                : $this->convertedFiles = $this->convertUploadedFiles($files);

}//get allFiles

 

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

}

 

public function file($key = null, $default = null)

{

    return data_get($this->allFiles(), $key, $default);

}//Retrieve a file from the request.

 

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;

}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229508.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号