Избавляемся от констант и глобальных переменных

This commit is contained in:
CORP\phedor 2018-03-28 12:43:06 +03:00
parent 8b38b2a3cc
commit f041488554
10 changed files with 39 additions and 33 deletions

View file

@ -52,7 +52,6 @@ class Action
public $param = array(); // Параметры для ссылки
public /*.Registry.*/$_registry; // Ссылка на реестр
public $_shortcut;
public $modulePrefix = '';
public $iconPath = '';
@ -69,10 +68,12 @@ class Action
}
public function loadConfig($name) {
$filename = Shortcut::getUrl('config', $name);
$basePath = $this->settings['base'];
$filename = Path::join($basePath, 'modules', $name);
$settings = [];
if (file_exists($filename)) {
include($filename);
$settings = include($filename);
} else {
throw new Exception('Невозможно загрузить файл настроек ' . $name);
}
@ -86,7 +87,8 @@ class Action
public function installPath($name)
{
return Path::join(CMS_PATH, "modules", $name);
$basePath = $this->settings['base'];
return Path::join($basePath, "modules", $name);
}
public function addSuggest(View $view, $name)
@ -110,13 +112,16 @@ class Action
* @param $viewClass String
* @return View_Composite
*/
public function getView($name, $viewClass = 'View_Composite')
public function getView($name, $viewClass = 'ctiso\\View\\Composite')
{
$file = $name . self::TEMPLATE_EXTENSION;
$basePath = $this->settings['base'];
$webPath = $this->settings['web'];
$list = array(
Path::join($this->viewPath, TEMPLATES, $this->viewPathPrefix) => Path::join(WWW_PATH, "modules", $this->name, TEMPLATES, $this->viewPathPrefix),
Path::join(CMS_PATH, "templates") => Path::join(WWW_PATH, "templates")
Path::join($this->viewPath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix),
Path::join($basePath, "templates") => Path::join($webPath, "templates")
);
// Поиск файла для шаблона
@ -127,7 +132,7 @@ class Action
/*.View_Composite.*/$tpl = new $viewClass($template);
$assets = Path::join(enableHttps(WWW_PATH), "assets", "css");
$assets = Path::join($webPath, "assets", "css");
$tpl->set('icons', $this->iconPath); // Путь к файлам текущей темы
$tpl->set('media', $this->themePath); // Путь к файлам текущей темы
$tpl->set('assets', $assets);

View file

@ -11,28 +11,26 @@ use ctiso\Controller\Action,
ctiso\Collection,
ctiso\Filter\ActionAccess,
ctiso\Filter\ActionLogger,
ctiso\Path;
ctiso\Path,
ctiso\UserMessageException,
ctiso\HttpRequest;
class Front extends Action
{
/** @var Shortcut */
protected $shortcut; // Ярлык к модулю
protected $_param; // Параметр по которому выбирается модуль
protected $default; // Значение параметра по умолчанию
protected $modules = array();
/**
* @param Settings $_registry
* @param Shortcut $_shortcut
* @param Settings $settings
*/
public function __construct($db, $settings, $default) {
public function __construct($db, $settings, $user, $default) {
parent::__construct();
$this->settings = $settings;
$this->db = $db;
$this->user = $user;
$this->default = $default;
}
@ -52,23 +50,26 @@ class Front extends Action
$module = $this->modules[$name];
return $module->access->execute($request);
}
$system = $this->settings['system'];
$basePath = $this->settings['system']->readKey(['path', 'modules']);
$moduleFile = Path::join($basePath, $name, 'classes', $controller ? $controller : $name);
$moulesPath = $system->readKey(['path', 'modules']);
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
$moduleFile = Path::join($this->settings['base'], $moulesPath, $name, 'classes', $controller ? $controller : $name);
$ucname = ucfirst($name);
$moduleClass = "Module\\$ucname\\$ucname";
$moduleClass = "Modules\\$ucname\\$ucname";
$module = new $moduleClass();
if ($module) {
// Инициализация модуля
$modPath = Path::join($basePath, $name);
$modPath = Path::join($moulesPath, $name);
$module->viewPath = $modPath;
$module->name = $name;
//
$module->settings = $this->settings;
$module->db = $this->db;
// Ведение лога
$logger = new ActionLogger($module);
$logger = new ActionLogger($module, $logPath, $this->user);
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));
// Управление доступом
$module->access = new ActionAccess($logger);