Media
extends AbstractMedia
in package
Class Media
Table of Contents
Properties
- $audios : array<string|int, mixed>
- $files : array<string|int, mixed>
- $global : GlobalMedia
- $images : array<string|int, mixed>
- $items : array<string|int, mixed>
- $media_order : array<string|int, mixed>|null
- $path : string|null
- $standard_exif : array<string|int, mixed>
- $videos : array<string|int, mixed>
- $_upload_defaults : array<string|int, mixed>
Methods
- __construct() : mixed
- __invoke() : mixed
- Call object as function to get medium by filename.
- __wakeup() : mixed
- Initialize static variables on unserialize.
- 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
- getPath() : string|null
- Return media path.
- getRawRoute() : string|null
- Return raw route to the page.
- getRoute() : string|null
- Return page route.
- 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
- path() : string|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.
- 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
- init() : void
- Initialize class.
- orderMedia() : array<string|int, mixed>
- Order the media based on the page's media_order
- translate() : string
Properties
$audios
protected
array<string|int, mixed>
$audios
= []
$files
protected
array<string|int, mixed>
$files
= []
$global
protected
static GlobalMedia
$global
$images
protected
array<string|int, mixed>
$images
= []
$items
protected
array<string|int, mixed>
$items
= []
$media_order
protected
array<string|int, mixed>|null
$media_order
$path
protected
string|null
$path
$standard_exif
protected
array<string|int, mixed>
$standard_exif
= ['FileSize', 'MimeType', 'height', 'width']
$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
__construct()
public
__construct(string $path[, array<string|int, mixed>|null $media_order = null ][, bool $load = true ]) : mixed
Parameters
- $path : string
- $media_order : array<string|int, mixed>|null = null
- $load : bool = true
__invoke()
Call object as function to get medium by filename.
public
__invoke(string $filename) : mixed
Parameters
- $filename : string
Attributes
- #[ReturnTypeWillChange]
__wakeup()
Initialize static variables on unserialize.
public
__wakeup() : mixed
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
ImageFilegetPath()
Return media path.
public
getPath() : string|null
Return values
string|nullgetRawRoute()
Return raw route to the page.
public
getRawRoute() : string|null
Return values
string|null —Route to the page or null if media isn't for a page.
getRoute()
Return page route.
public
getRoute() : string|null
Return values
string|null —Route to the page or null if media isn't for a page.
getUploadSettings()
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|nullpath()
public
path() : string|null
Use $this->getPath() instead.
Return values
string|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>clearCache()
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
Languageinit()
Initialize class.
protected
init() : void
orderMedia()
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>translate()
protected
translate(string $string) : string
Parameters
- $string : string