Attention needed

Saeghe is a difficult name to pronounce. Therefore, Saeghe project has been renamed to phpkg.

This website no longer receives updates.

Please visit phpkg website at phpkg.com

Introduction

The Filename class extends Datatype Text class. You can use it to keep any filename as a string. It also gives you access to an API that you can see in the following.

Note For more information on the Text class, please read its documentation

Usage

You can pass the filename to the constructor:

use Saeghe\FileManager\Filesystem\Filename;

$filename = new Filename('filename');
echo $filename; // Output: 'filename'
echo $filename->string(); // Output: 'filename'

$filename = new Filename('.filename');
echo $filename; // Output: '.filename'
echo $filename->string(); // Output: '.filename'

Methods

Here you can see a list of the available methods on the filename:


directory

It returns a Directory object by appending the filename to the given root directory.

public function directory(Directory $root): Directory

Example

$filename = new Filename('subdirectory');
$result = $filename->directory(Directory::from_string('/home/user'));

assert_true($result instanceof Directory);
assert_true('/home/user/subdirectory' === $result->path->string());

file

It returns a File object by appending the filename to the given root directory.

public function file(Directory $root): File

Example

$filename = new Filename('filename');
$result = $filename->file(Directory::from_string('/home/user'));

assert_true($result instanceof File);
assert_true('/home/user/filename' === $result->path->string());

symlink

It returns a Symlink object by appending the filename to the given root directory.

public function symlink(Directory $root): Symlink

Example

$filename = new Filename('symlink');
$result = $filename->symlink(Directory::from_string('/home/user'));

assert_true($result instanceof Symlink);
assert_true('/home/user/symlink' === $result->path->string());