eZPublishCommunityProject  2013.4
eZ\Publish\Core\Base\Configuration Class Reference

Configuration instance class. More...

Public Member Functions

 __construct ($moduleName, array $paths, array $globalConfiguration)
 Create instance of Configuration. More...
 
 get ($section, $key, $fallBackValue=null)
 Gets a configuration value, or $fallBackValue if undefined Triggers warning if key is not set and $fallBackValue is null. More...
 
 getAll ()
 Gets all section and configuration value. More...
 
 getDirs ($scope=null)
 Get raw instance override path list data. More...
 
 getSection ($section, $fallBackValue=null)
 Gets a configuration values for a section or $fallBackValue if undefined Triggers warning if section is not set and $fallBackValue is null. More...
 
 has ($section, $key=null)
 Checks if a configuration section and optionally key is set. More...
 
 hasValue ($section, $key)
 Checks if a configuration section & key is set and has a value. More...
 
 load ($hasCache=null, $useCache=null)
 Loads the configuration from cache or from source (if $useCache is false or there is no cache) More...
 
 reload ()
 Reload cache data conditionally if path hash has changed on current instance. More...
 
 set ($section, $key, $value=null)
 Gets a configuration value, or null if not set. More...
 

Public Attributes

const CONFIG_CACHE_DIR = 'var/cache/ini/'
 
const CONFIG_CACHE_REV = 3
 
const TEMP_INI_UNSET_VAR = '__UNSET__'
 

Protected Member Functions

 createCacheName ($configurationPathsHash)
 Create cache name. More...
 
 generateRawData ($configurationPathsHash, array $configurationData, array $sourceFiles=array(), array $sourcePaths=array())
 Generate raw data for use in cache. More...
 
 hasCache ($cacheName)
 Check if cache file exists. More...
 
 parse (array $configurationPaths, array &$sourceFiles)
 Parse configuration files. More...
 
 pathsHash ()
 Get cache hash based on override dirs. More...
 
 readCache ($cacheName)
 Loads cache file, use hasCache() to make sure it exists first! More...
 
 recursiveArrayClearing (array $iniArray, &$configurationPiece)
 Recursively clear array values. More...
 
 setGlobalConfig (array $globalSettings, array &$conf)
 Recursively set global configuration. More...
 
 storeCache ($cacheName, array $rawData)
 Store cache file, overwrites any existing file. More...
 

Protected Attributes

 $dirPermission = 0755
 
 $filePermission = 0644
 
 $globalConfiguration
 
 $moduleName = null
 
 $raw = null
 

Private Attributes

 $paths = array()
 
 $pathsHash = ''
 

Detailed Description

Configuration instance class.

A configuration class with override setting support that uses parsers to deal with files so you can support ini/yaml/xml/json given it is defined when setting up the class.

By default values are cached to a raw php files and files are not read again unless development mode is on and some file has been removed or modified since cache was created.

When generating cache files.

Constructor & Destructor Documentation

eZ\Publish\Core\Base\Configuration::__construct (   $moduleName,
array  $paths,
array  $globalConfiguration 
)

Create instance of Configuration.

Parameters
string$moduleNameThe name of the module (and in case of ini files, same as ini filename w/o suffix)
array$pathsPaths to look for settings in.
array$globalConfigurationGlobal settings for module

Member Function Documentation

eZ\Publish\Core\Base\Configuration::createCacheName (   $configurationPathsHash)
protected

Create cache name.

Parameters
string$configurationPathsHash
Returns
string

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::generateRawData (   $configurationPathsHash,
array  $configurationData,
array  $sourceFiles = array(),
array  $sourcePaths = array() 
)
protected

Generate raw data for use in cache.

Parameters
string$configurationPathsHash
array$configurationData
array$sourceFilesOptional, stored in cache to be able to check modified time in future devMode
array$sourcePathsOptional, stored in cache to be able to debug it more easily
Returns
array

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::get (   $section,
  $key,
  $fallBackValue = null 
)

Gets a configuration value, or $fallBackValue if undefined Triggers warning if key is not set and $fallBackValue is null.

Parameters
string$sectionThe configuration section to get value for
string$keyThe configuration key to get value for
mixed$fallBackValuevalue to return if setting is undefined.
Returns
mixed|null (null if key is undefined and no $fallBackValue is provided)
eZ\Publish\Core\Base\Configuration::getAll ( )

Gets all section and configuration value.

Returns
array
eZ\Publish\Core\Base\Configuration::getDirs (   $scope = null)

Get raw instance override path list data.

Exceptions
InvalidArgumentValueIf scope has wrong value
Parameters
string$scopeSee $globalPaths for scope values (first level keys)
Returns
array

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::getSection (   $section,
  $fallBackValue = null 
)

