PHP Класс MeioUploadBehavior, MeioUpload

Наследование: extends ModelBehavior
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$__fields array The array that saves the $options for the behavior
$__filesToRemove array Array of files to be removed on the afterSave callback
$_imageTypes array Array of all possible images that can be converted to thumbnails
$defaultOptions array The default options for the behavior
$defaultValidations array Default validations
$patterns array Patterns of reserved words
$replacements array Words to replace the patterns of reserved words

Открытые методы

Метод Описание
__construct ( ) Constructor
_addError ( string $msg ) : void Adds an error, legacy from the component
_arrayMerge ( array $arr, array $ins ) : array Merges two arrays recursively
_copyFileFromTemp ( string $tmpName, string $saveAs, integer $filePermission ) : mixed Copies file from temporary directory to final destination
_createFolders ( string $dir, string $thumbDir, array $thumbsizes, integer $folderPermission ) : void Creates thumbnail folders if they do not already exist
_createThumbnail ( object &$model, string $source, string $target, string $fieldName, array $params = [] ) : void Function to create Thumbnail images
_createThumbnails ( object &$model, array $data, string $fieldName, $saveAs, string $ext, array $options ) : void Create all the thumbnails
_deleteFiles ( object &$model, string $field, string $filename, stirng $dir ) : boolean Delete the $filename inside the $dir and the thumbnails.
_deleteFilesList ( object &$model ) : void Deletes the files marked to be deleted in the save method.
_fixName ( object &$model, string $fieldName, boolean $checkFile = true ) : void Removes the bad characters from the $filename and replace reserved words. It updates the $model->data.
_getThumbnailName ( string $saveAs, string $dir, string $thumbDir, string $key, string $fieldToSaveAs, string $sub = null ) : string Generate the name for the thumbnail If a 'normal' thumbnail is set, then it will overwrite the original file
_includeDefaultReplacement ( string $default ) : void Include a pattern of reserved word based on a filename, and it's replacement.
_markForDeletion ( object &$model, string $fieldName, array $data, strng $default, string $thumbDir ) : void Marks files for deletion in the beforeSave() callback
_nullifyDataFields ( object &$model, string $fieldName, array $data, array $options ) : array Sets as NULL data from $data Useful when deleting a file.
_removeOriginal ( string $saveAs ) : boolean Remove original file
_replaceTokens ( object &$model, string $string, string $fieldName, array $tokens = [] ) : string Replaces some tokens. {ModelName} to the underscore version of the model name {fieldName} to the field name, {DS}. / or \ to DS constant value.
_setFileToRemove ( object &$model, sting $fieldName, string $thumbDir ) : void Set a file to be removed in afterSave() callback
_setupValidation ( object &$model, string $fieldName, array $options ) : void Sets the validation for each field, based on the options.
_sizeToBytes ( string $size ) : integer Convert a size value to bytes. For example: 2 MB to 2097152.
_splitFilenameAndExt ( string $filename ) : array Splits a filename in two parts: the name and the extension. Returns an array with it respectively.
_unsetDataFields ( string $modelName, string $fieldName, array $data, array $options ) : array Unsets data from $data Useful for no-db upload
_uploadCheckSize ( object &$model, array &$data, string $type ) : boolean Check generic to size of image
_uploadFile ( object &$model, array $data = null ) : mixed Uploads the files
afterDelete ( Model $model ) : void After delete (callback)
afterSave ( Model $model, $created ) : void After save (callback)
beforeDelete ( Model $model, $cascade = true ) : boolean Deletes all files associated with the record beforing delete it.
beforeSave ( Model $model ) : boolean Initializes the upload
beforeValidate ( Model $model ) : boolean Sets the validation rules for each field.
regenerateThumbnails ( Model $model ) Regenerate all the thumbnails, for all fields that have thumbSizes, for records in the table. (used, eg, when you want to add or change thumbnail sizes) This will overwrite existing thumbnails, when they exist, so a backup of thumbnails should be done before hand.
setup ( Model $model, array $settings = [] ) : void Setup the behavior. It stores a reference to the model, merges the default options with the options for each field, and setup the validation rules.
upload ( object &$model, array $data ) : boolean Performs a manual upload
uploadCheckDir ( object &$model, array $data ) : boolean Checks if the folder exists or can be created or writable.
uploadCheckEmpty ( object &$model, array $data ) : boolean Checks if the filename is not empty.
uploadCheckFieldName ( object &$model, array $data ) : boolean Checks if the field was declared in the MeioUpload Behavior setup
uploadCheckHttpPost ( object &$model, array $data ) : boolean Checks if the file is uploaded via HTTP POST
uploadCheckInvalidExt ( object &$model, array $data ) : boolean Checks if the file has an allowed extension.
uploadCheckInvalidMime ( object &$model, array $data ) : boolean Checks if the file is of an allowed mime-type.
uploadCheckMaxHeight ( object &$model, array $data ) : boolean Checks if the max height is allowed
uploadCheckMaxSize ( object &$model, array $data ) : boolean Checks if the file isn't bigger then the max file size option.
uploadCheckMaxWidth ( object &$model, array $data ) : boolean Checks if the max width is allowed
uploadCheckMinHeight ( object &$model, array $data ) : boolean Checks if the min height is allowed
uploadCheckMinWidth ( object &$model, array $data ) : boolean Checks if the min width is allowed
uploadCheckUploadError ( object &$model, array $data ) : boolean Checks if ocurred erros in the upload.

