Validate/File/MimeType.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Validate
- Version
- $Id: MimeType.php 25175 2012-12-22 20:47:08Z rob $
\Zend_Validate_File_MimeType
Validator for the mime type of a file
- Parent(s)
- \Zend_Validate_Abstract
- Children
- \Zend_Validate_File_ExcludeMimeType
- \Zend_Validate_File_IsImage
- \Zend_Validate_File_IsCompressed
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants
Properties


\Zend_Translate $_defaultTranslator =
Default translation object for all validate objects
Inherited from: \Zend_Validate_Abstract::$$_defaultTranslator- Type
- \Zend_Translate
- Inherited_from
- \Zend_Validate_Abstract::$$_defaultTranslator


array $_errors = array()
Array of validation failure message codes
Inherited from: \Zend_Validate_Abstract::$$_errorsarray()
Details- Type
- array
- Inherited_from
- \Zend_Validate_Abstract::$$_errors


array $_magicFiles = 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')
If no $_ENV['MAGIC'] is set, try and autodiscover it based on common locations
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')
Details- Type
- array


Integer $_messageLength = -1
Limits the maximum returned length of a error message
Inherited from: \Zend_Validate_Abstract::$$_messageLength-1
Details- Type
- Integer
- Inherited_from
- \Zend_Validate_Abstract::$$_messageLength


