Регистр файлов
This commit is contained in:
parent
4fd0187ea6
commit
c8958cbee0
83 changed files with 25 additions and 53 deletions
84
src/Controller/Front.php
Normal file
84
src/Controller/Front.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Первичный контроллер контроллер страниц
|
||||
* @package core
|
||||
*/
|
||||
class Controller_Front extends Controller_Action
|
||||
{
|
||||
|
||||
protected $shortcut; // Ярлык к модулю
|
||||
protected $_param; // Параметр по которому выбирается модуль
|
||||
protected $default; // Значение параметра по умолчанию
|
||||
|
||||
public function __construct(Settings $_registry, $_shortcut)
|
||||
{
|
||||
parent::__construct();
|
||||
$registry = $_registry;
|
||||
$this->_registry = $_registry;
|
||||
$this->_shortcut = $_shortcut;
|
||||
|
||||
$this->db = Database::getConnection($registry->readKey(array('system', 'dsn')));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Создает экземпляр модуля и выполняет действия для него
|
||||
* @param string $name Имя модуля
|
||||
* @param request $request Имя модуля
|
||||
* @return string
|
||||
*/
|
||||
public function loadModule($name, Collection $request)
|
||||
{
|
||||
|
||||
$moduleFile = Shortcut::getUrl($this->shortcut, $name); // ModuleLoader (2)
|
||||
$module = $this->loadClass($moduleFile);
|
||||
|
||||
if ($module) {
|
||||
// Инициализация модуля
|
||||
// $module->viewPath = dirname($moduleFile);
|
||||
$module->viewPath = Shortcut::getUrl('modulepath', $name);
|
||||
$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->db = $this->db;
|
||||
// Не для всех приложений нужно вести лог действий
|
||||
// Ведение лога
|
||||
$logger = $this->loadClass(FRAMEWORK_PATH . '/src/filter/actionlogger.php', $module);
|
||||
$logger->before = $this->loadSettings(Shortcut::getUrl('logger', $name));
|
||||
// Управление доступом
|
||||
$module->access = $this->loadClass(FRAMEWORK_PATH . '/src/filter/actionaccess.php', $logger);
|
||||
$module->access->access = $this->loadSettings(Shortcut::getUrl('access', $name));
|
||||
|
||||
$module->setUp();
|
||||
|
||||
return $module->access->execute($request);
|
||||
}
|
||||
return null; // throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
public function setParameter($shortcut, $param, $name)
|
||||
{
|
||||
$this->shortcut = $shortcut;
|
||||
// Параметр
|
||||
$this->_param = $param;
|
||||
$this->default = $name;
|
||||
}
|
||||
|
||||
private function getParameter(Collection $list)
|
||||
{
|
||||
return ($list->get($this->_param)) ? $list->get($this->_param): $this->default;
|
||||
}
|
||||
|
||||
public function execute(HTTPRequest $request)
|
||||
{
|
||||
return $this->loadModule($this->getParameter($request), $request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue