ConfigTrait

trait atk4\core\ConfigTrait
This trait makes it possible for you to read config files and various configurations
use:
1. use Trait in your APP Class
use \atk4\core\ConfigTrait;
2. create config-default.php and/or config.php file and add config values like
$config[‘key’] = ‘value’;
3. call $this->readConfig();
before using config.
Source:vendor/atk4/core/src/ConfigTrait.php#15

Properties

public static property atk4\core\ConfigTrait::$_configTrait
Check this property to see if trait is present in the object.
Source:vendor/atk4/core/src/ConfigTrait.php#22
Type:bool
protected static property atk4\core\ConfigTrait::$config
This property stores config values. Use getConfig() method to access its values.
Source:vendor/atk4/core/src/ConfigTrait.php#29
Type:array

Methods

public atk4\core\ConfigTrait::readConfig( $files=[config.php], $format=php)
Read config file or files and store it in $config property.
Supported formats:
php - PHP file with $config[‘foo’] = ‘bar’ structure
php-inline - PHP file with return [‘foo’ => ‘bar’] structure
json - JSON file with {‘foo’:’bar’} structure
yaml - YAML file with yaml structure
Source:

vendor/atk4/core/src/ConfigTrait.php#47

Parameters:
  • $files (string | array) One or more filenames
  • $format (string) Optional format for config files
Throws:

\atk4\core\Exception

Returns:

$this

public atk4\core\ConfigTrait::setConfig($paths=[], $value=null)
Manually set configuration option.
Source:

vendor/atk4/core/src/ConfigTrait.php#107

Parameters:
  • $paths (string | array) Path to configuration element to set or array of [path=>value]
  • $value (mixed) Value to set
Returns:

$this

public atk4\core\ConfigTrait::getConfig($path, $default_value=null)
Get configuration element.
Source:

vendor/atk4/core/src/ConfigTrait.php#136

Parameters:
  • $path (string) Path to configuration element.
  • $default_value (mixed) Default value returned if element don’t exist
Returns:

mixed

protected atk4\core\ConfigTrait::_lookupConfigElement($path, $create_elements=false)
Internal method to lookup config element by given path.
Source:

vendor/atk4/core/src/ConfigTrait.php#157

Parameters:
  • $path (string) Path to navigate to
  • $create_elements (bool) Should we create elements it they don’t exist