Class luya\admin\file\Item

Inheritanceluya\admin\file\Item » luya\admin\storage\ItemAbstract » yii\base\BaseObject
Implementsluya\web\LinkInterface, yii\base\Arrayable, yii\base\Configurable
Uses Traitsluya\web\LinkTrait, yii\base\ArrayableTrait
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-admin/blob/master/src/file/Item.php

Storage File Item.

Public Properties

Hide inherited properties

Property Type Description Defined By
$caption string The file caption luya\admin\file\Item
$captionArray array Contains the captions for all languages luya\admin\file\Item
$content string Returns the content fo the file. luya\admin\file\Item
$extension string The file extension name like jpg, gif, png etc. luya\admin\file\Item
$fileExists \luya\admin\file\booelan Whether the file resource exists in the storage folder or not. luya\admin\file\Item
$fileHash string luya\admin\file\Item
$folder luya\admin\folder\Item Get the folder item object. luya\admin\file\Item
$folderId integer The id of the folder the file is stored in. luya\admin\file\Item
$hashName string The 8 chars long unique hash name of the file. luya\admin\file\Item
$href string Get the href value for the item based from $linkAbsolute luya\admin\file\Item
$id integer The File id luya\admin\file\Item
$isDeleted boolean Return whether the file has been removed from the filesytem or not. luya\admin\file\Item
$isHidden boolean Whether the file is marked as hidden or not. luya\admin\file\Item
$isImage boolean Whether the file is of type image or not. luya\admin\file\Item
$itemArray array An array with all elements assigned for this element. luya\admin\storage\ItemAbstract
$linkAbsolute string Get the absolute link path to the file. luya\admin\file\Item
$mimeType string The MIME type of the file while uploading. luya\admin\file\Item
$name string Get the original file name of the file. luya\admin\file\Item
$serverSource string The path to the file on the filesystem of the server. luya\admin\file\Item
$size integer Size of the file in Bytes. luya\admin\file\Item
$sizeReadable string The humand readable size. luya\admin\file\Item
$source string The source url to the file inside the storage folder with nice Urls. luya\admin\file\Item
$sourceAbsolute string The absolute source url to the file inside the storage folder with nice Urls. luya\admin\file\Item
$systemFileName string The new file name inside the storage folder. luya\admin\file\Item
$target string Get the link target attribute value. luya\admin\file\Item
$uploadTimestamp integer Unix timestamp when the file has been uploaded. luya\admin\file\Item

Public Methods

Hide inherited methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__toString() Return the href string from getHref() when echoing the object. luya\web\LinkTrait
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
create() Method to construct/build the item from Iterator or Query class. luya\admin\storage\ItemAbstract
extraFields() Returns the list of fields that can be expanded further and returned by toArray(). yii\base\ArrayableTrait
fields() Returns the list of fields that should be returned by default by toArray() when no specific fields are specified. luya\admin\file\Item
getCaption() Return the caption text for this file, if not defined the item array will be collected luya\admin\file\Item
getCaptionArray() Get the array with all captions from the filemanager global "captions" definition for all provided languages luya\admin\file\Item
getContent() Get the file content. luya\admin\file\Item
getExtension() Get the file extension. luya\admin\file\Item
getFileExists() Return boolean value whether the file server source exsits on the server or not. luya\admin\file\Item
getFileHash() Get the md5 sum of the file calculated when creating. luya\admin\file\Item
getFolder() Get the Folder Object where the file is stored in. luya\admin\file\Item
getFolderId() Get the Id of the folder fhe file is stored in. luya\admin\file\Item
getHashName() The unique file hash name for the file itself. luya\admin\file\Item
getHref() Get the href attribute value inside the Link tag. luya\admin\file\Item
getId() Get the ID of the file (File-Id) and has nothing incommon with the image id. luya\admin\file\Item
getIsDeleted() Indicates wether a file is delete from the file system. luya\admin\file\Item
getIsHidden() Return whether the file is hidden or not. luya\admin\file\Item
getIsImage() Whether the file is of type image or not. luya\admin\file\Item
getItemArray() Returns the whole item array. luya\admin\storage\ItemAbstract
getKey() Returns a value for a given key inside the itemArray. luya\admin\storage\ItemAbstract
getLink() Get the link to a file. luya\admin\file\Item
getLinkAbsolute() Get the absolute link url but with the sheme includes, means including server location. luya\admin\file\Item
getMimeType() Get the MIME Type of the file. luya\admin\file\Item
getName() Get the original file name of the file. luya\admin\file\Item
getServerSource() Get the path to the source files internal, on the servers path. luya\admin\file\Item
getSize() Get the size of the file in Bytes. luya\admin\file\Item
getSizeReadable() Get the size of a file in human readable size. luya\admin\file\Item
getSource() Get the absolute source path to the file location on the webserver. luya\admin\file\Item
getSourceAbsolute() Path to the source with sheme includes, means including server location. luya\admin\file\Item
getSystemFileName() Get the new defined storage file Name. luya\admin\file\Item
getTarget() Get the target attribute value inside the Link tag. luya\admin\file\Item
getUploadTimestamp() The Unix Timestamp when the file has been uploaded to the Server. luya\admin\file\Item
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
setCaption() Set caption for file item, override existings values luya\admin\file\Item
setItemArray() Setter method for itemArray property. luya\admin\storage\ItemAbstract
setTarget() Setter method for Link target. luya\admin\file\Item
toArray() Converts the model into an array. yii\base\ArrayableTrait

