MediaWiki master
MediaWiki\Settings\Source\FileSource Class Reference

Settings loaded from a local file path. More...

Inherits MediaWiki\Settings\Cache\CacheableSource, and MediaWiki\Settings\Source\SettingsIncludeLocator.

Collaboration diagram for MediaWiki\Settings\Source\FileSource:

Public Member Functions

 __construct (string $path, SettingsFormat $format=null)
 Constructs a new FileSource for the given path and possibly a custom format to decode the contents.
 
 __toString ()
 Returns this file source as a string.
 
 allowsStaleLoad ()
 Disallow stale results from file sources in the case of load failure as failing to read from disk would be quite catastrophic and worthy of propagation.
 
 getExpiryTtl ()
 The cache expiry TTL (in seconds) for this file source.
 
 getExpiryWeight ()
 Coefficient used in determining early expiration of cached settings to avoid stampedes.
 
 getHashKey ()
 Returns a hash key computed from the file's inode, size, and last modified timestamp.
 
 load ()
 Loads contents from the file and decodes them using the first format to claim support for the file's extension.
 
 locateInclude (string $location)
 This method defines how a relative reference to the location of another settings source is interpreted.
 

Detailed Description

Settings loaded from a local file path.

Since
1.38

Definition at line 18 of file FileSource.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Settings\Source\FileSource::__construct ( string $path,
SettingsFormat $format = null )

Constructs a new FileSource for the given path and possibly a custom format to decode the contents.

If no format is given, the built-in formats will be tried and the first one that supports the file extension will be used.

Built-in formats:

  • JsonFormat
  • YamlFormat

<?php $source = new FileSource( 'my/settings.json' ); $source->load();

While a specialized caller may want to pass a specialized format

<?php $source = new FileSource( 'my/settings.toml', new TomlFormat() ); $source->load();

Parameters
string$path
SettingsFormat | null$format

Definition at line 87 of file FileSource.php.

References $path.

Member Function Documentation

◆ __toString()

MediaWiki\Settings\Source\FileSource::__toString ( )

Returns this file source as a string.

Returns
string

Definition at line 176 of file FileSource.php.

◆ allowsStaleLoad()

MediaWiki\Settings\Source\FileSource::allowsStaleLoad ( )

Disallow stale results from file sources in the case of load failure as failing to read from disk would be quite catastrophic and worthy of propagation.

Returns
bool

Implements MediaWiki\Settings\Cache\CacheableSource.

Definition at line 99 of file FileSource.php.

◆ getExpiryTtl()

MediaWiki\Settings\Source\FileSource::getExpiryTtl ( )

The cache expiry TTL (in seconds) for this file source.

Returns
int

Implements MediaWiki\Settings\Cache\CacheableSource.

Definition at line 138 of file FileSource.php.

◆ getExpiryWeight()

MediaWiki\Settings\Source\FileSource::getExpiryWeight ( )

Coefficient used in determining early expiration of cached settings to avoid stampedes.

Returns
float

Implements MediaWiki\Settings\Cache\CacheableSource.

Definition at line 148 of file FileSource.php.

◆ getHashKey()

MediaWiki\Settings\Source\FileSource::getHashKey ( )

Returns a hash key computed from the file's inode, size, and last modified timestamp.

Returns
string

Implements MediaWiki\Settings\Cache\CacheableSource.

Definition at line 158 of file FileSource.php.

◆ load()

MediaWiki\Settings\Source\FileSource::load ( )

Loads contents from the file and decodes them using the first format to claim support for the file's extension.

Exceptions
SettingsBuilderException
Returns
array

Implements MediaWiki\Settings\Source\SettingsSource.

Definition at line 110 of file FileSource.php.

◆ locateInclude()

MediaWiki\Settings\Source\FileSource::locateInclude ( string $location)

This method defines how a relative reference to the location of another settings source is interpreted.

It tries to make $location absolute by interpreting it as relative to the location of the SettingsSource it originates from.

Implementation are "best effort". If a location cannot be made absolute, it may be returned as-is. Implementations are also free to throw a SettingsBuilderException to indicate that the given include location is not supported in this context.

Parameters
string$location
Returns
string
Exceptions
SettingsBuilderExceptionif the given location cannot be used as an include by the current source.

Implements MediaWiki\Settings\Source\SettingsIncludeLocator.

Definition at line 225 of file FileSource.php.


The documentation for this class was generated from the following file: