Избавляемся от статических классов и синглтонов

This commit is contained in:
CORP\phedor 2018-03-27 12:23:58 +03:00
parent 77fa3dbd5e
commit 805fb6654d
11 changed files with 177 additions and 309 deletions

View file

@ -304,12 +304,12 @@ class Controller_Action
/**
* Добавление widget к отображению
*/
public function addChild(/*Widget*/ $section, $node)
public function addChild(/*Widgets_Widget*/ $section, $node)
{
$this->childNodes[$section] = $node;
}
public function setValue(/*Widget*/ $name, $value)
public function setValue(/*Widgets_Widget*/ $name, $value)
{
$this->ctrlValues[$name] = $value;
}

View file

@ -18,15 +18,12 @@ class Controller_Front extends Controller_Action
* @param Settings $_registry
* @param Shortcut $_shortcut
*/
public function __construct(Settings $_registry, $_shortcut) // $db, $installer, $shortcut
public function __construct($db, $settings, $default) // $db, $installer, $shortcut
{
parent::__construct();
$registry = $_registry;
$this->_registry = $_registry;
$this->_shortcut = $_shortcut; // $cc->newShortcut();
$dsn = $registry->readKey(array('system', 'dsn'));
$this->db = Database::getConnection($dsn); // $cc->newConnection();
$this->settings = $settings;
$this->db = $db;
$this->default = $default;
}
public function isLoaded($name)
@ -47,34 +44,24 @@ class Controller_Front extends Controller_Action
return $module->access->execute($request);
}
if ($controller) {
$moduleFile = Shortcut::getUrl($this->shortcut, $name, $controller); // ModuleLoader (2)
} else {
$moduleFile = Shortcut::getUrl($this->shortcut, $name, $name); // ModuleLoader (2)
}
$basePath = $this->settings['system']->readKey(['path', 'modules']);
$moduleFile = Path::join($basePath, $name, 'classes', $controller ? $controller : $name);
$module = $this->loadClass($moduleFile, null, 'Module_');
if ($module) {
// Инициализация модуля
$module->viewPath = Shortcut::getUrl('modulepath', $name);
$modPath = Path::join($basePath, $name);
$module->viewPath = $modPath;
$module->name = $name;
$module->param = $this->param;
//
$module->_registry = $this->_registry;
$module->_shortcut = $this->_shortcut;
$module->iconPath = $this->iconPath; // -> Registry
$module->themePath = $this->themePath; // -> Registry
$module->jsPath = $this->jsPath; // -> Registry
$module->settings = $this->settings;
$module->db = $this->db;
// Не для всех приложений нужно вести лог действий
// Ведение лога
$logger = $this->loadClass(__DIR__ . '/../Filter/ActionLogger.php', $module, 'Filter_');
$logger->before = $this->loadSettings(Shortcut::getUrl('logger', $name));
$logger = new Filter_ActionLogger($module);
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));
// Управление доступом
$module->access = $this->loadClass(__DIR__ . '/../Filter/ActionAccess.php', $logger, 'Filter_');
$module->access->access = $this->loadSettings(Shortcut::getUrl('access', $name));
$module->access = new Filter_ActionAccess($logger);
$module->access->access = $this->loadSettings(Path::join($modPath, 'filter', 'access.php'));
$module->setUp();
@ -85,27 +72,19 @@ class Controller_Front extends Controller_Action
return null; // throw new FileNotFoundException();
}
public function setParameter($shortcut, $param, $name)
{
$this->shortcut = $shortcut;
// Параметр
$this->_param = $param;
$this->default = $name;
}
public function execute(HTTPRequest $request)
{
$name = explode("_", $request->get($this->_param, $this->default));
$name = explode("_", $request->get('module', $this->default));
if (count($name) >= 2) {
$controller = $name[1];
} else {
$controller = false;
}
try{
try {
return $this->loadModule($name[0], $request, $controller);
} catch (UserMessageException $ex) { //Исключение с понятным пользователю сообщением
$mode = $request->get('mode');
if($mode == 'ajax' || $mode == 'json'){
if($mode == 'ajax' || $mode == 'json') {
return json_encode(['result'=>'fail', 'message'=> $ex->userMessage]);
} else {
return $ex->userMessage;