Protected Methods

Hide inherited methods

Method Description Defined By
extractFieldsFor() Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id". yii\base\ArrayableTrait
extractRootFields() Extracts the root field names from nested fields. yii\base\ArrayableTrait
resolveFields() Determines which fields can be returned by toArray(). yii\base\ArrayableTrait

Property Details

Hide inherited properties

$caption public property

The file caption

public string $caption null
$captionArray public property

Contains the captions for all languages

public array $captionArray null
$content public property

Returns the content fo the file.

public string $content null
$extension public property

The file extension name like jpg, gif, png etc.

public string $extension null
$fileExists public property

Whether the file resource exists in the storage folder or not.

public \luya\admin\file\booelan $fileExists null
$fileHash public read-only property
public string getFileHash ( )
$folder public property

Get the folder item object.

$folderId public property

The id of the folder the file is stored in.

public integer $folderId null
$hashName public property

The 8 chars long unique hash name of the file.

public string $hashName null
$href public property

Get the href value for the item based from $linkAbsolute

public string $href null
$id public property

The File id

public integer $id null
$isDeleted public property

Return whether the file has been removed from the filesytem or not.

public boolean $isDeleted null
$isHidden public property

Whether the file is marked as hidden or not.

public boolean $isHidden null
$isImage public property

Whether the file is of type image or not.

public boolean $isImage null
$linkAbsolute public property

Get the absolute link path to the file.

public string $linkAbsolute null
$mimeType public property

The MIME type of the file while uploading.

public string $mimeType null
$name public property

Get the original file name of the file.

public string $name null
$serverSource public property

The path to the file on the filesystem of the server.

public string $serverSource null
$size public property

Size of the file in Bytes.

public integer $size null
$sizeReadable public property

The humand readable size.

public string $sizeReadable null
$source public property

The source url to the file inside the storage folder with nice Urls.

public string $source null
$sourceAbsolute public property

The absolute source url to the file inside the storage folder with nice Urls.

public string $sourceAbsolute null
$systemFileName public property

The new file name inside the storage folder.

public string $systemFileName null
$target public property

Get the link target attribute value.

public string $target null
$uploadTimestamp public property

Unix timestamp when the file has been uploaded.

public integer $uploadTimestamp null

Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string

The method name

$params array

Method parameters

return mixed

The method return value

throws yii\base\UnknownMethodException

when calling unknown method

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public method

Defined in: yii\base\BaseObject::__construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
public void __construct ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public method

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

See also __set().

public mixed __get ( $name )
$name string

The property name

return mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is write-only

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

Defined in: yii\base\BaseObject::__isset()

Checks if a property is set, i.e. defined and not null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($object->property).

Note that if the property is not defined, false will be returned.

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name string

The property name or the event name

return boolean

Whether the named property is set (not null).

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public method

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

See also __get().

public void __set ( $name, $value )
$name string

The property name or the event name

$value mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is read-only

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__toString() public method

Defined in: luya\web\LinkTrait::__toString()

Return the href string from getHref() when echoing the object.

public void __toString ( )

                public function __toString()
{
    return $this->getHref();
}

            
__unset() public method

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name string

The property name

throws yii\base\InvalidCallException

if the property is read only.

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
canGetProperty() public method

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be read

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public method

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be written

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return string

