Answer the question
In order to leave comments, you need to log in
How to make the application configuration available in all plug-in classes in the form of an array?
In general, there is an application configuration array:
$config = [
'logotext' => 'USER Application Name',
'base_dir' => BASE_DIR,
'db' => [
'file' => BASE_DIR . 'db/database.sqlite',
],
'router'=> [
'path'=>true,
'action'=>'index',
'rules'=> [],
],
];
// Старт приложения:
$app = new Application($config);
echo $app->run();
abstract class System {
public $config;
public function __construct($config=null)
{
$this->_setConfig($config); // Преобразую Массив конфига в обьекты, чисто для красоты ($this->config->paramName->subParamName)
$this->init();
}
private function _setConfig($config)
{
$this->config = $this->_toObject($config);
}
public function router($class='Router')
{
return new $class($this->config->router);
}
}
class Application extends System {
function __construct($config=null)
{
parent::__construct($config);
}
}
class Data {
function getConfigDSNString()
{
return; // Вернуть какую либо строку из конфигурации в качестве примера передачи конфиг массива в класс
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question