<?php
namespace Lia\Compo;
class Config extends \Lia\Compo {
protected $map = [];
public function apiSet_lia_conf_set($key, $value){
$this->map[$key] = $value;
}
public function apiGet_lia_conf_get($key){
if (isset($this->map[$key]))return $this->map[$key];
throw new \Lia\Exception\Base("Key '{$key}' is not set to config.");
}
/**
* set the default $value for the $key. This will never overwrite a previously set value.
*/
public function apiDefault_lia_conf_default($key, $value){
if (!isset($this->map[$key]))$this->map[$key] = $value;
}
public function onPreStart(){
//@TODO test the configurations that are supposed to propagate to a package from liaison, when prefixed with 'package.'
foreach ($this->map as $key=>$value){
$parts = explode('.',$key);
$prefix = $parts[0] ?? null;
if ($prefix!='package')continue;
$package = $this->lia->api('lia.package', 'get', 'package',$parts[1]);
if ($package==null)continue;
array_shift($parts);
array_shift($parts);
if (count($parts)==0)continue;
$package->set(implode('.',$parts), $value);
}
}
}