The fully qualified name of this class.

                public static function className()
{
    return get_called_class();
}

            
create() public static method

Defined in: luya\admin\storage\ItemAbstract::create()

Method to construct/build the item from Iterator or Query class.

public static object create ( array $itemArray )
$itemArray array

The array data

return object

Returns the specific item object (file, folder, image).

                public static function create(array $itemArray)
{
    return Yii::createObject(['class' => self::className(), 'itemArray' => $itemArray]);
}

            
extraFields() public method

Defined in: yii\base\ArrayableTrait::extraFields()

Returns the list of fields that can be expanded further and returned by toArray().

This method is similar to fields() except that the list of fields returned by this method are not returned by default by toArray(). Only when field names to be expanded are explicitly specified when calling toArray(), will their values be exported.

The default implementation returns an empty array.

You may override this method to return a list of expandable fields based on some context information (e.g. the current application user).

See also:

public array extraFields ( )
return array

The list of expandable field names or field definitions. Please refer to fields() on the format of the return value.

                public function extraFields()
{
    return [];
}

            
extractFieldsFor() protected method (available since version 2.0.14)

Defined in: yii\base\ArrayableTrait::extractFieldsFor()

Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id".

protected array extractFieldsFor ( array $fields, $rootField )
$fields array

The fields requested for extraction

$rootField string

The root field for which we want to extract the nested fields

return array

Nested fields extracted for the given field

                protected function extractFieldsFor(array $fields, $rootField)
{
    $result = [];
    foreach ($fields as $field) {
        if (0 === strpos($field, "{$rootField}.")) {
            $result[] = preg_replace('/^' . preg_quote($rootField, '/') . '\./i', '', $field);
        }
    }
    return array_unique($result);
}

            
extractRootFields() protected method (available since version 2.0.14)

Defined in: yii\base\ArrayableTrait::extractRootFields()

Extracts the root field names from nested fields.

Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "item".

protected array extractRootFields ( array $fields )
$fields array

The fields requested for extraction

return array

Root fields extracted from the given nested fields

                protected function extractRootFields(array $fields)
{
    $result = [];
    foreach ($fields as $field) {
        $result[] = current(explode('.', $field, 2));
    }
    if (in_array('*', $result, true)) {
        $result = [];
    }
    return array_unique($result);
}

            
fields() public method

Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.

A field is a named element in the returned array by toArray().

This method should return an array of field names or field definitions. If the former, the field name will be treated as an object property name whose value will be used as the field value. If the latter, the array key should be the field name while the array value should be the corresponding field definition which can be either an object property name or a PHP callable returning the corresponding field value. The signature of the callable should be:

function ($model, $field) {
    // return field value
}

For example, the following code declares four fields:

  • email: the field name is the same as the property name email;
  • firstName and lastName: the field names are firstName and lastName, and their values are obtained from the first_name and last_name properties;
  • fullName: the field name is fullName. Its value is obtained by concatenating first_name and last_name.
return [
    'email',
    'firstName' => 'first_name',
    'lastName' => 'last_name',
    'fullName' => function () {
        return $this->first_name . ' ' . $this->last_name;
    },
];

In this method, you may also want to return different lists of fields based on some context information. For example, depending on the privilege of the current application user, you may return different sets of visible fields or filter out some fields.

The default implementation of this method returns the public object member variables indexed by themselves.

public array fields ( )
return array

The list of field names or field definitions.

                public function fields()
{
    return [
        'id', 'folderId', 'name', 'systemFileName', 'source', 'link', 'href', 'serverSource', 'isImage', 'mimeType', 'extension', 'uploadTimestamp', 'size', 'sizeReadable', 'caption', 'captionArray'
    ];
}

            
getCaption() public method

Return the caption text for this file, if not defined the item array will be collected

public string getCaption ( )
return string

The caption text for this image

                public function getCaption()
{
    if ($this->_caption === null) {
        // if its a none json value, it has been observed by bind()
        if (!Json::isJson($this->getKey('caption', false))) {
            $this->_caption = $this->getKey('caption');
        } else {
            $this->_caption = I18n::findActive($this->getCaptionArray());
        }
    }
    return $this->_caption;
}

            
getCaptionArray() public method

Get the array with all captions from the filemanager global "captions" definition for all provided languages

public array getCaptionArray ( )
return array

Get the array with all captions from the filemanager global "captions" definition for all provided languages

                public function getCaptionArray()
{
    return I18n::decode($this->getKey('caption'));
}

            
getContent() public method (available since version 1.2.0)

