Избавляемся от констант и глобальных переменных
This commit is contained in:
parent
8b38b2a3cc
commit
f041488554
10 changed files with 39 additions and 33 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Database extends PDO
|
|||
{
|
||||
parent::__construct($dsn, $username, $password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Database_PDOStatement', array()));
|
||||
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('ctiso\\Database\\PDOStatement', array()));
|
||||
}
|
||||
|
||||
public function getDSN()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Database;
|
||||
|
||||
namespace ctiso\Database\PDOStatement;
|
||||
use ctiso\\PDOStatement,
|
||||
ctiso\StatementIterator,
|
||||
use ctiso\Database\StatementIterator,
|
||||
PDO;
|
||||
use ctiso\Database\StatementIterator;
|
||||
|
||||
class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Filter;
|
||||
use ctiso\Shortcut,
|
||||
ctiso\HttpRequest,
|
||||
ctiso\Filter\UserAccess;
|
||||
use ctiso\HttpRequest;
|
||||
|
||||
class ActionLogger
|
||||
{
|
||||
public $before = array();
|
||||
public $file;
|
||||
public $user;
|
||||
public $action;
|
||||
public $processor;
|
||||
|
||||
function __construct(/*.Filter_Filter.*/$processor) {
|
||||
function __construct(/*.Filter_Filter.*/$processor, $logPath, $user) {
|
||||
$this->processor = $processor;
|
||||
$this->file = fopen(Shortcut::getUrl('access.log'), "a");
|
||||
$this->user = $user;
|
||||
$this->file = fopen($logPath, "a");
|
||||
}
|
||||
|
||||
function execute(HttpRequest $request) {
|
||||
$action = $request->getAction();
|
||||
if(in_array($action, $this->before)) {
|
||||
fwrite($this->file, "time: " . date("r", time()) . " query: ". json_encode(array_merge($_POST, $_GET)) . " by: " . UserAccess::$name . "\n");
|
||||
fwrite($this->file, "time: " . date("r", time()) . " query: ". json_encode(array_merge($_POST, $_GET)) . " by: " . $this->user->name . "\n");
|
||||
}
|
||||
return $this->processor->execute($request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Filter
|
|||
return $this->processor->execute($request);
|
||||
}
|
||||
|
||||
public function getView($name, $class = 'View_Top')
|
||||
public function getView($name, $class = 'ctiso\\View\\Top')
|
||||
{
|
||||
return $this->processor->getView($name, $class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class Login extends Filter
|
|||
// Если $hash не совпадает $_SESSION['hash'] то удаляем сессию
|
||||
if (isset($_SESSION ['access']) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) {
|
||||
if ($hash == $_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME]) {
|
||||
$this->user = $user = $role->getUserById($_SESSION['access']); // Поиск по идентификатору
|
||||
$this->user = $user = $this->role->getUserById($_SESSION['access']); // Поиск по идентификатору
|
||||
if ($user && isset($_SESSION['random']) && ($user->get('sid') == $_SESSION['random'])) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
namespace ctiso;
|
||||
use Exception,
|
||||
ArrayAccess,
|
||||
ctiso\Collection,
|
||||
ctiso\Session;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace ctiso\Layout;
|
|||
use ctiso\Filter\Filter,
|
||||
ctiso\HttpRequest;
|
||||
|
||||
class Empty extends Filter
|
||||
class Blank extends Filter
|
||||
{
|
||||
function execute(HttpRequest $request)
|
||||
{
|
||||
|
|
@ -67,6 +67,7 @@ class Manager extends Filter
|
|||
*/
|
||||
public function execute(HttpRequest $request)
|
||||
{
|
||||
// print_r($request->get('mode'));
|
||||
foreach ($this->condition as $condition) {
|
||||
if (call_user_func($condition[0], $request)) {
|
||||
$layout = $condition[1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue