ITPub博客

首页 > IT职业 > IT生活 > Request.php-2

Request.php-2

IT生活 作者:netroop 时间:2021-09-09 09:16:07 0 删除 编辑

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;

}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4741/viewspace-2801563/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-25

  • 博文量
    152
  • 访问量
    1068