Validator for the mime type of a file

category Zend
package Zend_Validator

 Methods

Sets validator options

__construct(string | array | \Traversable $options) 
Inherited

Mimetype to accept - NULL means default PHP usage by using the environment variable 'magic' - FALSE means disabling searching for mimetype, should be used for PHP 5.3 - A string is the mimetype file to use

inherited_from \Zend\Validator\File\MimeType::__construct()

Parameters

$options

stringarray\Traversable

Magic function returns the value of the requested property, if and only if it is the value or a message variable.

__get(string $property) : mixed
Inherited

inherited_from \Zend\Validator\AbstractValidator::__get()
inherited_from \Zend\Validator\File\MimeType::__get()

Parameters

$property

string

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixed

Invoke as command

__invoke(mixed $value) : bool
Inherited

inherited_from \Zend\Validator\AbstractValidator::__invoke()
inherited_from \Zend\Validator\File\MimeType::__invoke()

Parameters

$value

mixed

Returns

bool

Adds the mimetypes

addMimeType(string | array $mimetype) : \Zend\Validator\File\MimeType
Inherited

inherited_from \Zend\Validator\File\MimeType::addMimeType()

Parameters

$mimetype

stringarray

The mimetypes to add for validation

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\File\MimeTypeProvides a fluent interface

Disables usage of MagicFile

disableMagicFile(\Zend\Validator\File\$disable $disable) : \Zend\Validator\File\MimeType
Inherited

inherited_from \Zend\Validator\File\MimeType::disableMagicFile()

Parameters

$disable

\Zend\Validator\File\$disable

boolean False disables usage of magic file

Returns

\Zend\Validator\File\MimeTypeProvides fluid interface

Defines if the http header should be used Note that this is unsafe and therefor the default value is false

enableHeaderCheck(bool $headerCheck) : \Zend\Validator\File\MimeType
Inherited

inherited_from \Zend\Validator\File\MimeType::enableHeaderCheck()

Parameters

$headerCheck

bool

Returns

\Zend\Validator\File\MimeTypeProvides fluid interface

Get default translation object for all validate objects

getDefaultTranslator() : \Zend\I18n\Translator\Translator | null
Inherited

inherited_from \Zend\Validator\AbstractValidator::getDefaultTranslator()
inherited_from \Zend\Validator\File\MimeType::getDefaultTranslator()

Returns

Get default translation text domain for all validate objects

getDefaultTranslatorTextDomain() : string
Inherited

inherited_from \Zend\Validator\AbstractValidator::getDefaultTranslatorTextDomain()
inherited_from \Zend\Validator\File\MimeType::getDefaultTranslatorTextDomain()

Returns

string

Returns the Header Check option

getHeaderCheck() : bool
Inherited

inherited_from \Zend\Validator\File\MimeType::getHeaderCheck()

Returns

bool

Returns the actual set magicfile

getMagicFile() : string
Inherited

inherited_from \Zend\Validator\File\MimeType::getMagicFile()

Returns

string

Returns the maximum allowed message length

getMessageLength() : integer
Inherited

inherited_from \Zend\Validator\AbstractValidator::getMessageLength()
inherited_from \Zend\Validator\File\MimeType::getMessageLength()

Returns

integer

Returns the message templates from the validator

getMessageTemplates() : array
Inherited

inherited_from \Zend\Validator\AbstractValidator::getMessageTemplates()
inherited_from \Zend\Validator\File\MimeType::getMessageTemplates()

Returns

array

Returns an array of the names of variables that are used in constructing validation failure messages

getMessageVariables() : array
Inherited

inherited_from \Zend\Validator\AbstractValidator::getMessageVariables()
inherited_from \Zend\Validator\File\MimeType::getMessageVariables()

Returns

array

Returns array of validation failure messages

getMessages() : array
Inherited

The array keys are validation failure message identifiers, and the array values are the corresponding human-readable message strings.

If isValid() was never called or if the most recent isValid() call returned true, then this method returns an empty array.

inherited_from \Zend\Validator\AbstractValidator::getMessages()
inherited_from \Zend\Validator\File\MimeType::getMessages()

Returns

array

Returns the set mimetypes

getMimeType(bool $asArray) : string | array
Inherited

inherited_from \Zend\Validator\File\MimeType::getMimeType()

Parameters

$asArray

bool

Returns the values as array, when false a concatenated string is returned

Returns

stringarray

Returns an option

getOption(string $option) : mixed
Inherited

inherited_from \Zend\Validator\AbstractValidator::getOption()
inherited_from \Zend\Validator\File\MimeType::getOption()

Parameters

$option

string

Option to be returned

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixedReturned option

Returns all available options

getOptions() : array
Inherited

inherited_from \Zend\Validator\AbstractValidator::getOptions()
inherited_from \Zend\Validator\File\MimeType::getOptions()

Returns

