GlobalMedia
extends AbstractMedia
in package
Class GlobalMedia
Table of Contents
Properties
- $audios : array<string|int, mixed>
- $files : array<string|int, mixed>
- $images : array<string|int, mixed>
- $instance : self
- $items : array<string|int, mixed>
- $media_order : array<string|int, mixed>|null
- $path : string|null
- $videos : array<string|int, mixed>
- $_upload_defaults : array<string|int, mixed>
Methods
- __invoke() : mixed
- Call object as function to get medium by filename.
- add() : void
- all() : array<string|int, MediaObjectInterface>
- Get a list of all media.
- audios() : array<string|int, MediaObjectInterface>
- Get a list of all audio media.
- checkFileMetadata() : string
- Checks that file metadata meets the requirements. Returns new filename.
- checkUploadedFile() : string
- Checks that uploaded file meets the requirements. Returns new filename.
- copyUploadedFile() : void
- Copy uploaded file to the media collection.
- createFromArray() : Medium|null
- Create Medium from array of parameters
- createFromFile() : Medium|null
- Create Medium from a file.
- createFromUploadedFile() : Medium|null
- Create Medium from an uploaded file.
- deleteFile() : void
- Delete real file from the media collection.
- files() : array<string|int, MediaObjectInterface>
- Get a list of all file media.
- get() : MediaObjectInterface|null
- Get medium by filename.
- getImageFileObject() : ImageFile
- getInstance() : self
- getPath() : string|null
- Return media path.
- getUploadSettings() : array<string|int, mixed>
- Get upload settings.
- hide() : void
- images() : array<string|int, MediaObjectInterface>
- Get a list of all image media.
- offsetExists() : bool
- offsetGet() : MediaObjectInterface|null
- renameFile() : void
- Rename file inside the media collection.
- setPath() : void
- setTimestamps() : $this
- Set file modification timestamps (query params) for all the media files.
- videos() : array<string|int, MediaObjectInterface>
- Get a list of all video media.
- addMedium() : MediaObjectInterface|null
- clearCache() : void
- doAddUploadedMedium() : void
- doCopy() : void
- Internal logic to copy file.
- doMoveUploadedFile() : void
- Internal logic to move uploaded file.
- doRemove() : void
- Internal logic to remove file.
- doRemoveMetadata() : void
- doRename() : void
- Internal logic to rename file.
- doSanitizeSvg() : void
- doSaveMetadata() : void
- fileExists() : bool
- getConfig() : Config
- getFileParts() : array<string|int, mixed>
- Get filename, extension and meta part.
- getGrav() : Grav
- getLanguage() : Language
- orderMedia() : array<string|int, mixed>
- Order the media based on the page's media_order
- resolveStream() : string|null
- translate() : string
Properties
$audios
protected
array<string|int, mixed>
$audios
= []
$files
protected
array<string|int, mixed>
$files
= []
$images
protected
array<string|int, mixed>
$images
= []
$instance
protected
static self
$instance
$items
protected
array<string|int, mixed>
$items
= []
$media_order
protected
array<string|int, mixed>|null
$media_order
$path
protected
string|null
$path
$videos
protected
array<string|int, mixed>
$videos
= []
$_upload_defaults
private
array<string|int, mixed>
$_upload_defaults
= [
'self' => true,
// Whether path is in the media collection path itself.
'avoid_overwriting' => false,
// Do not override existing files (adds datetime postfix if conflict).
'random_name' => false,
// True if name needs to be randomized.
'accept' => ['image/*'],
// Accepted mime types or file extensions.
'limit' => 10,
// Maximum number of files.
'filesize' => null,
// Maximum filesize in MB.
'destination' => null,
]
Methods
__invoke()
Call object as function to get medium by filename.
public
__invoke(string $filename) : mixed
Parameters
- $filename : string
Attributes
- #[ReturnTypeWillChange]
add()
public
add(string $name, MediaObjectInterface|null $file) : void
Parameters
- $name : string
- $file : MediaObjectInterface|null
all()
Get a list of all media.
public
all() : array<string|int, MediaObjectInterface>
Return values
array<string|int, MediaObjectInterface>audios()
Get a list of all audio media.
public
audios() : array<string|int, MediaObjectInterface>
Return values
array<string|int, MediaObjectInterface>checkFileMetadata()
Checks that file metadata meets the requirements. Returns new filename.
public
checkFileMetadata(array<string|int, mixed> $metadata[, string $filename = null ][, array<string|int, mixed>|null $settings = null ]) : string
Parameters
- $metadata : array<string|int, mixed>
- $filename : string = null
- $settings : array<string|int, mixed>|null = null
Tags
Return values
stringcheckUploadedFile()
Checks that uploaded file meets the requirements. Returns new filename.
public
checkUploadedFile(UploadedFileInterface $uploadedFile[, string|null $filename = null ][, array<string|int, mixed>|null $settings = null ]) : string
Parameters
- $uploadedFile : UploadedFileInterface
- $filename : string|null = null
- $settings : array<string|int, mixed>|null = null
Tags
Return values
stringcopyUploadedFile()
Copy uploaded file to the media collection.
public
copyUploadedFile(UploadedFileInterface $uploadedFile, string $filename[, array<string|int, mixed>|null $settings = null ]) : void
WARNING: Always check uploaded file before copying it!
Parameters
- $uploadedFile : UploadedFileInterface
- $filename : string
- $settings : array<string|int, mixed>|null = null
Tags
createFromArray()
Create Medium from array of parameters
public
createFromArray([array<string|int, mixed> $items = [] ][, Blueprint|null $blueprint = null ]) : Medium|null
Parameters
- $items : array<string|int, mixed> = []
- $blueprint : Blueprint|null = null
Return values
Medium|nullcreateFromFile()
Create Medium from a file.
public
createFromFile(string $file[, array<string|int, mixed> $params = [] ]) : Medium|null
Parameters
- $file : string
- $params : array<string|int, mixed> = []
Return values
Medium|nullcreateFromUploadedFile()
Create Medium from an uploaded file.
public
createFromUploadedFile(UploadedFileInterface $uploadedFile[, array<string|int, mixed> $params = [] ]) : Medium|null
Parameters
- $uploadedFile : UploadedFileInterface
- $params : array<string|int, mixed> = []
Return values
Medium|nulldeleteFile()
Delete real file from the media collection.
public
deleteFile(string $filename[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
- $filename : string
- $settings : array<string|int, mixed>|null = null
Tags
files()
Get a list of all file media.
public
files() : array<string|int, MediaObjectInterface>
Return values
array<string|int, MediaObjectInterface>get()
Get medium by filename.
public
get(string $filename) : MediaObjectInterface|null
Parameters
- $filename : string
Return values
MediaObjectInterface|nullgetImageFileObject()
public
getImageFileObject(MediaObjectInterface $mediaObject) : ImageFile
Parameters
- $mediaObject : MediaObjectInterface
Return values
ImageFilegetInstance()
public
static getInstance() : self
Return values
selfgetPath()
Return media path.
public
getPath() : string|null
Return values
string|nullgetUploadSettings()
Get upload settings.
public
getUploadSettings([array<string|int, mixed>|null $settings = null ]) : array<string|int, mixed>
Parameters
- $settings : array<string|int, mixed>|null = null
-
Form field specific settings (override).
Return values
array<string|int, mixed>hide()
public
hide(string $name) : void
Parameters
- $name : string
images()
Get a list of all image media.
public
images() : array<string|int, MediaObjectInterface>
Return values
array<string|int, MediaObjectInterface>offsetExists()
public
offsetExists(string $offset) : bool
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
booloffsetGet()
public
offsetGet(string $offset) : MediaObjectInterface|null
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
MediaObjectInterface|nullrenameFile()
Rename file inside the media collection.
public
renameFile(string $from, string $to[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
- $from : string
- $to : string
- $settings : array<string|int, mixed>|null = null
setPath()
public
setPath(string|null $path) : void
Parameters
- $path : string|null
setTimestamps()
Set file modification timestamps (query params) for all the media files.
public
setTimestamps([string|int|null $timestamp = null ]) : $this
Parameters
- $timestamp : string|int|null = null
Return values
$thisvideos()
Get a list of all video media.
public
videos() : array<string|int, MediaObjectInterface>
Return values
array<string|int, MediaObjectInterface>addMedium()
protected
addMedium(string $stream) : MediaObjectInterface|null
Parameters
- $stream : string
Return values
MediaObjectInterface|nullclearCache()
protected
clearCache() : void
doAddUploadedMedium()
protected
doAddUploadedMedium(string $name, string $filename, string $path) : void
Parameters
- $name : string
- $filename : string
- $path : string
doCopy()
Internal logic to copy file.
protected
doCopy(string $src, string $dst, string $path) : void
Parameters
- $src : string
- $dst : string
- $path : string
doMoveUploadedFile()
Internal logic to move uploaded file.
protected
doMoveUploadedFile(UploadedFileInterface $uploadedFile, string $filename, string $path) : void
Parameters
- $uploadedFile : UploadedFileInterface
- $filename : string
- $path : string
doRemove()
Internal logic to remove file.
protected
doRemove(string $filename, string $path) : void
Parameters
- $filename : string
- $path : string
doRemoveMetadata()
protected
doRemoveMetadata(string $filename, string $path) : void
Parameters
- $filename : string
- $path : string
doRename()
Internal logic to rename file.
protected
doRename(string $from, string $to, string $path) : void
Parameters
- $from : string
- $to : string
- $path : string
doSanitizeSvg()
protected
doSanitizeSvg(string $filename, string $path) : void
Parameters
- $filename : string
- $path : string
doSaveMetadata()
protected
doSaveMetadata(array<string|int, mixed> $metadata, string $filename, string $path) : void
Parameters
- $metadata : array<string|int, mixed>
- $filename : string
- $path : string
fileExists()
protected
fileExists(string $filename, string $destination) : bool
Parameters
- $filename : string
- $destination : string
Return values
boolgetConfig()
protected
getConfig() : Config
Return values
ConfiggetFileParts()
Get filename, extension and meta part.
protected
getFileParts(string $filename) : array<string|int, mixed>
Parameters
- $filename : string
Return values
array<string|int, mixed>getGrav()
protected
getGrav() : Grav
Return values
GravgetLanguage()
protected
getLanguage() : Language
Return values
LanguageorderMedia()
Order the media based on the page's media_order
protected
orderMedia(array<string|int, mixed> $media) : array<string|int, mixed>
Parameters
- $media : array<string|int, mixed>
Return values
array<string|int, mixed>resolveStream()
protected
resolveStream(string $filename) : string|null
Parameters
- $filename : string
Return values
string|nulltranslate()
protected
translate(string $string) : string
Parameters
- $string : string