Contents

Cms\Classes\Asset

Overview

Asset for CMS asset files

Extends

Public Properties

public string $fileName

fileName specifies the file name corresponding the CMS object

public string $mtime

Last modified time.

public string $content

The entire file content.

public bool $exists

exists indicates if the model exists.

Show inherited public properties

Inherited Public Properties

Protected Properties

protected Cms\Classes\Theme $theme

A reference to the CMS theme containing the object.

protected string $dirName

dirName for the container name inside the theme

protected string $originalFileName

Specifies the file name, the CMS object was loaded from.

protected array $fillable

fillable attributes that are mass assignable

protected array $allowedExtensions

allowedExtensions for template files

Show inherited protected properties

Inherited Protected Properties


Public Methods

public __construct()

public __construct($theme): void

__construct creates an instance of the object and associates it with a CMS theme

public createDirectory()

public createDirectory($newName, $parent): void 

createDirectory creates a directory under a parent path within the assets root.

public delete()

public delete(): void

delete the object from disk, or tombstone its database row and remove the assets disk object when the asset database layer is enabled.

public deletePaths()

public deletePaths($fileList): void 

deletePaths removes the given list of files or directories under the assets root. Directories must be empty.

public fill()

public fill(array $attributes): void

Sets the object attributes.

public find()

public find($fileName): void

find a single template by its file name, resolving against the theme's database layer and filesystem before falling back to its parent theme.

public get()

public get($options = []): array 

get all assets in a theme and uses simple objects

Available options:

  • recursive: search subfolders and place in 'assets' key
  • flatten: produce a flat array instead of a recursive array
  • filterPath: only include within an inner path
  • filterFiles: only include files
  • filterFolders: only include folders
  • filterEditable: only show editable assets

public static getEditableExtensions()

public static getEditableExtensions(): array 

getEditableExtensions returns a list of editable asset extensions The list can be overridden with the cms.editable_asset_types configuration option.

public getFileName()

public getFileName(): string 

public getFilePath()

public getFilePath($fileName = null): string 

getFilePath returns the absolute file path of an asset

public static inTheme()

public static inTheme($theme): Cms\Classes\Asset 

inTheme prepares the theme datasource for the model.

public static listInTheme()

public static listInTheme($theme, $options = []): void

public static load()

public static load(Cms\Classes\Theme $theme, string $fileName): mixed 

load the object from a file This method is used in the CMS back-end. It doesn't use any caching.

public move()

public move($selectedList, $destinationDir): void 

move relocates a list of files or directories into a destination directory under the assets root.

public rename()

public rename($newName, $originalPath): void 

rename renames a single file or directory within the assets root.

public save()

public save(): void

save the object to the disk, or to the assets disk with database row tracking when the asset database layer is enabled.

public upload()

public upload($uploadedFile, $destinationDir): void 

upload accepts a single uploaded file into a destination directory under the theme's assets root. SVG content is sanitised before being written.

public validate()

public validate(): void

validate object

Show inherited public methods

Inherited Public Methods

Protected Methods

protected assertNoDatabaseCollision()

protected assertNoDatabaseCollision(
    $source,
    $basePath,
    $newPath,
    $name = null
): void 

assertNoDatabaseCollision throws when the target path is already occupied by an active row or an unsuppressed filesystem file.

protected assertNotRenamingToVector()

protected assertNotRenamingToVector(
    $newName,
    $originalPath,
    $allowedExtensions
): void 

assertNotRenamingToVector blocks renaming a non-svg file to svg, since only uploads pass through the vector sanitizer.

protected deletePathsWithDatabase()

protected deletePathsWithDatabase($fileList): void 

deletePathsWithDatabase deletes against the database layer, removing assets disk objects and tombstoning rows.

protected findInTheme()

protected findInTheme($theme, $fileName): void

findInTheme resolves an asset against a single theme, checking its database layer first and falling back to its filesystem copy.

protected findSourceFile()

protected findSourceFile($theme, $fileName): Cms\Models\SourceFile|null 

