Validator which checks if the file already exists in the directory

package Default
inherited_from \Zend\Validator\File\MimeType

 Methods

Sets validator options

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

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

Abstract constructor for all validators A validator should accept following parameters: - nothing f.e. Validator() - one or multiple scalar values f.e. Validator($first, $second, $third) - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third')) - an instance of Traversable f.e. Validator($config_instance)

__construct(array|\Traversable $options = null
Inherited

Parameters

$options

array\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

Parameters

$property

string

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixed

Invoke as command

__invoke(mixed $value) : boolean
Inherited

Parameters

$value

mixed

Returns

boolean

Adds the mimetypes

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

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($disable) : \Zend\Validator\File\MimeType
Inherited

Parameters

$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(boolean $headerCheck = true) : \Zend\Validator\File\MimeType
Inherited

Parameters

$headerCheck

boolean

Returns

\Zend\Validator\File\MimeTypeProvides fluid interface

Get default translation object for all validate objects

getDefaultTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
InheritedStatic

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Get default translation text domain for all validate objects

getDefaultTranslatorTextDomain() : string
InheritedStatic

Returns

string

Returns the Header Check option

getHeaderCheck() : boolean
Inherited

Returns

boolean

Returns the actual set magicfile

getMagicFile() : string
Inherited

Returns

string

Returns the maximum allowed message length

getMessageLength() : integer
InheritedStatic

Returns

integer

Returns the message templates from the validator

getMessageTemplates() : array
Inherited

Returns

array

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

getMessageVariables() : array
Inherited

Returns

array

Returns array of validation failure messages

getMessages() : array
Inherited

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\ValidatorInterface::getMessages()

Returns

array

Returns the set mimetypes

getMimeType(boolean $asArray = false) : string | array
Inherited

Parameters

$asArray

boolean

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

Returns

stringarray

Returns an option

getOption(string $option) : mixed
Inherited

Parameters

$option

string

Option to be returned

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixedReturned option

Returns all available options

getOptions() : array
Inherited

Returns

arrayArray with all available options

Return translation object

getTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslator()

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Return the translation text domain

getTranslatorTextDomain() : string
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslatorTextDomain()

Returns

string

Is there a default translation object set?

hasDefaultTranslator() : boolean
InheritedStatic

Returns

boolean

Does this validator have its own specific translator?

hasTranslator() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::hasTranslator()

Returns

boolean

Is usage of MagicFile disabled?

isMagicFileDisabled() : boolean
Inherited

Returns

boolean

Is translation enabled?

isTranslatorEnabled() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::isTranslatorEnabled()

Returns

boolean

Defined by Zend\Validator\ValidatorInterface

isValid(string|array $value, array $file = null) : boolean
Inherited

Returns true if the mimetype of the file matches the given ones. Also parts of mimetypes can be checked. If you give for example "image" all image mime types will be accepted like "image/gif", "image/jpeg" and so on.

Parameters

$value

stringarray

Real file to check for mimetype

$file

array

File data from \Zend\File\Transfer\Transfer (optional)

Returns

boolean

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

isValueObscured() : boolean
Inherited

Returns

boolean

Set default translation object for all validate objects

setDefaultTranslator(\Zend\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : void
InheritedStatic

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Set default translation text domain for all validate objects

setDefaultTranslatorTextDomain(string $textDomain = 'default') : void
InheritedStatic

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

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 = null) : \Zend\Validator\AbstractValidator
Inherited

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 = -1
InheritedStatic

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

Parameters

$messages

array

Returns

\Zend\Validator\AbstractValidator

Sets the mimetypes

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

Parameters

$mimetype

stringarray

The mimetypes to validate

Returns

\Zend\Validator\File\MimeTypeProvides a fluent interface

Sets one or multiple options

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

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\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslator()

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidator

Indicate whether or not translation should be enabled

setTranslatorEnabled(boolean $flag = true) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorEnabled()

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

Set translation text domain

setTranslatorTextDomain(string $textDomain = 'default') : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorTextDomain()

Parameters

$textDomain

string

Returns

\Zend\Validator\AbstractValidator

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

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

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

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.

Parameters

$messageKey

string

$value

stringarrayobject

Returns

string

error()

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

Parameters

$messageKey

string

$value

string

OPTIONAL

Returns the validation value

getValue() : mixed
Inherited

Returns

mixedValue to be validated

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

setValue(mixed $value) : void
Inherited

Parameters

$value

mixed

Translate a validation message

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

Parameters

$messageKey

string

$message

string

Returns

string

 Properties

 

$abstractOptions

$abstractOptions 

Default

array('messages' => array(), 'messageTemplates' => array(), 'messageVariables' => array(), 'translator' => null, 'translatorTextDomain' => null, 'translatorEnabled' => true, 'valueObscured' => false)
 

Default translation object for all validate objects

$defaultTranslator : \Zend\Validator\Translator\TranslatorInterface

Default

Static
 

Default text domain to be used with translator

$defaultTranslatorTextDomain : string

Default

'default'
Static
 

Finfo object to use

$finfo : resource

Default

 

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

$magicFiles : array

Default

array('/usr/share/misc/magic', '/usr/share/misc/magic.mime', '/usr/share/misc/magic.mgc', '/usr/share/mime/magic', '/usr/share/mime/magic.mime', '/usr/share/mime/magic.mgc', '/usr/share/file/magic', '/usr/share/file/magic.mime', '/usr/share/file/magic.mgc')
 

Limits the maximum returned length of an error message

$messageLength : integer

Default

-1
Static
 

Error message templates

$messageTemplates : array

Default

array(self::FALSE_TYPE => "File is not compressed, '%type%' detected", self::NOT_DETECTED => "The mimetype could not be detected from the file", self::NOT_READABLE => "File is not readable or does not exist")
inherited_from \Zend\Validator\File\MimeType::messageTemplates
 

Error message templates

$messageTemplates : array

Default

array(self::FALSE_TYPE => "File has an incorrect mimetype of '%type%'", self::NOT_DETECTED => "The mimetype could not be detected from the file", self::NOT_READABLE => "File is not readable or does not exist")
 

$messageVariables

$messageVariables : array

Default

array('type' => 'type')
 

Options for this validator

$options : array

Default

array('enableHeaderCheck' => false, 'disableMagicFile' => false, 'magicFile' => null, 'mimeType' => null)
 

$type

$type : string

Default

 

The value to be validated

$value : mixed

Default

 Constants

 

FALSE_TYPE

FALSE_TYPE = 'fileIsCompressedFalseType' 
const string Error constants
inherited_from \Zend\Validator\File\MimeType::FALSE_TYPE
 

FALSE_TYPE

FALSE_TYPE = 'fileMimeTypeFalse' 
 

NOT_DETECTED

NOT_DETECTED = 'fileIsCompressedNotDetected' 
inherited_from \Zend\Validator\File\MimeType::NOT_DETECTED
 

NOT_DETECTED

NOT_DETECTED = 'fileMimeTypeNotDetected' 
 

NOT_READABLE

NOT_READABLE = 'fileIsCompressedNotReadable' 
inherited_from \Zend\Validator\File\MimeType::NOT_READABLE
 

NOT_READABLE

NOT_READABLE = 'fileMimeTypeNotReadable'