Get the file content.

public string getContent ( )

                public function getContent()
{
    return Yii::$app->storage->fileSystemContent($this->systemFileName);
}

            
getExtension() public method

Get the file extension.

Contains the file extension of the file, this is used to concat the new file name with all its components. Example extensions could be:

  • jpg
  • gif
  • pdf
  • png

Its also very commont to check the extensions against the mime type to make reading of files more secure.

public string getExtension ( )
return string

The file extension name like jpg, gif, png etc.

                public function getExtension()
{
    return $this->getKey('extension');
}

            
getFileExists() public method

Return boolean value whether the file server source exsits on the server or not.

public boolean getFileExists ( )
return boolean

Whether the file still exists in the storage folder or not.

                public function getFileExists()
{
    return Yii::$app->storage->fileSystemExists($this->systemFileName);
}

            
getFileHash() public method

Get the md5 sum of the file calculated when creating.

{{luya\helpers\FileHelper::md5sum}}

public string getFileHash ( )

                public function getFileHash()
{
    return $this->getKey('hash_file');
}

            
getFolder() public method

Get the Folder Object where the file is stored in.

public luya\admin\folder\Item getFolder ( )
return luya\admin\folder\Item

The folder object

                public function getFolder()
{
    return Yii::$app->storage->getFolder($this->getFolderId());
}

            
getFolderId() public method

Get the Id of the folder fhe file is stored in.

public integer getFolderId ( )
return integer

The id of the folder where the file is located.

                public function getFolderId()
{
    return (int) $this->getKey('folder_id');
}

            
getHashName() public method

The unique file hash name for the file itself.

This identifier is also used to prevent external access on files when accessing them.

public string getHashName ( )
return string

The 8 chars long unique hash name of the file.

                public function getHashName()
{
    return $this->getKey('hash_name');
}

            
getHref() public method

Get the href attribute value inside the Link tag.

public string getHref ( )
return string

Returns the href string which can be either with or without domain.

                public function getHref()
{
    return $this->linkAbsolute;
}

            
getId() public method

Get the ID of the file (File-Id) and has nothing incommon with the image id.

public integer getId ( )
return integer

The id of the file from the database.

                public function getId()
{
    return (int) $this->getKey('id');
}

            
getIsDeleted() public method

Indicates wether a file is delete from the file system.

When a file is deleted from the filesystem, for example by moving into the trash with the filemanager in the administration area or by any other process who can delete files, the file will be removed from the disk but will still exist in the database but is marked as is_deleted.

public boolean getIsDeleted ( )
return boolean

Return whether the file has been removed from the filesytem or not.

                public function getIsDeleted()
{
    return (bool) $this->getKey('is_deleted');
}

            
getIsHidden() public method

Return whether the file is hidden or not.

Somefiles are uploaded by another process then the filemanager, for example user uploads in the frontend can also be uploaded with the storage system but are hidden from the administration area then the file is hidden but still available and usable.

public boolean getIsHidden ( )
return boolean

Whether the file is marked as hidden or not.

                public function getIsHidden()
{
    return (bool) $this->getKey('is_hidden');
}

            
getIsImage() public method

Whether the file is of type image or not.

If the mime type of the files is equals to:

  • image/gif
  • image/jpeg
  • image/jpg
  • image/png
  • image/bmp
  • image/tiff

The file indicates to be an image and return value is true.

public boolean getIsImage ( )
return boolean

Whether the file is of type image or not.

                public function getIsImage()
{
    return in_array($this->getMimeType(), Yii::$app->storage->imageMimeTypes);
}

            
getItemArray() public method

Defined in: luya\admin\storage\ItemAbstract::getItemArray()

Returns the whole item array.

public array getItemArray ( )
return array

An array with all keys for the given item.

                public function getItemArray()
{
    return $this->_itemArray;
}

            
getKey() public method

Defined in: luya\admin\storage\ItemAbstract::getKey()

Returns a value for a given key inside the itemArray.

public void getKey ( $key, $exception true )
$key string

The requested key.

$exception boolean

Whether getKey should throw an exception if the key is not found or just return false instead.

throws luya\Exception

