abstract class FileDriver implements MappingDriver (View source)

Base driver for file-based metadata drivers.

A file driver operates in a mode where it loads the mapping files of individual classes on demand. This requires the user to adhere to the convention of 1 mapping file per class and the file names of the mapping files must correspond to the full class name, including namespace, with the namespace delimiters '\', replaced by dots '.'.

Properties

protected FileLocator $locator
protected ClassMetadata[]|null $classCache
protected string|null $globalBasename

Methods

__construct(string|string[]|FileLocator $locator, string|null $fileExtension = null)

Initializes a new FileDriver that looks in the given path(s) for mapping documents and operates in the specified operating mode.

void
setGlobalBasename(string $file)

Sets the global basename.

string|null
getGlobalBasename()

Retrieves the global basename.

getElement(string $className)

Gets the element of schema meta data for the class from the mapping file.

bool
isTransient(string $className)

Returns whether the class with the specified name should have its metadata loaded.

string[]
getAllClassNames()

Gets the names of all mapped classes known to this driver.

loadMappingFile(string $file)

Loads a mapping file with the given name and returns a map from class/entity names to their corresponding file driver elements.

void
initialize()

Initializes the class cache from all the global files.

getLocator()

Retrieves the locator used to discover mapping files by className.

setLocator(FileLocator $locator)

Sets the locator used to discover mapping files by className.

Details

__construct(string|string[]|FileLocator $locator, string|null $fileExtension = null)

Initializes a new FileDriver that looks in the given path(s) for mapping documents and operates in the specified operating mode.

Parameters

string|string[]|FileLocator $locator A FileLocator or one/multiple paths where mapping documents can be found.
string|null $fileExtension

void setGlobalBasename(string $file)

Sets the global basename.

Parameters

string $file

Return Value

void

string|null getGlobalBasename()

Retrieves the global basename.

Return Value

string|null

ClassMetadata getElement(string $className)

Gets the element of schema meta data for the class from the mapping file.

This will lazily load the mapping file if it is not loaded yet.

Parameters

string $className

Return Value

ClassMetadata The element of schema meta data.

Exceptions

MappingException

bool isTransient(string $className)

Returns whether the class with the specified name should have its metadata loaded.

This is only the case if it is either mapped as an Entity or a MappedSuperclass.

Parameters

string $className

Return Value

bool

string[] getAllClassNames()

Gets the names of all mapped classes known to this driver.

Return Value

string[] The names of all mapped classes known to this driver.

abstract protected ClassMetadata[] loadMappingFile(string $file)

Loads a mapping file with the given name and returns a map from class/entity names to their corresponding file driver elements.

Parameters

string $file The mapping file to load.

Return Value

ClassMetadata[]

protected void initialize()

Initializes the class cache from all the global files.

Using this feature adds a substantial performance hit to file drivers as more metadata has to be loaded into memory than might actually be necessary. This may not be relevant to scenarios where caching of metadata is in place, however hits very hard in scenarios where no caching is used.

Return Value

void

FileLocator getLocator()

Retrieves the locator used to discover mapping files by className.

Return Value

FileLocator

setLocator(FileLocator $locator)

Sets the locator used to discover mapping files by className.

Parameters

FileLocator $locator