FsInterface
- Type
- Interface
- Namespace
- craft\base
- Extends
- craft\base\SavableComponentInterface
- Implemented by
- craft\base\Fs, craft\fs\Local, craft\fs\MissingFs, craft\fs\Temp
- Since
- 4.0.0
FieldInterface defines the common interface to be implemented by filesystem classes.
A class implementing this interface should also use craft\base\SavableComponentTrait and craft\base\FsTrait.
View source (opens new window)
# 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. |
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. |
extraFields() (opens new window) | Returns the list of additional fields that can be returned by toArray() (opens new window) in addition to those listed in fields() (opens new window). |
fields() (opens new window) | Returns the list of fields that should be returned by default by toArray() (opens new window) when no specific fields are specified. |
fileExists() | Returns whether a file exists. |
getDateModified() | Returns the last time the file was modified. |
getFileList() | List files. |
getFileSize() | Return the file size. |
getFileStream() | Gets a stream ready for reading by a file's URI. |
getIsNew() | Returns whether the component is new (unsaved). |
getSettings() | Returns an array of the component’s settings. |
getSettingsHtml() | Returns the component’s settings HTML. |
instance() (opens new window) | Returns static class instance, which can be used to obtain meta information. |
isSelectable() | Returns whether the component should be selectable in component Type selects. |
read() | Reads contents of a file to a string. |
renameDirectory() | Renames a directory. |
renameFile() | Renames a file. |
settingsAttributes() | Returns the list of settings attribute names. |
toArray() (opens new window) | Converts the object into an array. |
write() | Writes a string to a file. |
writeFileFromStream() | Writes a file to a fs from a given stream. |
# copyFile()
Copies a file.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file, relative to the source’s root$newPath
(string (opens new window)) – The path of the new file, relative to the source’s root
Throws
# createDirectory()
Creates a directory.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the directory, relative to the source’s root$config
(array (opens new window)) – The config to use
Throws
# deleteDirectory()
Deletes a directory.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the directory, relative to the source’s root
Throws
# deleteFile()
Deletes a file.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file, relative to the source’s root
# directoryExists()
Returns whether a directory exists at the given path.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The directory path to check
Returns
Throws
# fileExists()
Returns whether a file exists.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file, relative to the source’s root
Returns
Throws
# getDateModified()
Returns the last time the file was modified.
View source (opens new window)
Arguments
$uri
(string (opens new window))
Returns
Throws
# getFileList()
List files.
View source (opens new window)
Arguments
$directory
(string (opens new window)) – The path of the directory to list files of$recursive
(boolean (opens new window)) – Whether to fetch file list recursively, defaults to true
Returns
Throws
# getFileSize()
Return the file size.
View source (opens new window)
Arguments
$uri
(string (opens new window))
Returns
Throws
# getFileStream()
Gets a stream ready for reading by a file's URI.
View source (opens new window)
Arguments
$uriPath
(string (opens new window))
Returns
Throws
- craft\errors\FsException
if a stream cannot be created
# read()
Reads contents of a file to a string.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file
Returns
# renameDirectory()
Renames a directory.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the directory, relative to the source’s root$newName
(string (opens new window)) – The new path of the directory, relative to the source’s root
Throws
- craft\errors\FsObjectNotFoundException
if directory cannot be found
# renameFile()
Renames a file.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The old path of the file, relative to the source’s root$newPath
(string (opens new window)) – The new path of the file, relative to the source’s root
Throws
# write()
Writes a string to a file.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file$contents
(string (opens new window)) – The file contents to write$config
(array (opens new window)) – Additional config options to pass on
Throws
# writeFileFromStream()
Writes a file to a fs from a given stream.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The path of the file, relative to the source’s root$stream
(resource (opens new window)) – The new contents of the file as a stream$config
(array (opens new window)) – Additional config options to pass on