Описание методов

__construct() публичный Метод

Constructor
public __construct ( )

_addError() публичный Метод

Adds an error, legacy from the component
public _addError ( string $msg ) : void
$msg string error message
Результат void

_arrayMerge() публичный Метод

These values will remain intact even if the passed options were shorter. Solved that with array_splice to keep intact the previous indexes (already merged)
public _arrayMerge ( array $arr, array $ins ) : array
$arr array
$ins array
Результат array

_copyFileFromTemp() публичный Метод

Copies file from temporary directory to final destination
public _copyFileFromTemp ( string $tmpName, string $saveAs, integer $filePermission ) : mixed
$tmpName string full path to temporary file
$saveAs string full path to move the file to
$filePermission integer octal value of created file permission
Результат mixed true is successful, error message if not

_createFolders() публичный Метод

Creates thumbnail folders if they do not already exist
public _createFolders ( string $dir, string $thumbDir, array $thumbsizes, integer $folderPermission ) : void
$dir string Path to uploads
$thumbDir string Path to thumbnails
$thumbsizes array
$folderPermission integer octal value of created folder permission
Результат void

_createThumbnail() публичный Метод

Function to create Thumbnail images
public _createThumbnail ( object &$model, string $source, string $target, string $fieldName, array $params = [] ) : void
$model object Reference to model
$source string File name (without path)
$target string File name (without path)
$fieldName string
$params array
Результат void

_createThumbnails() публичный Метод

Create all the thumbnails
public _createThumbnails ( object &$model, array $data, string $fieldName, $saveAs, string $ext, array $options ) : void
$model object Reference to model
$data array
$fieldName string
$ext string
$options array
Результат void

_deleteFiles() публичный Метод

Returns true if the file is deleted and false otherwise.
public _deleteFiles ( object &$model, string $field, string $filename, stirng $dir ) : boolean
$model object Reference to model
$field string
$filename string
$dir stirng
Результат boolean

_deleteFilesList() публичный Метод

A file can be marked to be deleted if it is overwriten by another or if the user mark it to be deleted.
public _deleteFilesList ( object &$model ) : void
$model object Reference to model
Результат void

_fixName() публичный Метод

Removes the bad characters from the $filename and replace reserved words. It updates the $model->data.
public _fixName ( object &$model, string $fieldName, boolean $checkFile = true ) : void
$model object Reference to model
$fieldName string
$checkFile boolean
Результат void

_getThumbnailName() публичный Метод

Generate the name for the thumbnail If a 'normal' thumbnail is set, then it will overwrite the original file
public _getThumbnailName ( string $saveAs, string $dir, string $thumbDir, string $key, string $fieldToSaveAs, string $sub = null ) : string
$saveAs string name for original file
$dir string directory for all uploads
$thumbDir string Path to thumbnails
$key string thumbnail size
$fieldToSaveAs string field in model to save as
$sub string substring to append to directory for naming
Результат string

_includeDefaultReplacement() публичный Метод

Include a pattern of reserved word based on a filename, and it's replacement.
public _includeDefaultReplacement ( string $default ) : void
$default string
Результат void

_markForDeletion() публичный Метод

Marks files for deletion in the beforeSave() callback
public _markForDeletion ( object &$model, string $fieldName, array $data, strng $default, string $thumbDir ) : void
$model object Reference to model
$fieldName string name of field that holds a reference to the file
$data array
$default strng
$thumbDir string Thumb directory
Результат void

_nullifyDataFields() публичный Метод

Sets as NULL data from $data Useful when deleting a file.
public _nullifyDataFields ( object &$model, string $fieldName, array $data, array $options ) : array
$model object Reference to model
$fieldName string name of field that holds a reference to the file
$data array
$options array
Результат array

_removeOriginal() публичный Метод

Remove original file
public _removeOriginal ( string $saveAs ) : boolean
$saveAs string
Результат boolean

_replaceTokens() публичный Метод

Replaces some tokens. {ModelName} to the underscore version of the model name {fieldName} to the field name, {DS}. / or \ to DS constant value.
public _replaceTokens ( object &$model, string $string, string $fieldName, array $tokens = [] ) : string
$model object Reference to model
$string string
$fieldName string
$tokens array
Результат string

_setFileToRemove() публичный Метод

Set a file to be removed in afterSave() callback
public _setFileToRemove ( object &$model, sting $fieldName, string $thumbDir ) : void
$model object Reference to model
$fieldName sting
$thumbDir string Path to thumbnails
Результат void

_setupValidation() публичный Метод

