Избавляемся от констант и глобальных переменных
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 $param = array(); // Параметры для ссылки
|
||||||
|
|
||||||
public /*.Registry.*/$_registry; // Ссылка на реестр
|
public /*.Registry.*/$_registry; // Ссылка на реестр
|
||||||
public $_shortcut;
|
|
||||||
public $modulePrefix = '';
|
public $modulePrefix = '';
|
||||||
public $iconPath = '';
|
public $iconPath = '';
|
||||||
|
|
||||||
|
|
@ -69,10 +68,12 @@ class Action
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadConfig($name) {
|
public function loadConfig($name) {
|
||||||
$filename = Shortcut::getUrl('config', $name);
|
$basePath = $this->settings['base'];
|
||||||
|
|
||||||
|
$filename = Path::join($basePath, 'modules', $name);
|
||||||
$settings = [];
|
$settings = [];
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
include($filename);
|
$settings = include($filename);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('Невозможно загрузить файл настроек ' . $name);
|
throw new Exception('Невозможно загрузить файл настроек ' . $name);
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +87,8 @@ class Action
|
||||||
|
|
||||||
public function installPath($name)
|
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)
|
public function addSuggest(View $view, $name)
|
||||||
|
|
@ -110,13 +112,16 @@ class Action
|
||||||
* @param $viewClass String
|
* @param $viewClass String
|
||||||
* @return View_Composite
|
* @return View_Composite
|
||||||
*/
|
*/
|
||||||
public function getView($name, $viewClass = 'View_Composite')
|
public function getView($name, $viewClass = 'ctiso\\View\\Composite')
|
||||||
{
|
{
|
||||||
$file = $name . self::TEMPLATE_EXTENSION;
|
$file = $name . self::TEMPLATE_EXTENSION;
|
||||||
|
|
||||||
|
$basePath = $this->settings['base'];
|
||||||
|
$webPath = $this->settings['web'];
|
||||||
|
|
||||||
$list = array(
|
$list = array(
|
||||||
Path::join($this->viewPath, TEMPLATES, $this->viewPathPrefix) => Path::join(WWW_PATH, "modules", $this->name, TEMPLATES, $this->viewPathPrefix),
|
Path::join($this->viewPath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix),
|
||||||
Path::join(CMS_PATH, "templates") => Path::join(WWW_PATH, "templates")
|
Path::join($basePath, "templates") => Path::join($webPath, "templates")
|
||||||
);
|
);
|
||||||
|
|
||||||
// Поиск файла для шаблона
|
// Поиск файла для шаблона
|
||||||
|
|
@ -127,7 +132,7 @@ class Action
|
||||||
|
|
||||||
/*.View_Composite.*/$tpl = new $viewClass($template);
|
/*.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('icons', $this->iconPath); // Путь к файлам текущей темы
|
||||||
$tpl->set('media', $this->themePath); // Путь к файлам текущей темы
|
$tpl->set('media', $this->themePath); // Путь к файлам текущей темы
|
||||||
$tpl->set('assets', $assets);
|
$tpl->set('assets', $assets);
|
||||||
|
|
|
||||||
|
|
@ -11,28 +11,26 @@ use ctiso\Controller\Action,
|
||||||
ctiso\Collection,
|
ctiso\Collection,
|
||||||
ctiso\Filter\ActionAccess,
|
ctiso\Filter\ActionAccess,
|
||||||
ctiso\Filter\ActionLogger,
|
ctiso\Filter\ActionLogger,
|
||||||
ctiso\Path;
|
ctiso\Path,
|
||||||
ctiso\UserMessageException,
|
ctiso\UserMessageException,
|
||||||
ctiso\HttpRequest;
|
ctiso\HttpRequest;
|
||||||
|
|
||||||
class Front extends Action
|
class Front extends Action
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var Shortcut */
|
|
||||||
protected $shortcut; // Ярлык к модулю
|
|
||||||
protected $_param; // Параметр по которому выбирается модуль
|
protected $_param; // Параметр по которому выбирается модуль
|
||||||
protected $default; // Значение параметра по умолчанию
|
protected $default; // Значение параметра по умолчанию
|
||||||
|
|
||||||
protected $modules = array();
|
protected $modules = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Settings $_registry
|
* @param Settings $settings
|
||||||
* @param Shortcut $_shortcut
|
|
||||||
*/
|
*/
|
||||||
public function __construct($db, $settings, $default) {
|
public function __construct($db, $settings, $user, $default) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
$this->user = $user;
|
||||||
$this->default = $default;
|
$this->default = $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,23 +50,26 @@ class Front extends Action
|
||||||
$module = $this->modules[$name];
|
$module = $this->modules[$name];
|
||||||
return $module->access->execute($request);
|
return $module->access->execute($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$system = $this->settings['system'];
|
||||||
|
|
||||||
$basePath = $this->settings['system']->readKey(['path', 'modules']);
|
$moulesPath = $system->readKey(['path', 'modules']);
|
||||||
$moduleFile = Path::join($basePath, $name, 'classes', $controller ? $controller : $name);
|
$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);
|
$ucname = ucfirst($name);
|
||||||
$moduleClass = "Module\\$ucname\\$ucname";
|
$moduleClass = "Modules\\$ucname\\$ucname";
|
||||||
$module = new $moduleClass();
|
$module = new $moduleClass();
|
||||||
if ($module) {
|
if ($module) {
|
||||||
// Инициализация модуля
|
// Инициализация модуля
|
||||||
$modPath = Path::join($basePath, $name);
|
$modPath = Path::join($moulesPath, $name);
|
||||||
$module->viewPath = $modPath;
|
$module->viewPath = $modPath;
|
||||||
$module->name = $name;
|
$module->name = $name;
|
||||||
//
|
//
|
||||||
$module->settings = $this->settings;
|
$module->settings = $this->settings;
|
||||||
$module->db = $this->db;
|
$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'));
|
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));
|
||||||
// Управление доступом
|
// Управление доступом
|
||||||
$module->access = new ActionAccess($logger);
|
$module->access = new ActionAccess($logger);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class Database extends PDO
|
||||||
{
|
{
|
||||||
parent::__construct($dsn, $username, $password);
|
parent::__construct($dsn, $username, $password);
|
||||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$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()
|
public function getDSN()
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace ctiso\Database;
|
||||||
|
|
||||||
namespace ctiso\Database\PDOStatement;
|
use ctiso\Database\StatementIterator,
|
||||||
use ctiso\\PDOStatement,
|
|
||||||
ctiso\StatementIterator,
|
|
||||||
PDO;
|
PDO;
|
||||||
use ctiso\Database\StatementIterator;
|
|
||||||
|
|
||||||
class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ctiso\Filter;
|
namespace ctiso\Filter;
|
||||||
use ctiso\Shortcut,
|
use ctiso\HttpRequest;
|
||||||
ctiso\HttpRequest,
|
|
||||||
ctiso\Filter\UserAccess;
|
|
||||||
|
|
||||||
class ActionLogger
|
class ActionLogger
|
||||||
{
|
{
|
||||||
public $before = array();
|
public $before = array();
|
||||||
public $file;
|
public $file;
|
||||||
|
public $user;
|
||||||
public $action;
|
public $action;
|
||||||
public $processor;
|
public $processor;
|
||||||
|
|
||||||
function __construct(/*.Filter_Filter.*/$processor) {
|
function __construct(/*.Filter_Filter.*/$processor, $logPath, $user) {
|
||||||
$this->processor = $processor;
|
$this->processor = $processor;
|
||||||
$this->file = fopen(Shortcut::getUrl('access.log'), "a");
|
$this->user = $user;
|
||||||
|
$this->file = fopen($logPath, "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute(HttpRequest $request) {
|
function execute(HttpRequest $request) {
|
||||||
$action = $request->getAction();
|
$action = $request->getAction();
|
||||||
if(in_array($action, $this->before)) {
|
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);
|
return $this->processor->execute($request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Filter
|
||||||
return $this->processor->execute($request);
|
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);
|
return $this->processor->getView($name, $class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ class Login extends Filter
|
||||||
// Если $hash не совпадает $_SESSION['hash'] то удаляем сессию
|
// Если $hash не совпадает $_SESSION['hash'] то удаляем сессию
|
||||||
if (isset($_SESSION ['access']) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) {
|
if (isset($_SESSION ['access']) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) {
|
||||||
if ($hash == $_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'])) {
|
if ($user && isset($_SESSION['random']) && ($user->get('sid') == $_SESSION['random'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
namespace ctiso;
|
namespace ctiso;
|
||||||
use Exception,
|
use Exception,
|
||||||
|
ArrayAccess,
|
||||||
ctiso\Collection,
|
ctiso\Collection,
|
||||||
ctiso\Session;
|
ctiso\Session;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace ctiso\Layout;
|
||||||
use ctiso\Filter\Filter,
|
use ctiso\Filter\Filter,
|
||||||
ctiso\HttpRequest;
|
ctiso\HttpRequest;
|
||||||
|
|
||||||
class Empty extends Filter
|
class Blank extends Filter
|
||||||
{
|
{
|
||||||
function execute(HttpRequest $request)
|
function execute(HttpRequest $request)
|
||||||
{
|
{
|
||||||
|
|
@ -67,6 +67,7 @@ class Manager extends Filter
|
||||||
*/
|
*/
|
||||||
public function execute(HttpRequest $request)
|
public function execute(HttpRequest $request)
|
||||||
{
|
{
|
||||||
|
// print_r($request->get('mode'));
|
||||||
foreach ($this->condition as $condition) {
|
foreach ($this->condition as $condition) {
|
||||||
if (call_user_func($condition[0], $request)) {
|
if (call_user_func($condition[0], $request)) {
|
||||||
$layout = $condition[1];
|
$layout = $condition[1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue