PHP Class Codesleeve\Stapler\Attachment

Show file Open project: codesleeve/stapler Class Usage Examples

Protected Properties

Property Type Description
$config Codesleeve\Stapler\AttachmentConfig An instance of the configuration class.
$instance Codesleeve\Stapler\ORM\StaplerableInterface The model instance that the attachment belongs to.
$interpolator Codesleeve\Stapler\Interfaces\Interpolator An instance of the interpolator class for processing interpolations.
$queuedForDeletion array The uploaded/resized files that have been queued up for deletion.
$queuedForWrite array The uploaded/resized files that have been queued up to be written to storage.
$resizer Codesleeve\Stapler\File\Image\Resizer An instance of the resizer library that's being used for image processing.
$storageDriver StorageInterface. An instance of the underlying storage driver that is being used.
$uploadedFile Codesleeve\Stapler\Interfaces\File The uploaded file object for the attachment.

Public Methods

Method Description
__call ( string $method, array $parameters ) : mixed Handle dynamic method calls on the attachment.
__construct ( Codesleeve\Stapler\AttachmentConfig $config, Codesleeve\Stapler\Interfaces\Interpolator $interpolator, Codesleeve\Stapler\Interfaces\Resizer $resizer ) Constructor method.
__get ( string $optionName ) : mixed Handle the dynamic retrieval of attachment options.
__set ( string $name, mixed $value ) Handle the dynamic setting of attachment options.
afterDelete ( Codesleeve\Stapler\ORM\StaplerableInterface $instance ) Process the delete queue.
afterSave ( Codesleeve\Stapler\ORM\StaplerableInterface $instance ) Process the write queue.
beforeDelete ( Codesleeve\Stapler\ORM\StaplerableInterface $instance ) Queue up this attachments files for deletion.
clear ( array $stylesToClear = [] ) Queues up all or some of this attachments uploaded files/images for deletion.
clearAttributes ( ) Clear (set to null) all attachment related model attributes.
contentType ( ) : string Returns the content type of the file as originally assigned to this attachment's model.
createdAt ( ) : string Returns the creation time of the file as originally assigned to this attachment's model.
destroy ( array $stylesToClear = [] ) Removes all uploaded files (from storage) for this attachment.
getConfig ( ) : array Accessor method for the Config property.
getInstance ( ) : Codesleeve\Stapler\ORM\StaplerableInterface Accessor method for the underlying instance (model) object this attachment is defined on.
getInstanceClass ( ) : string Returns the class type of the attachment's underlying model instance.
getInterpolator ( ) : Codesleeve\Stapler\Interfaces\Interpolator Accessor method for the interpolator property.
getQueuedForDeletion ( ) : array Accessor method for the QueuedForDeletion property.
getResizer ( ) : Resizer Accessor method for the uploadedFile property.
getStorageDriver ( ) : Codesleeve\Stapler\Interfaces\Storage Accessor method for the storageDriver property.
getUploadedFile ( ) : Codesleeve\Stapler\Interfaces\File Accessor method for the uploadedFile property.
instanceWrite ( string $property, mixed $value ) Set an attachment attribute on the underlying model instance.
jsonSerialize ( ) : array Return a JSON representation of this class.
originalFilename ( ) : string Returns the name of the file as originally assigned to this attachment's model.
path ( string $styleName = '' ) : string Generates the file system path to an uploaded file (or a resized version of it).
reprocess ( ) Rebuilds the images for this attachment.
save ( ) Flushes the queuedForDeletion and queuedForWrite arrays.
setConfig ( Codesleeve\Stapler\AttachmentConfig $config ) Mutator method for the config property.
setInstance ( Codesleeve\Stapler\ORM\StaplerableInterface $instance ) Mutator method for the instance property.
setInterpolator ( Codesleeve\Stapler\Interfaces\Interpolator $interpolator ) Mutator method for the interpolator property.
setQueuedForDeletion ( array $array ) Mutator method for the QueuedForDeletion property.
setResizer ( Codesleeve\Stapler\Interfaces\Resizer $resizer ) Mutator method for the resizer property.
setStorageDriver ( Codesleeve\Stapler\Interfaces\Storage $storageDriver ) Mutator method for the storageDriver property.
setUploadedFile ( mixed $uploadedFile ) Mutator method for the uploadedFile property.
size ( ) : integer Returns the size of the file as originally assigned to this attachment's model.
updatedAt ( ) : string Returns the last modified time of the file as originally assigned to this attachment's model.
url ( string $styleName = '' ) : string Generates the url to an uploaded file (or a resized version of it).

Protected Methods

Method Description
defaultPath ( string $styleName = '' ) : string Generates the default path if no file attachment is present.
defaultUrl ( string $styleName = '' ) : string Generates the default url if no file attachment is present.
flushDeletes ( ) Process the queuedForDeletion que.
flushWrites ( ) Process the queuedForWrite que.
queueAllForDeletion ( ) Add all uploaded files (across all image styles) to the queuedForDeletion queue.
queueAllForWrite ( ) Fill the queuedForWrite que with all of this attachment's styles.
queueSomeForDeletion ( array $stylesToClear ) Add a subset (filtered via style) of the uploaded files for this attachment to the queuedForDeletion queue.

Method Details

__call() public method

This allows us to call methods on the underlying storage driver directly via the attachment.
public __call ( string $method, array $parameters ) : mixed
$method string
$parameters array
return mixed

__construct() public method

Constructor method.
public __construct ( Codesleeve\Stapler\AttachmentConfig $config, Codesleeve\Stapler\Interfaces\Interpolator $interpolator, Codesleeve\Stapler\Interfaces\Resizer $resizer )
$config Codesleeve\Stapler\AttachmentConfig
$interpolator Codesleeve\Stapler\Interfaces\Interpolator
$resizer Codesleeve\Stapler\Interfaces\Resizer

__get() public method

Style options will be converted into a php stcClass.
public __get ( string $optionName ) : mixed
$optionName string
return mixed

__set() public method

Handle the dynamic setting of attachment options.
public __set ( string $name, mixed $value )
$name string
$value mixed

afterDelete() public method

Process the delete queue.
public afterDelete ( Codesleeve\Stapler\ORM\StaplerableInterface $instance )
$instance Codesleeve\Stapler\ORM\StaplerableInterface

afterSave() public method

Process the write queue.
public afterSave ( Codesleeve\Stapler\ORM\StaplerableInterface $instance )
$instance Codesleeve\Stapler\ORM\StaplerableInterface

beforeDelete() public method

Queue up this attachments files for deletion.
public beforeDelete ( Codesleeve\Stapler\ORM\StaplerableInterface $instance )
$instance Codesleeve\Stapler\ORM\StaplerableInterface

clear() public method

Queues up all or some of this attachments uploaded files/images for deletion.
public clear ( array $stylesToClear = [] )
$stylesToClear array

clearAttributes() public method

Clear (set to null) all attachment related model attributes.
public clearAttributes ( )

contentType() public method

Lives in the _content_type attribute of the model.
public contentType ( ) : string
return string

createdAt() public method

Lives in the _created_at attribute of the model. This attribute may conditionally exist on the model, it is not one of the four required fields.
public createdAt ( ) : string
return string

defaultPath() protected method

Generates the default path if no file attachment is present.
protected defaultPath ( string $styleName = '' ) : string
$styleName string
return string

defaultUrl() protected method

Generates the default url if no file attachment is present.
protected defaultUrl ( string $styleName = '' ) : string
$styleName string
return string

destroy() public method

This method does not clear out attachment attributes on the model instance.
public destroy ( array $stylesToClear = [] )
$stylesToClear array

flushDeletes() protected method

Process the queuedForDeletion que.
protected flushDeletes ( )

flushWrites() protected method

Process the queuedForWrite que.
protected flushWrites ( )

getConfig() public method

Accessor method for the Config property.
public getConfig ( ) : array
return array

getInstance() public method

Accessor method for the underlying instance (model) object this attachment is defined on.
public getInstance ( ) : Codesleeve\Stapler\ORM\StaplerableInterface
return Codesleeve\Stapler\ORM\StaplerableInterface

getInstanceClass() public method

Returns the class type of the attachment's underlying model instance.
public getInstanceClass ( ) : string
return string

getInterpolator() public method

Accessor method for the interpolator property.
public getInterpolator ( ) : Codesleeve\Stapler\Interfaces\Interpolator
return Codesleeve\Stapler\Interfaces\Interpolator

getQueuedForDeletion() public method

Accessor method for the QueuedForDeletion property.
public getQueuedForDeletion ( ) : array
return array

getResizer() public method

Accessor method for the uploadedFile property.
public getResizer ( ) : Resizer
return Resizer

getStorageDriver() public method

Accessor method for the storageDriver property.
public getStorageDriver ( ) : Codesleeve\Stapler\Interfaces\Storage
return Codesleeve\Stapler\Interfaces\Storage

getUploadedFile() public method

Accessor method for the uploadedFile property.
public getUploadedFile ( ) : Codesleeve\Stapler\Interfaces\File
return Codesleeve\Stapler\Interfaces\File

instanceWrite() public method

Set an attachment attribute on the underlying model instance.
public instanceWrite ( string $property, mixed $value )
$property string
$value mixed

jsonSerialize() public method

Return a JSON representation of this class.
public jsonSerialize ( ) : array
return array

originalFilename() public method

Lives in the _file_name attribute of the model.
public originalFilename ( ) : string
return string

path() public method

This is used for saving files, etc.
public path ( string $styleName = '' ) : string
$styleName string
return string

queueAllForDeletion() protected method

Add all uploaded files (across all image styles) to the queuedForDeletion queue.
protected queueAllForDeletion ( )

queueAllForWrite() protected method

Fill the queuedForWrite que with all of this attachment's styles.
protected queueAllForWrite ( )

queueSomeForDeletion() protected method

Add a subset (filtered via style) of the uploaded files for this attachment to the queuedForDeletion queue.
protected queueSomeForDeletion ( array $stylesToClear )
$stylesToClear array

reprocess() public method

Rebuilds the images for this attachment.
public reprocess ( )

save() public method

Flushes the queuedForDeletion and queuedForWrite arrays.
public save ( )

setConfig() public method

Mutator method for the config property.
public setConfig ( Codesleeve\Stapler\AttachmentConfig $config )
$config Codesleeve\Stapler\AttachmentConfig

setInstance() public method

This provides a mechanism for the attachment to access properties of the corresponding model instance it's attached to.
public setInstance ( Codesleeve\Stapler\ORM\StaplerableInterface $instance )
$instance Codesleeve\Stapler\ORM\StaplerableInterface

setInterpolator() public method

Mutator method for the interpolator property.
public setInterpolator ( Codesleeve\Stapler\Interfaces\Interpolator $interpolator )
$interpolator Codesleeve\Stapler\Interfaces\Interpolator

setQueuedForDeletion() public method

Mutator method for the QueuedForDeletion property.
public setQueuedForDeletion ( array $array )
$array array

setResizer() public method

Mutator method for the resizer property.
public setResizer ( Codesleeve\Stapler\Interfaces\Resizer $resizer )
$resizer Codesleeve\Stapler\Interfaces\Resizer

setStorageDriver() public method

Mutator method for the storageDriver property.
public setStorageDriver ( Codesleeve\Stapler\Interfaces\Storage $storageDriver )
$storageDriver Codesleeve\Stapler\Interfaces\Storage

setUploadedFile() public method

Accepts the following inputs: - An absolute string url (for fetching remote files). - An array (data parsed from the $_FILES array), - A Symfony uploaded file object.
public setUploadedFile ( mixed $uploadedFile )
$uploadedFile mixed

size() public method

Lives in the _file_size attribute of the model.
public size ( ) : integer
return integer

updatedAt() public method

Lives in the _updated_at attribute of the model.
public updatedAt ( ) : string
return string

url() public method

Generates the url to an uploaded file (or a resized version of it).
public url ( string $styleName = '' ) : string
$styleName string
return string

Property Details

$config protected property

An instance of the configuration class.
protected AttachmentConfig,Codesleeve\Stapler $config
return Codesleeve\Stapler\AttachmentConfig

$instance protected property

The model instance that the attachment belongs to.
protected StaplerableInterface,Codesleeve\Stapler\ORM $instance
return Codesleeve\Stapler\ORM\StaplerableInterface

$interpolator protected property

An instance of the interpolator class for processing interpolations.
protected Interpolator,Codesleeve\Stapler\Interfaces $interpolator
return Codesleeve\Stapler\Interfaces\Interpolator

$queuedForDeletion protected property

The uploaded/resized files that have been queued up for deletion.
protected array $queuedForDeletion
return array

$queuedForWrite protected property

The uploaded/resized files that have been queued up to be written to storage.
protected array $queuedForWrite
return array

$resizer protected property

An instance of the resizer library that's being used for image processing.
protected Resizer,Codesleeve\Stapler\File\Image $resizer
return Codesleeve\Stapler\File\Image\Resizer

$storageDriver protected property

An instance of the underlying storage driver that is being used.
protected StorageInterface. $storageDriver
return StorageInterface.

$uploadedFile protected property

The uploaded file object for the attachment.
protected File,Codesleeve\Stapler\Interfaces $uploadedFile
return Codesleeve\Stapler\Interfaces\File