Documentation

File extends DataType
in package
implements Complex uses Log

Class File

Represents a file as a value object. This class handles file-related operations such as resolving paths, checking readability, and computing relative paths.

Table of Contents

Interfaces

Complex
A ValueObject that has a complex Value such as Date or Money which cannot be represented directly as a string and is thus returned from a DomainObject as is

Properties

$readable  : bool
$realPath  : string
$relativePath  : string
$directory  : string
$value  : mixed

Methods

__construct()  : mixed
The constructor is normally called from the DomainObject when instatiated.
__get()  : mixed
Magic getter to retrieve file properties.
__toString()  : string
Make sure to overwrite this method in the implementations
defaultValidators()  : array<string|int, mixed>
Overwrite this message if a DataType needs validation methods that are always applied
equals()  : mixed
Compares the internal value with the $compare argument
ifExists()  : callable
in()  : void
Stores the provided value as an SPLFileInfo object.
isComplex()  : bool
Indicates if the object represents a complex type.
isReadable()  : bool
Checks if the file is readable.
length()  : callable
maxLength()  : callable
minLength()  : callable
notBlank()  : callable
NotBlank
notNull()  : callable
NotNull
oneOf()  : callable
out()  : string
Retrieves the basename of the file without any directory components
required()  : callable
unique()  : callable
not implemented - remove?
value()  : mixed
Returns the internal value

Properties

$readable read-only

public bool $readable

Indicates whether the file is readable.

$realPath read-only

public string $realPath

The absolute real path of the file.

$relativePath read-only

public string $relativePath

The relative path of the file from the document root directory.

$directory

protected string $directory = 'file'

The default directory for file storage.

$value

protected mixed $value

The internal value of the DataType

Methods

__construct()

The constructor is normally called from the DomainObject when instatiated.

public __construct([mixde $value = null ]) : mixed
Parameters
$value : mixde = null

__get()

Magic getter to retrieve file properties.

public __get(string $name) : mixed
Parameters
$name : string

The name of the property.

__toString()

Make sure to overwrite this method in the implementations

public __toString() : string
Return values
string

The string representation of the DataType

defaultValidators()

Overwrite this message if a DataType needs validation methods that are always applied

public static defaultValidators() : array<string|int, mixed>
Return values
array<string|int, mixed>

equals()

Compares the internal value with the $compare argument

public equals(DataType|mixed $compare) : mixed

Remember that you get a DomainObject when using the DomainObjects values, thus comparison can have undesired results, use the equals method to compare ValueObjects
This has to be overwritten in the descendants to get the desired comparison behaviour

Parameters
$compare : DataType|mixed

The value to be compared

ifExists()

public static ifExists(callable $test) : callable
Parameters
$test : callable
Return values
callable

Returns a predicate that tests a value using $test if it exists.

in()

Stores the provided value as an SPLFileInfo object.

public in(string $value) : void

This method takes the given path, resolves it relative to the defined directory, and stores it as an SPLFileInfo instance.

Parameters
$value : string

The relative path to the file.

isComplex()

Indicates if the object represents a complex type.

public isComplex() : bool
Return values
bool

Always returns true for this class.

isReadable()

Checks if the file is readable.

public isReadable() : bool
Return values
bool

True if the file is readable, false otherwise.

length()

public static length(int $n) : callable
Parameters
$n : int
Return values
callable

Returns a predicate that tests if its argument is of length $n.

maxLength()

public static maxLength(int $n) : callable
Parameters
$n : int
Return values
callable

Returns a predicate that tests if its argument is of length $n or less.

minLength()

public static minLength(int $n) : callable
Parameters
$n : int
Return values
callable

Returns a predicate that tests if its argument is of length $n or greater.

notBlank()

NotBlank

public static notBlank() : callable
Return values
callable

notNull()

NotNull

public static notNull() : callable
Return values
callable

oneOf()

public static oneOf(mixed $lst) : callable
Parameters
$lst : mixed
Return values
callable

Returns a predicate that test if it's argument is one of several elements.

out()

Retrieves the basename of the file without any directory components

public out() : string
Return values
string

The basename of the file.

required()

public static required() : callable
Return values
callable

Returns a predicate that tests for the existence of it's argument.

unique()

not implemented - remove?

public static unique() : callable
Return values
callable

Returns a predicate that tests if it's argument is unique in it's environment.

value()

Returns the internal value

public value() : mixed

        
On this page

Search results