Multiple config files and global variables extending

53 views
Skip to first unread message

scrazzy

unread,
Aug 22, 2017, 8:34:30 AM8/22/17
to Fat-Free Framework
Hi,
is it possible to extend variable (add string to current one in hive) from second and later config files used by $f3->config() method?

Im trying to use multiple config files and Im looking for possibility to add value to AUTOLOAD global variable from 2nd loaded config file.
When I use AUTOLOAD=something in second file, it will overwrite previous value, I want to add "something" to previously initialized AUTOLOAD.
Something like:

AUTOLOAD .= "module/my_module/classes/;"

Same situation is with UI variable, where I want to add "modules/my_module/ui" to UI variable initialized in previously in main config file.

Thanks in advance,
Marek

ved

unread,
Aug 22, 2017, 9:12:01 AM8/22/17
to Fat-Free Framework
Not sure but I doubt it.

You'd probably have to name them something else on your configs (e.g.: module_autoload, module_ui) and then use some code logic after importing the config in order to build the values for the AUTOLOAD and UI vars from those.

ikkez

unread,
Aug 22, 2017, 9:22:32 AM8/22/17
to Fat-Free Framework
You could write a custom config parser and add a concat method :D

your config could look like this:

[globals > Config->parse]
; overwrite
UI = theme2/
; extend / concat
AUTOLOAD <= foo/


and the parser like this:

class Config extends \Prefab {

/** @var static \Base */
protected $f3;

function __construct() {
$this->f3 = \Base::instance();
}

public function parse($key, $value, $scope) {
if (is_int(strpos($key,'<')))
$this->f3->concat(rtrim($key,' <'), ','.$value);
else
$this->f3->set($key, $value);
}
}

tested, works, but no warranty at all ;)

ikkez

unread,
Aug 22, 2017, 9:24:34 AM8/22/17
to Fat-Free Framework
you could also use the option to $allow dynamic variables in config files:

$f3->config('app.ini', TRUE);

AUTOLOAD = {{@AUTOLOAD}};module/my_module/classes/


Am Dienstag, 22. August 2017 14:34:30 UTC+2 schrieb scrazzy:

scrazzy

unread,
Aug 22, 2017, 9:38:56 AM8/22/17
to f3-fra...@googlegroups.com
This is probably what I was looking for, thank you a lot!
Reply all
Reply to author
Forward
0 new messages