If the key is not found inside the array an exception is thrown. If $exception is disabled false is returned instead.

                public function getKey($key, $exception = true)
{
    if (!array_key_exists($key, $this->_itemArray)) {
        if ($exception) {
            throw new Exception("Unable to find the requested item key '$key' in item " . var_export($this->_itemArray, true));
        } else {
            return false;
        }
    }
    return $this->_itemArray[$key];
}

            
getLink() public method

Get the link to a file.

The is the most common method when implementing the file object. This method allows you to generate links to the request file. For example you may want users to see the file (assuming its a PDF).

echo '<a href="{Yii::$app->storage->getFile(123)->link}">Download PDF</a>'; // you could also us href instead in order to be more semantic.

The output of source is a url which is provided by a UrlRUle of the admin module and returns nice readable source links:

/file/<ID>/<HASH>/<ORIGINAL_NAME>.<EXTENSION>

which could look like this when fille up:

/public_html/en/file/123/e976e224/foobar.png
public string getLink ( $scheme false )
$scheme
return string

The relative source url to the file inside the storage folder with nice Urls.

getLinkAbsolute() public method

Get the absolute link url but with the sheme includes, means including server location.

This is equals to getLink() method but alos includes the sheme of the current running websites as prefix and is not a relativ url its a static one.

https://luya.io/en/file/123/e976e224/foobar.png
public string getLinkAbsolute ( )
return string

The absolute source url to the file inside the storage folder with nice Urls.

                public function getLinkAbsolute()
{
    return $this->getLink(true);
}

            
getMimeType() public method

Get the MIME Type of the file.

The mime type is defined while uploading the file and is not checked against any other services. For example the MIME type could be:

  • image/png
  • image/jpg
  • image/gif
  • application/pdf
public string getMimeType ( )
return string

The MIME type of the file while uploading.

                public function getMimeType()
{
    return $this->getKey('mime_type');
}

            
getName() public method

Get the original file name of the file.

This is the file name the user has uploaded the file into the administration area. Including the file extensions

public string getName ( )
return string

The original file name

                public function getName()
{
    return $this->getKey('name_original');
}

            
getServerSource() public method

Get the path to the source files internal, on the servers path.

This is used when you want to to grab the file on server side for example to read the file with file_get_contents and is the absolut path on the file system on the server.

public string getServerSource ( )
return string

The path to the file on the filesystem of the server.

                public function getServerSource()
{
    return Yii::$app->storage->fileServerPath($this->systemFileName);
}

            
getSize() public method

Get the size of the file in Bytes.

public string getSize ( )
return string

Size of the file in Bytes.

                public function getSize()
{
    return (int) $this->getKey('file_size');
}

            
getSizeReadable() public method

Get the size of a file in human readable size.

For example sizes are partial splitet in readable forms:

  • 100B
  • 100KB
  • 10MB
  • 1GB
public string getSizeReadable ( )
return string

The humand readable size.

                public function getSizeReadable()
{
    return FileHelper::humanReadableFilesize($this->getSize());
}

            
getSource() public method

Get the absolute source path to the file location on the webserver.

This will return raw the path to the storage file inside the sotorage folder without readable urls.

public string getSource ( $scheme false )
$scheme boolean

Whether the source path should be absolute or not.

return string

The raw path to the file inside the storage folder.

                public function getSource($scheme = false)
{
    return $scheme ? Yii::$app->storage->fileAbsoluteHttpPath($this->getKey('name_new_compound')) : Yii::$app->storage->fileHttpPath($this->getKey('name_new_compound'));
}

            
getSourceAbsolute() public method

Path to the source with sheme includes, means including server location.

public string getSourceAbsolute ( )
return string

The absolute source url to the file inside the storage folder with nice Urls.

                public function getSourceAbsolute()
{
    return $this->getSource(true);
}

            
getSystemFileName() public method

Get the new defined storage file Name.

This is also known als name_new_compound from the admin_storage_file table. This is the original file name but without any bad letters or sign. Only a-z0-9 chars allowed.

public string getSystemFileName ( )
return string

The new file name inside the storage folder.

                public function getSystemFileName()
{
    return $this->getKey('name_new_compound');
}

            
getTarget() public method

Get the target attribute value inside the Link tag.

Can be either _blank, _self.

public string getTarget ( )
return string

Returns the target string value for the link resource.

                public function getTarget()
{
    return empty($this->_target) ? '_blank' : $this->_target;
}

            
getUploadTimestamp() public method

The Unix Timestamp when the file has been uploaded to the Server.

public integer getUploadTimestamp ( )
return integer