array $_messageTemplates = array(self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", self::NOT_READABLE => "File '%value%' is not readable or does not exist")
Validation failure message template definitions
array(self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", self::NOT_READABLE => "File '%value%' is not readable or does not exist")
Details- Type
- array


array $_messageVariables = array('type' => '_type')
Additional variables available for validation failure messages
array('type' => '_type')
Details- Type
- array


array $_messages = array()
array()
Details- Type
- array
- Inherited_from
- \Zend_Validate_Abstract::$$_messages


bool $_obscureValue = false
Flag indidcating whether or not value should be obfuscated in error messages
Inherited from: \Zend_Validate_Abstract::$$_obscureValuefalse
Details- Type
- bool
- Inherited_from
- \Zend_Validate_Abstract::$$_obscureValue


\Zend_Translate $_translator =
- Type
- \Zend_Translate
- Inherited_from
- \Zend_Validate_Abstract::$$_translator


Boolean $_translatorDisabled = false
false
Details- Type
- Boolean
- Inherited_from
- \Zend_Validate_Abstract::$$_translatorDisabled


boolean $_tryCommonMagicFiles = true
Indicates whether use of $_magicFiles should be attempted.
true
Details- Type
- boolean
Methods


__construct(string | array $mimetype) : void
Sets validator options
Mimetype to accept
Name | Type | Description |
---|---|---|
$mimetype | string | array | MimeType |


__get(string $property) : mixed
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
Inherited from: \Zend_Validate_Abstract::__get()Name | Type | Description |
---|---|---|
$property | string |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\Zend_Validate_Exception |


_createMessage(string $messageKey, string $value) : string
Constructs and returns a validation failure message with the given message key and value.
Inherited from: \Zend_Validate_Abstract::_createMessage()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.
Name | Type | Description |
---|---|---|
$messageKey | string | |
$value | string |
Type | Description |
---|---|
string |


_error(string $messageKey, string $value = null) : void
Name | Type | Description |
---|---|---|
$messageKey | string | |
$value | string | OPTIONAL |


_setValue(mixed $value) : void
Sets the value to be validated and clears the messages and errors arrays
Inherited from: \Zend_Validate_Abstract::_setValue()Name | Type | Description |
---|---|---|
$value | mixed |


_throw(string $file, string $errorType) : false
Throws an error of the given type
Name | Type | Description |
---|---|---|
$file | string | |
$errorType | string |
Type | Description |
---|---|
false |


addMimeType(string | array $mimetype) : \Zend_Validate_File_Extension
Adds the mimetypes
Name | Type | Description |
---|---|---|
$mimetype | string | array | The mimetypes to add for validation |
Type | Description |
---|---|
\Zend_Validate_File_Extension | Provides a fluent interface |


enableHeaderCheck( $headerCheck = true) : \Zend_Validate_File_MimeType
Defines if the http header should be used Note that this is unsave and therefor the default value is false
Name | Type | Description |
---|---|---|
$headerCheck |
Type | Description |
---|---|
\Zend_Validate_File_MimeType | Provides fluid interface |


getDefaultTranslator() : \Zend_Translate_Adapter | null
Get default translation object for all validate objects
Inherited from: \Zend_Validate_Abstract::getDefaultTranslator()Type | Description |
---|---|
\Zend_Translate_Adapter | null |


getErrors() : array
Returns array of validation failure message codes
Inherited from: \Zend_Validate_Abstract::getErrors()Type | Description |
---|---|
array |


getMagicFile() : string
Returns the actual set magicfile
Note that for PHP 5.3.0 or higher, we don't use $_ENV['MAGIC'] or try to find a magic file in a common location as PHP now has a built-in internal magic file.
Type | Description |
---|---|
string |


getMessageLength() : integer
Returns the maximum allowed message length
Inherited from: \Zend_Validate_Abstract::getMessageLength()Type | Description |
---|---|
integer |


getMessageTemplates() : array
Returns the message templates from the validator
Inherited from: \Zend_Validate_Abstract::getMessageTemplates()Type | Description |
---|---|
array |


getMessageVariables() : array
Returns an array of the names of variables that are used in constructing validation failure messages
Inherited from: \Zend_Validate_Abstract::getMessageVariables()Type | Description |
---|---|
array |


getMessages() : array
Returns array of validation failure messages
Inherited from: \Zend_Validate_Abstract::getMessages()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.
Type | Description |
---|---|
array |


getMimeType(boolean $asArray = false) : string | array
Returns the set mimetypes
Name | Type | Description |
---|---|---|
$asArray | boolean | Returns the values as array, when false an concated string is returned |
Type | Description |
---|---|
string | array |


getObscureValue() : bool
Retrieve flag indicating whether or not value should be obfuscated in messages
Inherited from: \Zend_Validate_Abstract::getObscureValue()Type | Description |
---|---|
bool |


getTranslator() : \Zend_Translate_Adapter | null
Type | Description |
---|---|
\Zend_Translate_Adapter | null |


hasDefaultTranslator() : boolean
Is there a default translation object set?
Inherited from: \Zend_Validate_Abstract::hasDefaultTranslator()Type | Description |
---|---|
boolean |


hasTranslator() : bool
Does this validator have its own specific translator?
Inherited from: \Zend_Validate_Abstract::hasTranslator()Type | Description |
---|---|
bool |


isValid(string $value, array $file = null) : boolean
Defined by Zend_Validate_Interface
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.
Name | Type | Description |
---|---|---|
$value | string | Real file to check for mimetype |
$file | array | File data from Zend_File_Transfer |
Type | Description |
---|---|
boolean |
Exception | Description |
---|---|
\Zend_Validate_Exception | If validation of $value is impossible |


setDefaultTranslator(\Zend_Translate | \Zend_Translate_Adapter | null $translator = null) : void
Set default translation object for all validate objects
Inherited from: \Zend_Validate_Abstract::setDefaultTranslator()Name | Type | Description |
---|---|---|
$translator | \Zend_Translate | \Zend_Translate_Adapter | null |


setDisableTranslator(bool $flag) : \Zend_Validate_Abstract
Indicate whether or not translation should be disabled
Inherited from: \Zend_Validate_Abstract::setDisableTranslator()Name | Type | Description |
---|---|---|
$flag | bool |
Type | Description |
---|---|
\Zend_Validate_Abstract |


setMagicFile(string $file) : \Zend_Validate_File_MimeType
Sets the magicfile to use if null, the MAGIC constant from php is used if the MAGIC file is errorous, no file will be set
Name | Type | Description |
---|---|---|
$file | string |
Type | Description |
---|---|
\Zend_Validate_File_MimeType | Provides fluid interface |
Exception | Description |
---|---|
\Zend_Validate_Exception | When finfo can not read the magicfile |


setMessage(string $messageString, string $messageKey = null) : \Zend_Validate_Abstract
Sets the validation failure message template for a particular key
Inherited from: \Zend_Validate_Abstract::setMessage()Name | Type | Description |
---|---|---|
$messageString | string | |
$messageKey | string | OPTIONAL |
Type | Description |
---|---|
\Zend_Validate_Abstract | Provides a fluent interface |
Exception | Description |
---|---|
\Zend_Validate_Exception |


setMessageLength(integer $length = -1) : void
Sets the maximum allowed message length
Inherited from: \Zend_Validate_Abstract::setMessageLength()Name | Type | Description |
---|---|---|
$length | integer |


setMessages(array $messages) : \Zend_Validate_Abstract
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.
Inherited from: \Zend_Validate_Abstract::setMessages()Name | Type | Description |
---|---|---|
$messages | array |
Type | Description |
---|---|
\Zend_Validate_Abstract |


setMimeType(string | array $mimetype) : \Zend_Validate_File_Extension
Sets the mimetypes
Name | Type | Description |
---|---|---|
$mimetype | string | array | The mimetypes to validate |
Type | Description |
---|---|
\Zend_Validate_File_Extension | Provides a fluent interface |


setObscureValue(bool $flag) : \Zend_Validate_Abstract
Set flag indicating whether or not value should be obfuscated in messages
Inherited from: \Zend_Validate_Abstract::setObscureValue()Name | Type | Description |
---|---|---|
$flag | bool |
Type | Description |
---|---|
\Zend_Validate_Abstract |


setTranslator(\Zend_Translate | \Zend_Translate_Adapter | null $translator = null) : \Zend_Validate_Abstract
Name | Type | Description |
---|---|---|
$translator | \Zend_Translate | \Zend_Translate_Adapter | null |
Type | Description |
---|---|
\Zend_Validate_Abstract |


setTryCommonMagicFilesFlag(boolean $flag = true) : \Zend_Validate_File_MimeType
Enables or disables attempts to try the common magic file locations specified by Zend_Validate_File_MimeType::_magicFiles
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
\Zend_Validate_File_MimeType | Provides fluent interface |
- See
- \global\http://framework.zend.com/issues/browse/ZF-11784


shouldTryCommonMagicFiles() : boolean
Accessor for Zend_Validate_File_MimeType::_magicFiles
Type | Description |
---|---|
boolean |
- See
- \global\http://framework.zend.com/issues/browse/ZF-11784