File

Defines some file-system helpers for the CMS system.

 class Cms\Helpers\File

Methods

public static validateExtension (string $fileName, array $allowedExtensions, boolean $allowEmpty = true) : bool

Validates whether a file has an allowed extension.

Parameters
Property Description
$fileName
string

Specifies a path to validate

$allowedExtensions
array

A list of allowed file extensions

$allowEmpty
boolean

Determines whether the file extension could be empty.

Returns
bool

Returns true if the file extension is valid. Otherwise returns false.

public static validateName (string $fileName) : bool

Validates a CMS object file or directory name.

CMS object file names can contain only alphanumeric symbols, dashes, underscores and dots. Name can also begin with a component name, eg: MyComponent::filename.

Parameters
Property Description
$fileName
string

Specifies a path to validate

Returns
bool

Returns true if the file name is valid. Otherwise returns false.

public static validatePath (string $filePath, integer $maxNesting = 2) : bool

Validates a CMS object path.

CMS object directory and file names can contain only alphanumeric symbols, dashes and dots. CMS objects support only a single level of subdirectories.

Parameters
Property Description
$filePath
string

Specifies a path to validate

$maxNesting
integer

Specifies the maximum allowed nesting level

Returns
bool

Returns true if the file name is valid. Otherwise returns false.

Copyright © 2024 Winter CMS