Unix timestamp when the file has been uploaded.

                public function getUploadTimestamp()
{
    return (int) $this->getKey('upload_timestamp');
}

            
hasMethod() public method

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

public boolean hasMethod ( $name )
$name string

The method name

return boolean

Whether the method is defined

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public method

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also:

public boolean hasProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property is defined

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() public method

Defined in: yii\base\BaseObject::init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

                public function init()
{
}

            
resolveFields() protected method

Defined in: yii\base\ArrayableTrait::resolveFields()

Determines which fields can be returned by toArray().

This method will first extract the root fields from the given fields. Then it will check the requested root fields against those declared in fields() and extraFields() to determine which fields can be returned.

protected array resolveFields ( array $fields, array $expand )
$fields array

The fields being requested for exporting

$expand array

The additional fields being requested for exporting

return array

The list of fields to be exported. The array keys are the field names, and the array values are the corresponding object property names or PHP callables returning the field values.

                protected function resolveFields(array $fields, array $expand)
{
    $fields = $this->extractRootFields($fields);
    $expand = $this->extractRootFields($expand);
    $result = [];
    foreach ($this->fields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (empty($fields) || in_array($field, $fields, true)) {
            $result[$field] = $definition;
        }
    }
    if (empty($expand)) {
        return $result;
    }
    foreach ($this->extraFields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (in_array($field, $expand, true)) {
            $result[$field] = $definition;
        }
    }
    return $result;
}

            
setCaption() public method

Set caption for file item, override existings values

public void setCaption ( $text )
$text string

The caption text for this image

                public function setCaption($text)
{
    $this->_caption = trim($text);
}

            
setItemArray() public method

Defined in: luya\admin\storage\ItemAbstract::setItemArray()

Setter method for itemArray property.

public void setItemArray ( array $item )
$item array

                public function setItemArray(array $item)
{
    $this->_itemArray = $item;
}

            
setTarget() public method

Setter method for Link target.

public void setTarget ( $target )
$target string

The target must be a valid link target attribute value.

                public function setTarget($target)
{
    $this->_target = $target;
}

            
toArray() public method

Defined in: yii\base\ArrayableTrait::toArray()

Converts the model into an array.

This method will first identify which fields to be included in the resulting array by calling resolveFields(). It will then turn the model into an array with these fields. If $recursive is true, any embedded objects will also be converted into arrays. When embedded objects are yii\base\Arrayable, their respective nested fields will be extracted and passed to toArray().

If the model implements the yii\web\Linkable interface, the resulting array will also have a _link element which refers to a list of links as specified by the interface.

public array toArray ( array $fields = [], array $expand = [], $recursive true )
$fields array

The fields being requested. If empty or if it contains '*', all fields as specified by fields() will be returned. Fields can be nested, separated with dots (.). e.g.: item.field.sub-field $recursive must be true for nested fields to be extracted. If $recursive is false, only the root fields will be extracted.

$expand array

The additional fields being requested for exporting. Only fields declared in extraFields() will be considered. Expand can also be nested, separated with dots (.). e.g.: item.expand1.expand2 $recursive must be true for nested expands to be extracted. If $recursive is false, only the root expands will be extracted.

$recursive boolean

Whether to recursively return array representation of embedded objects.

return array

The array representation of the object

                public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
    $data = [];
    foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
        $attribute = is_string($definition) ? $this->$definition : $definition($this, $field);
        if ($recursive) {
            $nestedFields = $this->extractFieldsFor($fields, $field);
            $nestedExpand = $this->extractFieldsFor($expand, $field);
            if ($attribute instanceof Arrayable) {
                $attribute = $attribute->toArray($nestedFields, $nestedExpand);
            } elseif ($attribute instanceof \JsonSerializable) {
                $attribute = $attribute->jsonSerialize();
            } elseif (is_array($attribute)) {
                $attribute = array_map(
                    function ($item) use ($nestedFields, $nestedExpand) {
                        if ($item instanceof Arrayable) {
                            return $item->toArray($nestedFields, $nestedExpand);
                        } elseif ($item instanceof \JsonSerializable) {
                            return $item->jsonSerialize();
                        }
                        return $item;
                    },
                    $attribute
                );
            }
        }
        $data[$field] = $attribute;
    }
    if ($this instanceof Linkable) {
        $data['_links'] = Link::serialize($this->getLinks());
    }
    return $recursive ? ArrayHelper::toArray($data) : $data;
}