VolumeInterface ​
- Type
- Interface
- Namespace
- craft\base
- Extends
- craft\base\SavableComponentInterface
- Implemented by
- craft\base\FlysystemVolume, craft\base\Volume, craft\volumes\Local, craft\volumes\MissingVolume, craft\volumes\Temp
- Since
- 3.0.0
VolumeInterface defines the common interface to be implemented by volume classes.
A class implementing this interface should also use craft\base\SavableComponentTrait and craft\base\VolumeTrait.
Public Methods ​
Method | Description |
---|---|
afterDelete() | Performs actions after a component is deleted. |
afterSave() | Performs actions after a component is saved. |
beforeApplyDelete() | Performs actions before a component delete is applied to the database. |
beforeDelete() | Performs actions before a component is deleted. |
beforeSave() | Performs actions before a component is saved. |
copyFile() | Copies a file. |
createDirectory() | Creates a directory. |
createFileByStream() | Creates a file. |
deleteDirectory() | Deletes a directory. |
deleteFile() | Deletes a file. |
directoryExists() | Returns whether a directory exists at the given path. |
displayName() | Returns the display name of this class. |
fileExists() | Returns whether a file exists. |
getDateModified() | Returns the last time the file was modified. |
getFieldLayout() | Returns the volume's field layout, or null if it doesn’t have one. |
getFileList() | List files. |
getFileMetadata() | Return the metadata about a file. |
getFileSize() | Returns the file size. |
getFileStream() | Gets a stream ready for reading by a file's URI. |
getIsNew() | Returns whether the component is new (unsaved). |
getRootUrl() | Returns the URL to the source, if it’s accessible via HTTP traffic. |
getSettings() | Returns an array of the component’s settings. |
getSettingsHtml() | Returns the component’s settings HTML. |
isSelectable() | Returns whether the component should be selectable in component Type selects. |
renameDirectory() | Renames a directory. |
renameFile() | Renames a file. |
saveFileLocally() | Save a file from the source's uriPath to a local target path. |
settingsAttributes() | Returns the list of settings attribute names. |
updateFileByStream() | Updates a file. |
copyFile()
​
Copies a file.
Arguments ​
$path
(string) – The path of the file, relative to the source’s root$newPath
(string) – The path of the new file, relative to the source’s root
Throws ​
- craft\errors\VolumeObjectExistsException
if a file with such a name exists already - craft\errors\VolumeObjectNotFoundException
if the file to be renamed cannot be found - craft\errors\VolumeException
if something else goes wrong
createDirectory()
​
- Since
- 3.6.0
Creates a directory.
Arguments ​
$path
(string) – The path of the directory, relative to the source’s root
Throws ​
- craft\errors\VolumeObjectExistsException
if a directory with such name already exists - craft\errors\VolumeException
if something else goes wrong
createFileByStream()
​
Creates a file.
Arguments ​
$path
(string) – The path of the file, relative to the source’s root$stream
(resource) – The stream to file$config
(array) – Additional config options to pass to the adapter
Throws ​
- craft\errors\VolumeObjectExistsException
if a file already exists at the path on the volume - craft\errors\VolumeException
if something else goes wrong
deleteDirectory()
​
- Since
- 3.6.0
Deletes a directory.
Arguments ​
$path
(string) – The path of the directory, relative to the source’s root
Throws ​
- craft\errors\VolumeException
if something goes wrong
deleteFile()
​
Deletes a file.
Arguments ​
$path
(string) – The path of the file, relative to the source’s root
Throws ​
- craft\errors\VolumeException
if something goes wrong
directoryExists()
​
Returns whether a directory exists at the given path.
Arguments ​
$path
(string) – The folder path to check
Returns ​
fileExists()
​
Returns whether a file exists.
Arguments ​
$path
(string) – The path of the file, relative to the source’s root
Returns ​
getDateModified()
​
- Since
- 3.6.0
Returns the last time the file was modified.
Arguments ​
$uri
(string)
Returns ​
Throws ​
- craft\errors\VolumeObjectNotFoundException
if the file cannot be found
getFieldLayout()
​
- Since
- 3.5.0
Returns the volume's field layout, or null
if it doesn’t have one.
Returns ​
craft\models\FieldLayout, null
getFileList()
​
List files.
Arguments ​
$directory
(string) – The path of the directory to list files of$recursive
(boolean) – Whether to fetch file list recursively
Returns ​
getFileMetadata()
​
DEPRECATED
Deprecated in Craft 3.6.0. Use getFileSize() and getDateModified() instead.
Return the metadata about a file.
Arguments ​
$uri
(string) – URI to the file on the volume
Returns ​
Throws ​
- craft\errors\VolumeObjectNotFoundException
if the file cannot be found
getFileSize()
​
- Since
- 3.6.0
Returns the file size.
Arguments ​
$uri
(string)
Returns ​
Throws ​
- craft\errors\VolumeObjectNotFoundException
if the file cannot be found
getFileStream()
​
Gets a stream ready for reading by a file's URI.
Arguments ​
$uriPath
(string)
Returns ​
Throws ​
- craft\errors\AssetException
if a stream cannot be created
getRootUrl()
​
Returns the URL to the source, if it’s accessible via HTTP traffic.
The URL should end in a /
.
Returns ​
string, false – The root URL, or false
if there isn’t one
renameDirectory()
​
- Since
- 3.6.0
Renames a directory.
Arguments ​
$path
(string) – The path of the directory, relative to the source’s root$newName
(string) – The new path of the directory, relative to the source’s root
Throws ​
- craft\errors\VolumeObjectNotFoundException
if a directory with such name already exists - craft\errors\VolumeObjectExistsException
if a directory with such name already exists - craft\errors\VolumeException
if something else goes wrong
renameFile()
​
Renames a file.
Arguments ​
$path
(string) – The old path of the file, relative to the source’s root$newPath
(string) – The new path of the file, relative to the source’s root
Throws ​
- craft\errors\VolumeObjectExistsException
if a file with such a name exists already - craft\errors\VolumeObjectNotFoundException
if the file to be renamed cannot be found - craft\errors\VolumeException
if something else goes wrong
saveFileLocally()
​
Save a file from the source's uriPath to a local target path.
Arguments ​
Returns ​
integer – Amount of bytes copied
updateFileByStream()
​
Updates a file.
Arguments ​
$path
(string) – The path of the file, relative to the source’s root$stream
(resource) – The new contents of the file as a stream$config
(array) – Additional config options to pass to the adapter
Throws ​
- craft\errors\VolumeObjectNotFoundException
if the file to be updated cannot be found - craft\errors\VolumeException
if something else goes wrong