Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • All
  • AllOf
  • Alnum
  • Alpha
  • BaseValidator
  • Between
  • Blank
  • Callback
  • CharLength
  • Chinese
  • Color
  • Contains
  • CreditCard
  • Date
  • DateTime
  • Decimal
  • Digit
  • Dir
  • DivisibleBy
  • DoubleByte
  • Email
  • EndsWith
  • EqualTo
  • Exists
  • FieldExists
  • File
  • GreaterThan
  • GreaterThanOrEqual
  • IdCardCn
  • IdCardHk
  • IdCardMo
  • IdCardTw
  • IdenticalTo
  • Image
  • In
  • Ip
  • Length
  • LessThan
  • LessThanOrEqual
  • Lowercase
  • Luhn
  • MaxLength
  • MinLength
  • MobileCn
  • NaturalNumber
  • NoneOf
  • Null
  • Number
  • OneOf
  • Password
  • Phone
  • PhoneCn
  • PlateNumberCn
  • PositiveInteger
  • PostcodeCn
  • Present
  • QQ
  • RecordExists
  • Regex
  • Required
  • SomeOf
  • StartsWith
  • Time
  • Tld
  • Type
  • Uppercase
  • Url
  • Uuid
  • Overview
  • Namespace
  • Class

Class File

Check if the input is valid file

Wei\Base
Extended by Wei\Validator\BaseValidator
Extended by Wei\Validator\File

Direct known subclasses

Wei\Validator\Image

Indirect known subclasses

Wei\Upload
Namespace: Wei\Validator
Author: Twin Huang twinhuang@qq.com
Located at Validator/File.php
Methods summary
public boolean
# __invoke( mixed $input, $options = array() )

Validate the input value

Validate the input value

Parameters

$input
$options

Returns

boolean

Overrides

Wei\Validator\BaseValidator::__invoke()
protected boolean
# doValidate( mixed $input )

Validate the input value (ignore the $negative property)

Validate the input value (ignore the $negative property)

Parameters

$input
The input to be validated

Returns

boolean
public boolean
# inMimeType( string $findMe, array $mimeTypes )

Checks if a mime type exists in a mime type array

Checks if a mime type exists in a mime type array

Parameters

$findMe
The mime type to be searched
$mimeTypes

The mime type array, allow element likes "image/*" to match all image mime type, such as "image/gif", "image/jpeg", etc

Returns

boolean
public Wei\Validator\File
# setExts( string|array $exts )

Set allowed file extensions

Set allowed file extensions

Parameters

$exts
String format likes 'php,js' or array format likes [php, js]

Returns

Wei\Validator\File
public Wei\Validator\File
# setExcludeExts( string|array $exts )

Set exclude file extensions

Set exclude file extensions

Parameters

$exts
String format likes 'php,js' or array format likes [php, js]

Returns

Wei\Validator\File
protected Wei\Validator\File
# setMaxSize( string|integer $maxSize )

Set maximum file size

Set maximum file size

Parameters

$maxSize

Returns

Wei\Validator\File
protected Wei\Validator\File
# setMinSize( string|integer $minSize )

Set the minimum file size

Set the minimum file size

Parameters

$minSize

Returns

Wei\Validator\File
public integer
# toBytes( string|integer $size )

Converts human readable file size (e.g. 1.2MB, 10KB) into bytes

Converts human readable file size (e.g. 1.2MB, 10KB) into bytes

Parameters

$size

Returns

integer
public string
# fromBytes( integer $bytes )

Formats bytes to human readable file size (e.g. 1.2MB, 10KB)

Formats bytes to human readable file size (e.g. 1.2MB, 10KB)

Parameters

$bytes

Returns

string
public Wei\Validator\File
# setMimeTypes( string|array $mimeTypes )

Set the file mime types

Set the file mime types

Parameters

$mimeTypes

Returns

Wei\Validator\File
public Wei\Validator\File
# setExcludeMimeTypes( string|array $excludeMimeTypes )