Sets the validation for each field, based on the options.
public _setupValidation ( object &$model, string $fieldName, array $options ) : void
$model object Reference to model
$fieldName string
$options array
Результат void

_sizeToBytes() публичный Метод

Convert a size value to bytes. For example: 2 MB to 2097152.
public _sizeToBytes ( string $size ) : integer
$size string
Результат integer

_splitFilenameAndExt() публичный Метод

Splits a filename in two parts: the name and the extension. Returns an array with it respectively.
public _splitFilenameAndExt ( string $filename ) : array
$filename string
Результат array

_unsetDataFields() публичный Метод

Unsets data from $data Useful for no-db upload
public _unsetDataFields ( string $modelName, string $fieldName, array $data, array $options ) : array
$modelName string name of the Model
$fieldName string name of field that holds a reference to the file
$data array
$options array
Результат array

_uploadCheckSize() публичный Метод

Check generic to size of image
public _uploadCheckSize ( object &$model, array &$data, string $type ) : boolean
$model object Reference to model
$data array Reference to data
$type string Type of check: minHeight, minWidth, maxHeight, maxWidth
Результат boolean

_uploadFile() публичный Метод

Uploads the files
public _uploadFile ( object &$model, array $data = null ) : mixed
$model object Reference to model
$data array Optional Containing data to be saved
Результат mixed

afterDelete() публичный Метод

After delete (callback)
public afterDelete ( Model $model ) : void
$model Model Reference to model
Результат void

afterSave() публичный Метод

After save (callback)
public afterSave ( Model $model, $created ) : void
$model Model Reference to model
Результат void

beforeDelete() публичный Метод

Deletes all files associated with the record beforing delete it.
public beforeDelete ( Model $model, $cascade = true ) : boolean
$model Model Reference to model
Результат boolean Always true

beforeSave() публичный Метод

Initializes the upload
public beforeSave ( Model $model ) : boolean
$model Model Reference to model
Результат boolean Whether the upload completed

beforeValidate() публичный Метод

Sets the validation rules for each field.
public beforeValidate ( Model $model ) : boolean
$model Model Reference to model
Результат boolean Always true

regenerateThumbnails() публичный Метод

This will not delete any redundant thumbnails - redundant thumbnails can be deleted manually. From your controller, call this method like: $this->MyModel->regenerateThumbnails();
public regenerateThumbnails ( Model $model )
$model Model Reference to model

setup() публичный Метод

Setup the behavior. It stores a reference to the model, merges the default options with the options for each field, and setup the validation rules.
public setup ( Model $model, array $settings = [] ) : void
$model Model Reference to model
$settings array Settings (optional)
Результат void

upload() публичный Метод

Performs a manual upload
public upload ( object &$model, array $data ) : boolean
$model object Reference to model
$data array Array data to be saved
Результат boolean Whether the upload completed

uploadCheckDir() публичный Метод

Checks if the folder exists or can be created or writable.
public uploadCheckDir ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckEmpty() публичный Метод

Checks if the filename is not empty.
public uploadCheckEmpty ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckFieldName() публичный Метод

Checks if the field was declared in the MeioUpload Behavior setup
public uploadCheckFieldName ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckHttpPost() публичный Метод

Checks if the file is uploaded via HTTP POST
public uploadCheckHttpPost ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckInvalidExt() публичный Метод

Checks if the file has an allowed extension.
public uploadCheckInvalidExt ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckInvalidMime() публичный Метод

Checks if the file is of an allowed mime-type.
public uploadCheckInvalidMime ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckMaxHeight() публичный Метод

Checks if the max height is allowed
public uploadCheckMaxHeight ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckMaxSize() публичный Метод

Checks if the file isn't bigger then the max file size option.
public uploadCheckMaxSize ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckMaxWidth() публичный Метод

Checks if the max width is allowed
public uploadCheckMaxWidth ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckMinHeight() публичный Метод

Checks if the min height is allowed
public uploadCheckMinHeight ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckMinWidth() публичный Метод

Checks if the min width is allowed
public uploadCheckMinWidth ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

uploadCheckUploadError() публичный Метод

Checks if ocurred erros in the upload.
public uploadCheckUploadError ( object &$model, array $data ) : boolean
$model object Reference to model
$data array
Результат boolean

Описание свойств

$__fields публичное свойство

The array that saves the $options for the behavior
public array $__fields
Результат array

$__filesToRemove публичное свойство

Array of files to be removed on the afterSave callback
public array $__filesToRemove
Результат array

$_imageTypes публичное свойство

Array of all possible images that can be converted to thumbnails
public array $_imageTypes
Результат array

$defaultOptions публичное свойство

The default options for the behavior
public array $defaultOptions
Результат array

$defaultValidations публичное свойство

Default validations
public array $defaultValidations
Результат array

$patterns публичное свойство

Patterns of reserved words
public array $patterns
Результат array

$replacements публичное свойство

Words to replace the patterns of reserved words
public array $replacements
Результат array