arrayArray with all available options

Return translation object

getTranslator() : \Zend\I18n\Translator\Translator | null
Inherited

inherited_from \Zend\Validator\AbstractValidator::getTranslator()
inherited_from \Zend\Validator\File\MimeType::getTranslator()

Returns

Return the translation text domain

getTranslatorTextDomain() : string
Inherited

inherited_from \Zend\Validator\AbstractValidator::getTranslatorTextDomain()
inherited_from \Zend\Validator\File\MimeType::getTranslatorTextDomain()

Returns

string

Is there a default translation object set?

hasDefaultTranslator() : bool
Inherited

inherited_from \Zend\Validator\AbstractValidator::hasDefaultTranslator()
inherited_from \Zend\Validator\File\MimeType::hasDefaultTranslator()

Returns

bool

Does this validator have its own specific translator?

hasTranslator() : bool
Inherited

inherited_from \Zend\Validator\AbstractValidator::hasTranslator()
inherited_from \Zend\Validator\File\MimeType::hasTranslator()

Returns

bool

Is usage of MagicFile disabled?

isMagicFileDisabled() : bool
Inherited

inherited_from \Zend\Validator\File\MimeType::isMagicFileDisabled()

Returns

bool

Is translation enabled?

isTranslatorEnabled() : bool
Inherited

inherited_from \Zend\Validator\AbstractValidator::isTranslatorEnabled()
inherited_from \Zend\Validator\File\MimeType::isTranslatorEnabled()

Returns

bool

Returns true if the mimetype of the file does not matche the given ones.

isValid(string $value, array $file) : bool

Also parts of mimetypes can be checked. If you give for example "image" all image mime types will not be accepted like "image/gif", "image/jpeg" and so on.

Parameters

$value

string

Real file to check for mimetype

$file

array

File data from \Zend\File\Transfer\Transfer

Exceptions

\Zend\Validator\Exception\RuntimeException If validation of $value is impossible

Returns

bool

Retrieve flag indicating whether or not value should be obfuscated in messages

isValueObscured() : bool
Inherited

inherited_from \Zend\Validator\AbstractValidator::isValueObscured()
inherited_from \Zend\Validator\File\MimeType::isValueObscured()

Returns

bool

Set default translation object for all validate objects

setDefaultTranslator(\Zend\I18n\Translator\Translator $translator, string $textDomain) : void
Inherited

inherited_from \Zend\Validator\AbstractValidator::setDefaultTranslator()
inherited_from \Zend\Validator\File\MimeType::setDefaultTranslator()

Parameters

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Set default translation text domain for all validate objects

setDefaultTranslatorTextDomain(string $textDomain) : void
Inherited

inherited_from \Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain()
inherited_from \Zend\Validator\File\MimeType::setDefaultTranslatorTextDomain()

Parameters

$textDomain

string

Sets the magicfile to use if null, the MAGIC constant from php is used if the MAGIC file is erroneous, no file will be set if false, the default MAGIC file from PHP will be used

setMagicFile(string $file) : \Zend\Validator\File\MimeType
Inherited

inherited_from \Zend\Validator\File\MimeType::setMagicFile()

Parameters

$file

string

Exceptions

\Zend\Validator\Exception\RuntimeException When finfo can not read the magicfile
\Zend\Validator\Exception\InvalidArgumentException
\Zend\Validator\Exception\InvalidMagicMimeFileException

Returns

\Zend\Validator\File\MimeTypeProvides fluid interface

Sets the validation failure message template for a particular key

setMessage(string $messageString, string $messageKey) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setMessage()
inherited_from \Zend\Validator\File\MimeType::setMessage()

Parameters

$messageString

string

$messageKey

string

OPTIONAL

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidatorProvides a fluent interface

Sets the maximum allowed message length

setMessageLength(integer $length) 
Inherited

inherited_from \Zend\Validator\AbstractValidator::setMessageLength()
inherited_from \Zend\Validator\File\MimeType::setMessageLength()

Parameters

$length

integer

Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.

setMessages(array $messages) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setMessages()
inherited_from \Zend\Validator\File\MimeType::setMessages()

Parameters

$messages

array

Returns

Sets the mimetypes

setMimeType(string | array $mimetype) : \Zend\Validator\File\MimeType
Inherited

inherited_from \Zend\Validator\File\MimeType::setMimeType()

Parameters

$mimetype

stringarray

The mimetypes to validate

Returns

\Zend\Validator\File\MimeTypeProvides a fluent interface

Sets one or multiple options

setOptions(array | \Traversable $options) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setOptions()
inherited_from \Zend\Validator\File\MimeType::setOptions()

Parameters

$options

array\Traversable

Options to set

Exceptions

\Zend\Validator\Exception\InvalidArgumentException If $options is not an array or Traversable

Returns

\Zend\Validator\AbstractValidatorProvides fluid interface

Set translation object

