[李景山php]每天laravel-20161021|Request.php-2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[李景山php]每天laravel-20161021|Request.php-2相关的知识,希望对你有一定的参考价值。
/** * 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; }
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1842714
以上是关于[李景山php]每天laravel-20161021|Request.php-2的主要内容,如果未能解决你的问题,请参考以下文章
[李景山php]每天laravel-20161028|Translator.php
[李景山php]每天laravel-20161107|PhpEngine.php
[李景山php]每天laravel-20161106|EngineResolver.php
[李景山php]每天laravel-20161108|ShareErrorsFromSession.php