Gets a configuration values for a section or $fallBackValue if undefined Triggers warning if section is not set and $fallBackValue is null.

Parameters
string$sectionThe configuration section to get value for
mixed$fallBackValuevalue to return if section is undefined.
Returns
array|null (null if key is undefined and no $fallBackValue is provided)
eZ\Publish\Core\Base\Configuration::has (   $section,
  $key = null 
)

Checks if a configuration section and optionally key is set.

Parameters
string$section
string$keyOptional, only checks if section exists if null
Returns
boolean Return true if setting exist
eZ\Publish\Core\Base\Configuration::hasCache (   $cacheName)
protected

Check if cache file exists.

Parameters
string$cacheNameAs generated by createCacheName()
Returns
boolean

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::hasValue (   $section,
  $key 
)

Checks if a configuration section & key is set and has a value.

(ie. a check using !empty())

Parameters
string$section
string$key
Returns
boolean Return true if setting exist and has value
eZ\Publish\Core\Base\Configuration::load (   $hasCache = null,
  $useCache = null 
)

Loads the configuration from cache or from source (if $useCache is false or there is no cache)

Parameters
boolean | null$hasCacheLets you specify if there is a cache file, will check if null and $useCache is true
boolean$useCacheWill skip using cached config files (slow), when null depends on [ini]-cache setting

Referenced by eZ\Publish\Core\Base\Configuration\reload().

eZ\Publish\Core\Base\Configuration::parse ( array  $configurationPaths,
array &  $sourceFiles 
)
protected

Parse configuration files.

Uses configured parsers to do the file parsing pr file, and then merges the result from them and:

  • Handles array clearing
  • Handles section extends ( "Section:Base" extends "Base" )
Parameters
array$configurationPaths
array$sourceFilesByRef value or source files that has been/is going to be parsed files you pass in will not be checked if they exists.
Exceptions
\eZ\Publish\Core\Base\Exceptions\BadConfigurationIf no parser have been defined
Returns
array Data structure for parsed ini files

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::pathsHash ( )
protected

Get cache hash based on override dirs.

Returns
string md5 hash

Referenced by eZ\Publish\Core\Base\Configuration\load(), and eZ\Publish\Core\Base\Configuration\reload().

eZ\Publish\Core\Base\Configuration::readCache (   $cacheName)
protected

Loads cache file, use hasCache() to make sure it exists first!

Parameters
string$cacheNameAs generated by createCacheName()
Returns
array|null

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::recursiveArrayClearing ( array  $iniArray,
$configurationPiece 
)
protected

Recursively clear array values.

Parameters
array$iniArray
array | null$configurationPiece

Referenced by eZ\Publish\Core\Base\Configuration\parse().

eZ\Publish\Core\Base\Configuration::reload ( )

Reload cache data conditionally if path hash has changed on current instance.

eZ\Publish\Core\Base\Configuration::set (   $section,
  $key,
  $value = null 
)

Gets a configuration value, or null if not set.

Parameters
string$sectionThe configuration section to get value for
string$keyThe configuration key to get value for
mixed$valuevalue to return if setting is not defined.
Returns
boolean Return true if section existed and was overwritten
eZ\Publish\Core\Base\Configuration::setGlobalConfig ( array  $globalSettings,
array &  $conf 
)
protected

Recursively set global configuration.

Parameters
array$globalSettings
array$conf

Referenced by eZ\Publish\Core\Base\Configuration\load().

eZ\Publish\Core\Base\Configuration::storeCache (   $cacheName,
array  $rawData 
)
protected

Store cache file, overwrites any existing file.

Parameters
string$cacheNameAs generated by createCacheName()
array$rawDataAs generated by generateRawData()

Referenced by eZ\Publish\Core\Base\Configuration\load().

Member Data Documentation

eZ\Publish\Core\Base\Configuration::$dirPermission = 0755
protected
eZ\Publish\Core\Base\Configuration::$filePermission = 0644
protected
eZ\Publish\Core\Base\Configuration::$globalConfiguration
protected
eZ\Publish\Core\Base\Configuration::$moduleName = null
protected
eZ\Publish\Core\Base\Configuration::$paths = array()
private
eZ\Publish\Core\Base\Configuration::$pathsHash = ''
private
eZ\Publish\Core\Base\Configuration::$raw = null
protected
const eZ\Publish\Core\Base\Configuration::CONFIG_CACHE_DIR = 'var/cache/ini/'
const eZ\Publish\Core\Base\Configuration::CONFIG_CACHE_REV = 3
const eZ\Publish\Core\Base\Configuration::TEMP_INI_UNSET_VAR = '__UNSET__'

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