setTranslator(\Zend\I18n\Translator\Translator $translator, string $textDomain) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setTranslator()
inherited_from \Zend\Validator\File\MimeType::setTranslator()

Parameters

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

Indicate whether or not translation should be enabled

setTranslatorEnabled(bool $flag) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setTranslatorEnabled()
inherited_from \Zend\Validator\File\MimeType::setTranslatorEnabled()

Parameters

$flag

bool

Returns

Set translation text domain

setTranslatorTextDomain(string $textDomain) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setTranslatorTextDomain()
inherited_from \Zend\Validator\File\MimeType::setTranslatorTextDomain()

Parameters

$textDomain

string

Returns

Set flag indicating whether or not value should be obfuscated in messages

setValueObscured(bool $flag) : \Zend\Validator\AbstractValidator
Inherited

inherited_from \Zend\Validator\AbstractValidator::setValueObscured()
inherited_from \Zend\Validator\File\MimeType::setValueObscured()

Parameters

$flag

bool

Returns

Throws an error of the given type

createError(string $file, string $errorType) : false
Inherited

inherited_from \Zend\Validator\File\MimeType::createError()

Parameters

$file

string

$errorType

string

Returns

false

Constructs and returns a validation failure message with the given message key and value.

createMessage(string $messageKey, string | array | object $value) : string
Inherited

Returns null if and only if $messageKey does not correspond to an existing template.

If a translator is available and a translation exists for $messageKey, the translation will be used.

inherited_from \Zend\Validator\AbstractValidator::createMessage()
inherited_from \Zend\Validator\File\MimeType::createMessage()

Parameters

$messageKey

string

$value

stringarrayobject

Returns

string

error()

error(string $messageKey, string $value) : void
Inherited

inherited_from \Zend\Validator\AbstractValidator::error()
inherited_from \Zend\Validator\File\MimeType::error()

Parameters

$messageKey

string

$value

string

OPTIONAL

Returns the validation value

getValue() : mixed
Inherited

inherited_from \Zend\Validator\AbstractValidator::getValue()
inherited_from \Zend\Validator\File\MimeType::getValue()

Returns

mixedValue to be validated

Sets the value to be validated and clears the messages and errors arrays

setValue(mixed $value) : void
Inherited

inherited_from \Zend\Validator\AbstractValidator::setValue()
inherited_from \Zend\Validator\File\MimeType::setValue()

Parameters

$value

mixed

Translate a validation message

translateMessage(string $messageKey, string $message) : string
Inherited

inherited_from \Zend\Validator\AbstractValidator::translateMessage()
inherited_from \Zend\Validator\File\MimeType::translateMessage()

Parameters

$messageKey

string

$message

string

Returns

string

 Properties

 

$abstractOptions

$abstractOptions 
Inherited

inherited_from \Zend\Validator\AbstractValidator::$$abstractOptions
inherited_from \Zend\Validator\File\MimeType::$$abstractOptions
 

Default translation object for all validate objects

$defaultTranslator : \Zend\I18n\Translator\Translator
Inherited

inherited_from \Zend\Validator\AbstractValidator::$$defaultTranslator
inherited_from \Zend\Validator\File\MimeType::$$defaultTranslator
 

Default text domain to be used with translator

$defaultTranslatorTextDomain : string
Inherited

inherited_from \Zend\Validator\AbstractValidator::$$defaultTranslatorTextDomain
inherited_from \Zend\Validator\File\MimeType::$$defaultTranslatorTextDomain
 

Finfo object to use

$finfo : resource
Inherited

inherited_from \Zend\Validator\File\MimeType::$$finfo
 

If no environment variable 'MAGIC' is set, try and autodiscover it based on common locations

$magicFiles : array
Inherited

inherited_from \Zend\Validator\File\MimeType::$$magicFiles
 

Limits the maximum returned length of a error message

$messageLength : Integer
Inherited

inherited_from \Zend\Validator\AbstractValidator::$$messageLength
inherited_from \Zend\Validator\File\MimeType::$$messageLength
 

<p>Error message templates</p>

$messageTemplates : array
Inherited

inherited_from \Zend\Validator\File\MimeType::$$messageTemplates
 

$messageVariables

$messageVariables : array
Inherited

inherited_from \Zend\Validator\File\MimeType::$$messageVariables
 

Options for this validator

$options : array
Inherited

inherited_from \Zend\Validator\File\MimeType::$$options
 

$type

$type : string
Inherited

inherited_from \Zend\Validator\File\MimeType::$$type
 

The value to be validated

$value : mixed
Inherited

inherited_from \Zend\Validator\AbstractValidator::$$value
inherited_from \Zend\Validator\File\MimeType::$$value

 Constants

 

FALSE_TYPE

FALSE_TYPE 

 

NOT_DETECTED

NOT_DETECTED 

 

NOT_READABLE

NOT_READABLE