Files and Folders

DirectoryTree Helper

The DirectoryTree class provides helper methods for rendering a directory tree as HTML.

Namespace: Medialight\Textstem\Helpers

make

Static method that creates a new instance and calls render.

public static function make(): string

Returns:

  • (string): The rendered HTML directory tree.

render

Renders the entire directory tree.

public function render(): string

Returns:

  • (string): The rendered HTML directory tree.

renderNode

Renders a single node in the tree.

public function renderNode($node): void

Parameters:

  • $node (array): The node to render.

Returns:

  • (void): This method modifies the internal tree property.

FileHelper

The FileHelper class provides helper methods for file operations.

Namespace: Medialight\Textstem\Helpers

__construct (FileHelper)

Constructor that takes a source file path.

public function __construct($src, $disk = 'public')

Parameters:

  • $src (string): The source file path.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (void)

rename

Renames a file.

public function rename($newName): string

Parameters:

  • $newName (string): The new name or path for the file.

Returns:

  • (string): The new path of the file.

copy

Copies a file.

public function copy($newName): string

Parameters:

  • $newName (string): The new name or path for the copied file.

Returns:

  • (string): The path of the copied file.

moveFile

Static method to move a file.

public static function moveFile($fileName, $newPath, $disk = 'public'): string

Parameters:

  • $fileName (string): The file to move.
  • $newPath (string): The new path for the file.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (string): The new path of the file.

copyFile

Static method to copy a file.

public static function copyFile($fileName, $newPath, $disk = 'public'): string

Parameters:

  • $fileName (string): The file to copy.
  • $newPath (string): The new path for the copied file.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (string): The path of the copied file.

duplicateFile

Static method to duplicate a file.

public static function duplicateFile($fileName, $disk = 'public'): string

Parameters:

  • $fileName (string): The file to duplicate.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (string): The path of the duplicated file, or an empty string if the original file doesn't exist.

getNewFileName

Static method to get a new file name.

public static function getNewFileName($fileName, $disk = 'public'): string

Parameters:

  • $fileName (string): The original file name.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (string): A new file name that doesn't exist in the storage.

assetTypeFromMime

Determines the asset type based on the given MIME type.

public static function assetTypeFromMime($mime): string

Parameters:

  • $mime (string): The MIME type of the asset.

Returns:

  • (string): The asset type, which can be one of the following:
    • "image" for image assets
    • "video" for video assets
    • "audio" for audio assets
    • "file" for other types of assets

FolderHelper

The FolderHelper class provides helper methods for folder operations.

Namespace: Medialight\Textstem\Helpers

__construct (FolderHelper)

Constructor that takes a source folder path.

public function __construct($src, $disk = 'public')

Parameters:

  • $src (string): The source folder path.
  • $disk (string): The storage disk to use. Default is 'public'.

Returns:

  • (void)

directoryTree

Returns a tree structure of directories.

public function directoryTree(): array

Returns:

  • (array): A tree structure of directories.

browse

Returns a list of directories and files in the source folder.

public function browse(): array

Returns:

  • (array): A list of directories and files in the source folder.

MimeType Helper

The MimeType class provides helper methods for working with MIME types.

Namespace: Medialight\Textstem\Helpers

getMimeFromExtension

Gets the MIME type for a given file extension.

public static function getMimeFromExtension($ext)

Parameters:

  • $ext (string): The file extension.

Returns:

  • (string): The MIME type for the given extension.
esc