Set the file exclude mime types

Set the file exclude mime types

Parameters

$excludeMimeTypes

Returns

Wei\Validator\File
protected array
# convertToArray( mixed $var )

Converts parameter to array

Converts parameter to array

Parameters

$var

Returns

array

Throws

InvalidArgumentException
When parameter is not a string or array
public string|false
# getMimeType( )

Returns the file mime type on success

Returns the file mime type on success

Returns

string|false

Throws

UnexpectedValueException
When failed to open fileinfo database
public string
# getExt( )

Returns the file extension, if file is not exists, return null instead

Returns the file extension, if file is not exists, return null instead

Returns

string
Methods inherited from Wei\Validator\BaseValidator
addError(), getErrors(), getFirstMessage(), getJoinedMessage(), getMessages(), getName(), hasError(), isString(), isValid(), loadTranslationMessages(), setMessages(), setName(), storeOption()
Methods inherited from Wei\Base
__call(), __construct(), __get(), getOption(), setOption()
Magic methods inherited from Wei\Validator\BaseValidator
t()
Properties summary
protected string $notFoundMessage
# '%name% is not found or not readable'
protected string $maxSizeMessage
# '%name% is too large(%sizeString%), allowed maximum size is %maxSizeString%'
protected string $minSizeMessage
# '%name% is too small(%sizeString%), expected minimum size is %minSizeString%'
protected string $extsMessage
# '%name% extension(%ext%) is not allowed, allowed extension: %exts%'
protected string $excludeExtsMessage
# '%name% extension(%ext%) is not allowed, not allowed extension: %excludeExts%'
protected string $mimeTypeNotDetectedMessage
# '%name% mime type could not be detected'
protected string $mimeTypesMessage
# '%name% mime type "%mimeType%" is not allowed'
protected string $excludeMimeTypesMessage
# '%name% mime type "%mimeType%" is not allowed'
protected string $negativeMessage

The common message for negative validator

The common message for negative validator

# '%name% must be a non-existing file'
protected string|false $file

The absolute file path, or false when file not found or not readable

The absolute file path, or false when file not found or not readable

#
protected string $originFile

The origin name of uploaded file, if the input is not uploaded file array, the origin name is equals to $this->file

The origin name of uploaded file, if the input is not uploaded file array, the origin name is equals to $this->file

#
protected integer $size

The detected byte size of file

The detected byte size of file

#
protected string $sizeString

The formatted file size, e.g. 1.2MB, 10KB

The formatted file size, e.g. 1.2MB, 10KB

#
protected integer $maxSize

The maximum file size limit

The maximum file size limit

# 0
protected string $maxSizeString

The formatted maximum file size, e.g. 1.2MB, 10KB

The formatted maximum file size, e.g. 1.2MB, 10KB

#
protected integer $minSize

The minimum file size limit

The minimum file size limit

# 0
protected string $minSizeString

The formatted minimum file size, e.g. 1.2MB, 10KB

The formatted minimum file size, e.g. 1.2MB, 10KB

#
protected string $ext

The detected file extension

The detected file extension

#
protected array $exts

The allowed file extensions

The allowed file extensions

# array()
protected array $excludeExts

The excluding file extensions

The excluding file extensions

# array()
protected string $mimeType

The detected file mime type

The detected file mime type

#
protected array $mimeTypes

The allowed file mime types

The allowed file mime types

# array()
protected array $excludeMimeTypes

The excluding file mime types

The excluding file mime types

# array()
protected string $units

The file size unit

The file size unit

# array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
protected string|null $magicFile

The magic database file to detect file mime type

The magic database file to detect file mime type

Link

http://www.php.net/manual/en/function.finfo-open.php
#
Properties inherited from Wei\Validator\BaseValidator
$errors, $name, $negative, $notStringMessage, $validator
Properties inherited from Wei\Base
$providers, $wei
Magic properties inherited from Wei\Validator\BaseValidator
$t
Wei Framework API documentation generated by ApiGen