class YamlDirectoryDiscovery implements DiscoverableInterface (View source)

Discovers multiple YAML files in a set of directories.

Constants

FILE_KEY

Defines the key in the discovered data where the file path is stored.

Properties

protected array $directories

An array of directories to scan, keyed by the provider.

protected string $fileCacheKeySuffix

The suffix for the file cache key.

protected string $idKey

The key contained in the discovered data that identifies it.

Methods

__construct(array $directories, string $file_cache_key_suffix, string $key = 'id')

Constructs a YamlDirectoryDiscovery object.

array
findAll()

Returns an array of discoverable items.

string
getIdentifier(string $file, array $data)

Gets the identifier from the data.

array
findFiles()

Returns an array of providers keyed by file path.

getDirectoryIterator(string $directory)

Gets an iterator to loop over the files in the provided directory.

Details

__construct(array $directories, string $file_cache_key_suffix, string $key = 'id')

Constructs a YamlDirectoryDiscovery object.

Parameters

array $directories

An array of directories to scan, keyed by the provider. The value can either be a string or an array of strings. The string values should be the path of a directory to scan.

string $file_cache_key_suffix

The file cache key suffix. This should be unique for each type of discovery.

string $key

(optional) The key contained in the discovered data that identifies it. Defaults to 'id'.

array findAll()

Returns an array of discoverable items.

Return Value

array

An array of discovered data keyed by provider.

Exceptions

DiscoveryException

protected string getIdentifier(string $file, array $data)

Gets the identifier from the data.

Parameters

string $file

The filename.

array $data

The data from the YAML file.

Return Value

string

The identifier from the data.

protected array findFiles()

Returns an array of providers keyed by file path.

Return Value

array

An array of providers keyed by file path.

protected Traversable getDirectoryIterator(string $directory)

Gets an iterator to loop over the files in the provided directory.

This method exists so that it is easy to replace this functionality in a class that extends this one. For example, it could be used to make the scan recursive.

Parameters

string $directory

The directory to scan.

Return Value

Traversable

An \Traversable object or array where the values are \SplFileInfo objects.