MediaLibrary

Provides abstraction level for the Media Library operations.

 class Cms\Classes\MediaLibrary
extends System\Classes\MediaLibrary

Implements the library caching features and security checks.

Extends

Class Description
MediaLibrary

Provides abstraction level for the Media Library operations.

Traits

Trait Description
Singleton

Singleton trait.

Constants

Constant Description
SORT_BY_MODIFIED
string "modified"
SORT_BY_SIZE
string "size"
SORT_BY_TITLE
string "title"
SORT_DIRECTION_ASC
string "asc"
SORT_DIRECTION_DESC
string "desc"

Properties

inherited protected $cacheKey : string

Inherited from MediaLibrary

Cache key

inherited protected $ignoreNames : array

Inherited from MediaLibrary

Contains a list of files and directories to ignore. The list can be customized with cms.storage.media.ignore configuration option.

inherited protected $ignorePatterns : array

Inherited from MediaLibrary

Contains a list of regex patterns to ignore in files and directories. The list can be customized with cms.storage.media.ignorePatterns configuration option.

inherited protected $storageDisk : mixed

Inherited from MediaLibrary

A reference to the Media Library disk.

inherited protected $storageFolder : string

Inherited from MediaLibrary

The root Library folder path.

inherited protected $storageFolderNameLength : int

Inherited from MediaLibrary

Cache for the storage folder name length.

inherited protected $storagePath : string

Inherited from MediaLibrary

Relative or absolute URL of the Library root folder.

Methods

protected init ()

Initialize this singleton.

Returns
mixed

inherited public __clone ()

Inherited from MediaLibrary
Returns
mixed

inherited public __wakeup ()

Inherited from MediaLibrary
Returns
mixed

inherited public copyFolder (string $originalPath, string $newPath) : bool

Inherited from MediaLibrary

Copies a folder.

Parameters
Property Description
$originalPath
string

Specifies the original path of the folder.

$newPath
string

Specifies the new path of the folder.

Returns
bool

inherited public deleteFiles (array $paths)

Inherited from MediaLibrary

Deletes a file from the Library.

Parameters
Property Description
$paths
array

A list of file paths relative to the Library root to delete.

Returns
mixed

inherited public deleteFolder (string $path)

Inherited from MediaLibrary

Deletes a folder from the Library.

Parameters
Property Description
$path
string

Specifies the folder path relative to the Library root.

Returns
mixed

inherited public exists (string $path) : bool

Inherited from MediaLibrary

Determines if a file with the specified path exists in the library.

Parameters
Property Description
$path
string

Specifies the file path relative the the Library root.

Returns
bool

Returns TRUE if the file exists.

inherited public findFiles (string $searchTerm, string $sortBy = "title", string $filter = null) : array

Inherited from MediaLibrary

Finds files in the Library.

Parameters
Property Description
$searchTerm
string

Specifies the search term.

$sortBy
string

Determines the sorting preference. Supported values are 'title', 'size', 'lastModified' (see SORT_BY_XXX class constants), FALSE (to disable sorting), or an associative array with a 'by' key and a 'direction' key: ['by' => SORT_BY_XXX, 'direction' => SORT_DIRECTION_XXX].

$filter
string

Determines the document type filtering preference. Supported values are 'image', 'video', 'audio', 'document' (see FILE_TYPE_XXX constants of MediaLibraryItem class).

Returns
array

Returns an array of MediaLibraryItem objects.

inherited public folderExists (string $path) : bool

Inherited from MediaLibrary

Determines if a folder with the specified path exists in the library.

Parameters
Property Description
$path
string

Specifies the folder path relative the the Library root.

Returns
bool

Returns TRUE if the folder exists.

inherited public static final forgetInstance ($container = null) : void

Inherited from MediaLibrary

Forget this singleton's instance if it exists

Parameters
Property Description
$container
mixed
Returns
void

inherited public get (string $path) : string

Inherited from MediaLibrary

Returns a file contents.

Parameters
Property Description
$path
string

Specifies the file path relative the the Library root.

Returns
string

Returns the file contents

inherited public getCacheKey () : string

Inherited from MediaLibrary

Get the cache key

Returns
string

The cache key to set as the cache key for this instance

inherited public getMediaPath (string $path) : string

Inherited from MediaLibrary

Returns a file or folder path with the prefixed storage folder.

Parameters
Property Description
$path
string

Specifies a path to process.

Returns
string

Returns a processed string.

inherited public getPathUrl (string $path) : string

Inherited from MediaLibrary

Returns a public file URL.

Parameters
Property Description
$path
string

Specifies the file path relative the the Library root.

Returns
string

inherited public getStorageDisk () : Illuminate\Filesystem\FilesystemAdapter

Inherited from MediaLibrary

Initializes and returns the Media Library disk.

This method should always be used instead of trying to access the $storageDisk property directly as initializing the disc requires communicating with the remote storage.

Returns
Illuminate\Filesystem\FilesystemAdapter

Returns the storage disk object.

inherited public static final instance ($container = null) : static

Inherited from MediaLibrary

Create a new instance of this singleton.

Parameters
Property Description
$container
mixed
Returns
static

inherited public listAllDirectories (array $exclude = []) : array

Inherited from MediaLibrary

Returns a list of all directories in the Library, optionally excluding some of them.

Parameters
Property Description
$exclude
array

A list of folders to exclude from the result list. The folder paths should be specified relative to the Library root.

Returns
array

inherited public listFolderContents (string $folder = "\/", string $sortBy = "title", string $filter = null, boolean $ignoreFolders = false) : array

Inherited from MediaLibrary

Returns a list of folders and files in a Library folder.

Parameters
Property Description
$folder
string

