芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/myvyralapp.com/bck/vendor/laravel/framework/src/Illuminate/Validation/Rules/File.php
$mimetypes * @return static */ public static function types($mimetypes) { return tap(new static(), fn ($file) => $file->allowedMimetypes = (array) $mimetypes); } /** * Indicate that the uploaded file should be exactly a certain size in kilobytes. * * @param int $kilobytes * @return $this */ public function size($kilobytes) { $this->minimumFileSize = $kilobytes; $this->maximumFileSize = $kilobytes; return $this; } /** * Indicate that the uploaded file should be between a minimum and maximum size in kilobytes. * * @param int $minKilobytes * @param int $maxKilobytes * @return $this */ public function between($minKilobytes, $maxKilobytes) { $this->minimumFileSize = $minKilobytes; $this->maximumFileSize = $maxKilobytes; return $this; } /** * Indicate that the uploaded file should be no less than the given number of kilobytes. * * @param int $kilobytes * @return $this */ public function min($kilobytes) { $this->minimumFileSize = $kilobytes; return $this; } /** * Indicate that the uploaded file should be no more than the given number of kilobytes. * * @param int $kilobytes * @return $this */ public function max($kilobytes) { $this->maximumFileSize = $kilobytes; return $this; } /** * Specify additional validation rules that should be merged with the default rules during validation. * * @param string|array $rules * @return $this */ public function rules($rules) { $this->customRules = array_merge($this->customRules, Arr::wrap($rules)); return $this; } /** * Determine if the validation rule passes. * * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { $this->messages = []; $validator = Validator::make( $this->data, [$attribute => $this->buildValidationRules()], $this->validator->customMessages, $this->validator->customAttributes ); if ($validator->fails()) { return $this->fail($validator->messages()->all()); } return true; } /** * Build the array of underlying validation rules based on the current state. * * @return array */ protected function buildValidationRules() { $rules = ['file']; $rules = array_merge($rules, $this->buildMimetypes()); $rules[] = match (true) { is_null($this->minimumFileSize) && is_null($this->maximumFileSize) => null, is_null($this->maximumFileSize) => "min:{$this->minimumFileSize}", is_null($this->minimumFileSize) => "max:{$this->maximumFileSize}", $this->minimumFileSize !== $this->maximumFileSize => "between:{$this->minimumFileSize},{$this->maximumFileSize}", default => "size:{$this->minimumFileSize}", }; return array_merge(array_filter($rules), $this->customRules); } /** * Separate the given mimetypes from extensions and return an array of correct rules to validate against. * * @return array */ protected function buildMimetypes() { if (count($this->allowedMimetypes) === 0) { return []; } $rules = []; $mimetypes = array_filter( $this->allowedMimetypes, fn ($type) => str_contains($type, '/') ); $mimes = array_diff($this->allowedMimetypes, $mimetypes); if (count($mimetypes) > 0) { $rules[] = 'mimetypes:'.implode(',', $mimetypes); } if (count($mimes) > 0) { $rules[] = 'mimes:'.implode(',', $mimes); } return $rules; } /** * Adds the given failures, and return false. * * @param array|string $messages * @return bool */ protected function fail($messages) { $messages = collect(Arr::wrap($messages))->map(function ($message) { return $this->validator->getTranslator()->get($message); })->all(); $this->messages = array_merge($this->messages, $messages); return false; } /** * Get the validation error message. * * @return array */ public function message() { return $this->messages; } /** * Set the current validator. * * @param \Illuminate\Contracts\Validation\Validator $validator * @return $this */ public function setValidator($validator) { $this->validator = $validator; return $this; } /** * Set the current data under validation. * * @param array $data * @return $this */ public function setData($data) { $this->data = $data; return $this; } }