Config
Configuration class. This class is used to manage the configuration of the application. It allows to import, export, validate and access configuration data. It also provides methods to handle paths, languages, themes, and cache.
Table of Contents
Constants
- IMPORT_MERGE = 2
- IMPORT_PRESERVE = 0
- IMPORT_REPLACE = 1
- LANG_CODE_PATTERN = '([a-z]{2}(-[A-Z]{2})?)'
- LANG_LOCALE_PATTERN = '[a-z]{2}(_[A-Z]{2})?(_[A-Z]{2})?'
- IMPORT_PRESERVE = 0
Properties
- $data : Data
- Configuration is a Data object.
- $default : Data
- Default configuration.
- $destinationDir : string|null
- Destination directory.
- $languages : array<string|int, mixed>|null
- Languages list as array.
- $sourceDir : string|null
- Source directory.
Methods
- __construct() : mixed
- Build the Config object with the default config + the optional given array.
- export() : array<string|int, mixed>
- Get configuration as an array.
- get() : mixed|null
- Get the value of a configuration's key.
- getAssetsImagesSizes() : array<string|int, mixed>
- Returns asset image sizes.
- getAssetsImagesWidths() : array<string|int, mixed>
- Returns asset image widths.
- getAssetsPath() : string
- Returns the path of assets files directory.
- getAssetsRemotePath() : string
- Returns the path of remote assets files directory (in cache).
- getCacheAssetsPath() : string
- Returns cache path of assets.
- getCachePath() : string
- Returns cache path.
- getCacheTemplatesPath() : string
- Returns cache path of templates.
- getCacheTranslationsPath() : string
- Returns cache path of translations.
- getDataPath() : string
- Returns the path of the data directory.
- getDestinationDir() : string
- Get the destination directory.
- getLanguageDefault() : string
- Returns the default language code (ie: "en", "fr-FR", etc.).
- getLanguageIndex() : int
- Returns a language code index.
- getLanguageProperty() : string
- Returns the property value of a (specified or the default) language.
- getLanguages() : array<string|int, mixed>
- Returns an array of available languages.
- getLayoutSection() : string|null
- Returns the layout for a section.
- getLayoutsInternalPath() : string
- Returns the path of internal templates directory.
- getLayoutsPath() : string
- Returns the path of templates directory.
- getOutputFormatProperty() : string|array<string|int, mixed>|null
- Returns the property value of an output format.
- getOutputPath() : string
- Returns the path of the output directory.
- getPagesPath() : string
- Returns the path of the pages directory.
- getSourceDir() : string
- Get the source directory.
- getStaticPath() : string
- Returns the path of static files directory.
- getTheme() : array<string|int, mixed>|null
- Returns theme(s) as an array.
- getThemeDirPath() : string
- Returns the path of a specific theme's directory.
- getThemesPath() : string
- Returns the path of themes directory.
- getTranslationsInternalPath() : string
- Returns the path of internal translations directory.
- getTranslationsPath() : string
- Returns the path of translations directory.
- has() : bool
- Is configuration's key exists?
- hasTheme() : bool
- Has a (valid) theme(s)?
- import() : void
- Imports (and validate) configuration.
- isCacheDirIsAbsolute() : bool
- Is cache dir is absolute to system files or relative to project destination?
- isEnabled() : bool
- Is an option is enabled? Checks if the key is set to `false` or if subkey `enabled` is set to `false`.
- loadFile() : array<string|int, mixed>
- Loads and parse a YAML file.
- setDestinationDir() : self
- Set the destination directory.
- setSourceDir() : self
- Set the source directory.
- castSetValue() : bool|mixed
- Casts boolean value given to set() as string.
- setFromEnv() : void
- Set configuration from environment variables starting with "CECIL_".
- validate() : void
- Validate the configuration.
Constants
IMPORT_MERGE
public
mixed
IMPORT_MERGE
= 2
IMPORT_PRESERVE
public
mixed
IMPORT_PRESERVE
= 0
IMPORT_REPLACE
public
mixed
IMPORT_REPLACE
= 1
LANG_CODE_PATTERN
public
mixed
LANG_CODE_PATTERN
= '([a-z]{2}(-[A-Z]{2})?)'
LANG_LOCALE_PATTERN
public
mixed
LANG_LOCALE_PATTERN
= '[a-z]{2}(_[A-Z]{2})?(_[A-Z]{2})?'
Properties
$data
Configuration is a Data object.
protected
Data
$data
This allows to use dot notation to access configuration keys. For example: $config->get('key.subkey') or $config->has('key.subkey').
$default
Default configuration.
protected
Data
$default
$destinationDir
Destination directory.
protected
string|null
$destinationDir
= null
This is the directory where the output files will be generated. It is used to resolve relative paths in the configuration. If not set, it defaults to the source directory.
$languages
Languages list as array.
protected
array<string|int, mixed>|null
$languages
= null
This is used to store the languages defined in the configuration. It is initialized to null and will be populated when the languages are requested.
Tags
$sourceDir
Source directory.
protected
string|null
$sourceDir
= null
This is the directory where the source files are located. It is used to resolve relative paths in the configuration. If not set, it defaults to the current working directory.
Methods
__construct()
Build the Config object with the default config + the optional given array.
public
__construct([array<string|int, mixed>|null $config = null ]) : mixed
Parameters
- $config : array<string|int, mixed>|null = null
export()
Get configuration as an array.
public
export() : array<string|int, mixed>
Return values
array<string|int, mixed>get()
Get the value of a configuration's key.
public
get(string $key[, string $language = null ][, bool $fallback = true ]) : mixed|null
Parameters
- $key : string
-
Configuration key
- $language : string = null
-
Language code (optional)
- $fallback : bool = true
-
Set to false to not return the value in the default language as fallback
Return values
mixed|nullgetAssetsImagesSizes()
Returns asset image sizes.
public
getAssetsImagesSizes() : array<string|int, mixed>
Return values
array<string|int, mixed>getAssetsImagesWidths()
Returns asset image widths.
public
getAssetsImagesWidths() : array<string|int, mixed>
Return values
array<string|int, mixed>getAssetsPath()
Returns the path of assets files directory.
public
getAssetsPath() : string
Return values
stringgetAssetsRemotePath()
Returns the path of remote assets files directory (in cache).
public
getAssetsRemotePath() : string
Return values
stringgetCacheAssetsPath()
Returns cache path of assets.
public
getCacheAssetsPath() : string
Return values
stringgetCachePath()
Returns cache path.
public
getCachePath() : string
Tags
Return values
stringgetCacheTemplatesPath()
Returns cache path of templates.
public
getCacheTemplatesPath() : string
Return values
stringgetCacheTranslationsPath()
Returns cache path of translations.
public
getCacheTranslationsPath() : string
Return values
stringgetDataPath()
Returns the path of the data directory.
public
getDataPath() : string
Return values
stringgetDestinationDir()
Get the destination directory.
public
getDestinationDir() : string
Return values
stringgetLanguageDefault()
Returns the default language code (ie: "en", "fr-FR", etc.).
public
getLanguageDefault() : string
Tags
Return values
stringgetLanguageIndex()
Returns a language code index.
public
getLanguageIndex(string $code) : int
Parameters
- $code : string
Tags
Return values
intgetLanguageProperty()
Returns the property value of a (specified or the default) language.
public
getLanguageProperty(string $property[, string|null $code = null ]) : string
Parameters
- $property : string
- $code : string|null = null
Tags
Return values
stringgetLanguages()
Returns an array of available languages.
public
getLanguages() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getLayoutSection()
Returns the layout for a section.
public
getLayoutSection(string|null $section) : string|null
Parameters
- $section : string|null
Return values
string|nullgetLayoutsInternalPath()
Returns the path of internal templates directory.
public
getLayoutsInternalPath() : string
Return values
stringgetLayoutsPath()
Returns the path of templates directory.
public
getLayoutsPath() : string
Return values
stringgetOutputFormatProperty()
Returns the property value of an output format.
public
getOutputFormatProperty(string $name, string $property) : string|array<string|int, mixed>|null
Parameters
- $name : string
- $property : string
Tags
Return values
string|array<string|int, mixed>|nullgetOutputPath()
Returns the path of the output directory.
public
getOutputPath() : string
Return values
stringgetPagesPath()
Returns the path of the pages directory.
public
getPagesPath() : string
Return values
stringgetSourceDir()
Get the source directory.
public
getSourceDir() : string
Return values
stringgetStaticPath()
Returns the path of static files directory.
public
getStaticPath() : string
Return values
stringgetTheme()
Returns theme(s) as an array.
public
getTheme() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetThemeDirPath()
Returns the path of a specific theme's directory.
public
getThemeDirPath(string $theme[, string $dir = 'layouts' ]) : string
("layouts" by default).
Parameters
- $theme : string
- $dir : string = 'layouts'
Return values
stringgetThemesPath()
Returns the path of themes directory.
public
getThemesPath() : string
Return values
stringgetTranslationsInternalPath()
Returns the path of internal translations directory.
public
getTranslationsInternalPath() : string
Return values
stringgetTranslationsPath()
Returns the path of translations directory.
public
getTranslationsPath() : string
Return values
stringhas()
Is configuration's key exists?
public
has(string $key[, string $language = null ][, bool $fallback = true ]) : bool
Parameters
- $key : string
-
Configuration key
- $language : string = null
-
Language code (optional)
- $fallback : bool = true
-
Set to false to not return the value in the default language as fallback
Return values
boolhasTheme()
Has a (valid) theme(s)?
public
hasTheme() : bool
Tags
Return values
boolimport()
Imports (and validate) configuration.
public
import(array<string|int, mixed> $config[, int $mode = self::IMPORT_MERGE ]) : void
The mode can be:
- Config::IMPORT_PRESERVE: preserves existing configuration and adds new keys.
- Config::IMPORT_REPLACE: replaces existing configuration with new keys.
- Config::IMPORT_MERGE: merges existing configuration with new keys, overriding existing keys.
Parameters
- $config : array<string|int, mixed>
-
Configuration array to import
- $mode : int = self::IMPORT_MERGE
-
Import mode (default: Config::IMPORT_MERGE)
isCacheDirIsAbsolute()
Is cache dir is absolute to system files or relative to project destination?
public
isCacheDirIsAbsolute() : bool
Return values
boolisEnabled()
Is an option is enabled? Checks if the key is set to `false` or if subkey `enabled` is set to `false`.
public
isEnabled(string $key[, string|null $language = null ][, bool $fallback = true ]) : bool
Parameters
- $key : string
- $language : string|null = null
- $fallback : bool = true
Return values
boolloadFile()
Loads and parse a YAML file.
public
static loadFile(string $file[, bool $ignore = false ]) : array<string|int, mixed>
Parameters
- $file : string
- $ignore : bool = false
Return values
array<string|int, mixed>setDestinationDir()
Set the destination directory.
public
setDestinationDir(string $destinationDir) : self
Parameters
- $destinationDir : string
Tags
Return values
selfsetSourceDir()
Set the source directory.
public
setSourceDir(string $sourceDir) : self
Parameters
- $sourceDir : string
Tags
Return values
selfcastSetValue()
Casts boolean value given to set() as string.
private
castSetValue(mixed $value) : bool|mixed
Parameters
- $value : mixed
Return values
bool|mixedsetFromEnv()
Set configuration from environment variables starting with "CECIL_".
private
setFromEnv() : void
validate()
Validate the configuration.
private
validate() : void