findSourceFile returns an active SourceFile row for the given theme and filename, or null if none exists.

protected fireInvalidationEvent()

protected fireInvalidationEvent($diskPaths): void 

fireInvalidationEvent notifies listeners that asset bytes changed on the assets disk so CDN caches can be purged.

protected getDiskName()

protected getDiskName(): string 

getDiskName returns the Storage disk name used for published assets.

protected getDiskPath()

protected getDiskPath($theme, $fileName): string 

getDiskPath returns the assets disk key for a theme asset, mirroring the repo-relative path so it matches the public URL built by asset().

protected getInternal()

protected getInternal($path, $theme): array 

getInternal helps the get method. When the theme has the asset database layer enabled, results are merged with active SourceFile rows scoped to the listed directory level and any filesystem entries whose paths are tombstoned in the database are suppressed.

protected getOperationBasePath()

protected getOperationBasePath(): string 

getOperationBasePath returns the absolute path to the theme's assets directory, used as the root for all operations.

protected getOperationExtensions()

protected getOperationExtensions(): array 

getOperationExtensions returns allowed extensions for upload/rename operations. Includes all asset types defined in the asset definitions, with preprocessor types removed when safe mode is enabled.

protected getRelativePath()

protected getRelativePath($path, $theme): string 

getRelativePath returns path relative to the theme asset directory

protected getSourceIdentifier()

protected getSourceIdentifier($theme): string 

getSourceIdentifier returns the SourceFile source identifier for the given theme's assets. Format: theme.{themeDir}.asset

protected hydrateFromSourceFile()

protected hydrateFromSourceFile($fileName, $row): static 

hydrateFromSourceFile populates this instance from a SourceFile row, using the row's updated_at as the mtime so concurrent-edit detection compares like for like.

protected isTombstoned()

protected isTombstoned($theme, $fileName): bool 

isTombstoned returns true if a soft-deleted SourceFile row exists for the given theme and filename, meaning the file should be reported as not existing even when the filesystem still has a copy.

protected listTransferablePathsUnderPrefix()

protected listTransferablePathsUnderPrefix($prefix): array 

listTransferablePathsUnderPrefix returns the union of active row paths and unsuppressed filesystem file paths beneath a directory prefix.

protected moveWithDatabase()

protected moveWithDatabase($selectedList, $destinationDir): void 

moveWithDatabase relocates files and directories against the database layer and the assets disk, re-keying directory contents the same way as renameWithDatabase.

protected normalizeOperationPath()

protected normalizeOperationPath($path): string 

normalizeOperationPath produces the canonical relative path used as the SourceFile path key, matching the normalization in Asset::getInternal().

protected renameWithDatabase()

protected renameWithDatabase($newName, $originalPath): void 

renameWithDatabase performs a rename against the database layer and the assets disk. Directory renames re-key every file beneath the prefix so shipped assets keep working at their new URLs across all instances, leaving the local filesystem untouched.

protected saveToDatabase()

protected saveToDatabase(): void 

saveToDatabase writes the current content to the assets disk and upserts a disk-backed SourceFile row for this theme and filename

protected transferPathWithDatabase()

protected transferPathWithDatabase(
    $oldPath,
    $newPath,
    &$invalidatePaths
): void 

transferPathWithDatabase re-keys a single file from one path to another: bytes land at the new disk key, the old row is tombstoned and its disk object removed. Inline rows (directory placeholders) stay inline and touch no disk objects.

protected validateFileName()

protected validateFileName(string $fileName = null): void

validateFileName supplied with extension and path.

protected validateOperationFileExtension()

protected validateOperationFileExtension($name, $allowedExtensions): bool 

validateOperationFileExtension checks a filename against the allowed extension list.

protected validateOperationName()

protected validateOperationName($name): bool 

validateOperationName ensures a single file or directory name contains only safe characters.

protected validateOperationPath()

protected validateOperationPath($path): bool 

validateOperationPath ensures a relative path does not escape the assets root or contain unsafe characters.

Show inherited protected methods

Inherited Protected Methods