Documentation

Filesystem implements FilesystemInterface

Class Filesystem

Table of Contents

Interfaces

FilesystemInterface
Defines several stream-save filesystem actions.

Properties

$default  : static|null
$safe  : static|null
$unsafe  : static|null
$normalize  : bool|null

Methods

basename()  : string
Unicode-safe and stream-safe `\basename()` replacement.
dirname()  : string
Unicode-safe and stream-safe `\dirname()` replacement.
getInstance()  : Filesystem
getNormalization()  : bool|null
normalize()  : string
Normalize path by cleaning up `\`, `/./`, `//` and `/../`.
parent()  : string
Get parent path. Empty path is returned if there are no segments remaining.
pathinfo()  : array<string|int, mixed>|string
Unicode-safe and stream-safe `\pathinfo()` replacement.
pathname()  : string
Gets full path with trailing slash.
safe()  : self
Force all paths not to be normalized (speeds up the calls if given paths are known to be normalized).
setNormalization()  : Filesystem
Set path normalization.
unsafe()  : self
Force all paths to be normalized.
dirnameInternal()  : array<string|int, mixed>
getSchemeAndHierarchy()  : array<string|int, mixed>
Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> array(file, tmp)).
normalizePathPart()  : string
pathinfoInternal()  : array<string|int, mixed>|string
toString()  : string

Properties

Methods

basename()

Unicode-safe and stream-safe `\basename()` replacement.

public basename(string $path[, string|null $suffix = null ]) : string
Parameters
$path : string

A filename or path, does not need to exist as a file.

$suffix : string|null = null

If the filename ends in suffix this will also be cut off.

Tags
see
FilesystemInterface::basename()
Return values
string

dirname()

Unicode-safe and stream-safe `\dirname()` replacement.

public dirname(string $path[, int $levels = 1 ]) : string
Parameters
$path : string

A filename or path, does not need to exist as a file.

$levels : int = 1

The number of parent directories to go up (>= 1).

Tags
see
FilesystemInterface::dirname()
Return values
string

Returns path to the directory.

getInstance()

public static getInstance([bool|null $normalize = null ]) : Filesystem
Parameters
$normalize : bool|null = null

See $this->setNormalization()

Return values
Filesystem

getNormalization()

public getNormalization() : bool|null
Return values
bool|null

normalize()

Normalize path by cleaning up `\`, `/./`, `//` and `/../`.

public normalize(string $path) : string
Parameters
$path : string

A filename or path, does not need to exist as a file.

Tags
see
FilesystemInterface::normalize()
Return values
string

Returns normalized path.

parent()

Get parent path. Empty path is returned if there are no segments remaining.

public parent(string $path[, int $levels = 1 ]) : string
Parameters
$path : string

A filename or path, does not need to exist as a file.

$levels : int = 1

The number of parent directories to go up (>= 1).

Tags
see
FilesystemInterface::parent()
Return values
string

Returns parent path.

pathinfo()

Unicode-safe and stream-safe `\pathinfo()` replacement.

public pathinfo(string $path[, int|null $options = null ]) : array<string|int, mixed>|string
Parameters
$path : string

A filename or path, does not need to exist as a file.

$options : int|null = null

A PATHINFO_* constant.

Tags
see
FilesystemInterface::pathinfo()
Return values
array<string|int, mixed>|string

pathname()

Gets full path with trailing slash.

public pathname(string $path[, int $levels = 1 ]) : string
Parameters
$path : string
$levels : int = 1
Tags
phpstan-param

positive-int $levels

Return values
string

safe()

Force all paths not to be normalized (speeds up the calls if given paths are known to be normalized).

public safe() : self
Return values
self

setNormalization()

Set path normalization.

public setNormalization([bool|null $normalize = null ]) : Filesystem

Default option enables normalization for the streams only, but you can force the normalization to be either on or off for every path. Disabling path normalization speeds up the calls, but may cause issues if paths were not normalized.

Parameters
$normalize : bool|null = null
Return values
Filesystem

unsafe()

Force all paths to be normalized.

public unsafe() : self
Return values
self

dirnameInternal()

protected dirnameInternal(string|null $scheme, string $path[, int $levels = 1 ]) : array<string|int, mixed>
Parameters
$scheme : string|null
$path : string
$levels : int = 1
Tags
phpstan-param

positive-int $levels

Return values
array<string|int, mixed>

getSchemeAndHierarchy()

Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> array(file, tmp)).

protected getSchemeAndHierarchy(string $filename) : array<string|int, mixed>
Parameters
$filename : string
Return values
array<string|int, mixed>

normalizePathPart()

protected normalizePathPart(string $path) : string
Parameters
$path : string
Tags
throws
RuntimeException
Return values
string

pathinfoInternal()

protected pathinfoInternal(string|null $scheme, string $path[, int|null $options = null ]) : array<string|int, mixed>|string
Parameters
$scheme : string|null
$path : string
$options : int|null = null
Return values
array<string|int, mixed>|string

toString()

protected toString(string|null $scheme, string $path) : string
Parameters
$scheme : string|null
$path : string
Return values
string

        
On this page

Search results