Specifies the folder path relative the the Library root.

$sortBy
string

Determines the sorting preference. Supported values are 'title', 'size', 'lastModified' (see SORT_BY_XXX class constants), FALSE (to disable sorting), or an associative array with a 'by' key and a 'direction' key: ['by' => SORT_BY_XXX, 'direction' => SORT_DIRECTION_XXX].

$filter
string

Determines the document type filtering preference. Supported values are 'image', 'video', 'audio', 'document' (see FILE_TYPE_XXX constants of MediaLibraryItem class).

$ignoreFolders
boolean

Determines whether folders should be suppressed in the result list.

Returns
array

Returns an array of MediaLibraryItem objects.

inherited public makeFolder (string $path) : bool

Inherited from MediaLibrary

Creates a folder.

Parameters
Property Description
$path
string

Specifies the folder path.

Returns
bool

inherited public moveFile (string $oldPath, string $newPath, boolean $isRename = false) : bool

Inherited from MediaLibrary

Moves a file to another location.

Parameters
Property Description
$oldPath
string

Specifies the original path of the file.

$newPath
string

Specifies the new path of the file.

$isRename
boolean
Returns
bool

inherited public moveFolder (string $originalPath, string $newPath) : bool

Inherited from MediaLibrary

Moves a folder.

Parameters
Property Description
$originalPath
string

Specifies the original path of the folder.

$newPath
string

Specifies the new path of the folder.

Returns
bool

inherited public put (string $path, string $contents) : bool

Inherited from MediaLibrary

Puts a file to the library.

Parameters
Property Description
$path
string

Specifies the file path relative the the Library root.

$contents
string

Specifies the file contents.

Returns
bool

inherited public resetCache ()

Inherited from MediaLibrary

Resets the Library cache.

The cache stores the library table of contents locally in order to optimize the performance when working with remote storages. The default cache TTL is 10 minutes. The cache is deleted automatically when an item is added, changed or deleted. This method allows to reset the cache forcibly.

Returns
mixed

inherited public setCacheKey (string $cacheKey)

Inherited from MediaLibrary

Set the cache key

Parameters
Property Description
$cacheKey
string

The key to set as the cache key for this instance

Returns
mixed

inherited public static url (string $file) : string

Inherited from MediaLibrary

Helper that makes a URL for a media file.

Parameters
Property Description
$file
string
Returns
string

inherited public static validatePath (string $path, boolean $normalizeOnly = false) : string

Inherited from MediaLibrary

Checks if file path doesn't contain any substrings that would pose a security threat.

Throws an exception if the path is not valid.

Parameters
Property Description
$path
string

Specifies the path.

$normalizeOnly
boolean

Specifies if only the normalization, without validation should be performed.

Returns
string

Returns a normalized path.

inherited protected final __construct ()

Inherited from MediaLibrary

Constructor.

Returns
mixed

inherited protected filterItemList (array $itemList, string $filter)

Inherited from MediaLibrary

Filters item list by file type.

Parameters
Property Description
$itemList
array

Specifies the item list to sort.

$filter
string

Determines the document type filtering preference. Supported values are 'image', 'video', 'audio', 'document' (see FILE_TYPE_XXX constants of MediaLibraryItem class).

Returns
mixed

inherited protected generateRandomTmpFolderName ($location)

Inherited from MediaLibrary
Parameters
Property Description
$location
mixed
Returns
mixed

inherited protected getFolderItemCount (string $path) : int

Inherited from MediaLibrary

Returns a number of items on a folder.

Parameters
Property Description
$path
string

Specifies the folder path relative to the storage disk root.

Returns
int

Returns the number of items in the folder.

inherited protected getMediaRelativePath (string $path) : string

Inherited from MediaLibrary

Returns path relative to the Library root folder.

Parameters
Property Description
$path
string

Specifies a path relative to the Library disk root.

Returns
string

Returns the updated path.

inherited protected initLibraryItem (array $item, string $itemType) : mixed

Inherited from MediaLibrary

Initializes a library item from file metadata and item type.

Parameters
Property Description
$item
array

Specifies the file metadata as returned by the storage adapter.

$itemType
string

Specifies the item type.

Returns
mixed

Returns the MediaLibraryItem object or NULL if the item is not visible.

inherited protected isVisible (string $path) : bool

Inherited from MediaLibrary

Determines if the path should be visible (not ignored).

Parameters
Property Description
$path
string

Specifies a path to check.

Returns
bool

Returns TRUE if the path is visible.

inherited protected pathMatchesSearch (string $path, array $words) : bool

Inherited from MediaLibrary

Determines if file path contains all words form the search term.

Parameters
Property Description
$path
string

Specifies a path to examine.

$words
array

A list of words to check against.

Returns
bool

inherited protected scanFolderContents (string $fullFolderPath) : array

Inherited from MediaLibrary

Fetches the contents of a folder from the Library.

Parameters
Property Description
$fullFolderPath
string

Specifies the folder path relative the the storage disk root.

Returns
array

Returns an array containing two elements - 'files' and 'folders', each is an array of MediaLibraryItem objects.

inherited protected sortItemList (array $itemList, mixed $sortSettings)

Inherited from MediaLibrary

Sorts the item list by title, size or last modified date.

Parameters
Property Description
$itemList
array

Specifies the item list to sort.

$sortSettings
mixed

Determines the sorting preference. Supported values are 'title', 'size', 'lastModified' (see SORT_BY_XXX class constants) or an associative array with a 'by' key and a 'direction' key: ['by' => SORT_BY_XXX, 'direction' => SORT_DIRECTION_XXX].

Returns
mixed
Copyright © 2024 Winter CMS