Другая интерпретация реестра

This commit is contained in:
CORP\phedor 2018-04-20 18:03:39 +03:00
parent 40fad0e75b
commit aaa9c2e1bf
21 changed files with 156 additions and 92 deletions

View file

@ -9,6 +9,8 @@ use ctiso\Shortcut,
ctiso\HttpRequest,
ctiso\Functions,
ctiso\Settings,
ctiso\Registry,
ctiso\Role\User,
ctiso\View\Composite,
ctiso\Filter\ActionAccess,
ctiso\View\View,
@ -45,8 +47,8 @@ class Action
private $helpers = array(); // Помошники для действий
public $part = null; // Параметры для ссылки
public /*.Settings.*/$settings; // Ссылка на настройки
public $user; // Обьект пользователя
public /*.Registry.*/$config; // Ссылка на настройки
public /*.User.*/$user; // Обьект пользователя
// Для Widgets
public $view = null;
@ -62,7 +64,7 @@ class Action
}
public function loadConfig($name) {
$basePath = $this->settings['base'];
$basePath = $this->config->get('site', 'path');
$filename = Path::join($basePath, 'modules', $name);
$settings = [];
@ -81,7 +83,7 @@ class Action
public function installPath($name)
{
$basePath = $this->settings['base'];
$basePath = $this->config->get('site', 'path');
return Path::join($basePath, "modules", $name);
}
@ -94,7 +96,7 @@ class Action
}
function findIcon($icon, $size) {
$webPath = $this->settings['web'];
$webPath = $this->config->get('site', 'web');
return Path::join($webPath, 'icons', $size . 'x' . $size, $icon . '.png');
}
@ -108,8 +110,8 @@ class Action
{
$file = $name . self::TEMPLATE_EXTENSION;
$basePath = $this->settings['base'];
$webPath = $this->settings['web'];
$basePath = $this->config->get('site', 'path');
$webPath = $this->config->get('site', 'web');
$list = array(
Path::join($this->modulePath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix),
@ -151,7 +153,7 @@ class Action
public function getModel($name)
{
if (!$this->factory) {
$this->factory = new Factory($this->db, $this->settings['registry']);
$this->factory = new Factory($this->db, $this->config);
}
return $this->factory->getModel($name);
}
@ -327,7 +329,8 @@ class Action
*/
public function render()
{
if ($this->view instanceof View) {
$view = $this->view;
if ($view instanceof View) {
$this->view->assignValues($this->ctrlValues);
/*.Composite.*/$node = null;
@ -369,8 +372,8 @@ class Action
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
}
function redirect($action) {
header('location: ' . $action->toString());
function redirect(/*.string.*/$action) {
header('location: ' . $action);
exit();
}
}

View file

@ -12,20 +12,11 @@ use ctiso\HttpRequest,
ctiso\Database,
ctiso\Database\PDOStatement,
ctiso\Collection,
ctiso\Settings,
ctiso\Registry,
App\Controller\Site,
PHPTAL,
PHPTAL_PreFilter_Normalize;
function replaceContent($match) {
$result = Tales\Component::phptal_component(htmlspecialchars_decode($match[3]));
return $result;
}
function applyComponents($text) {
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'replaceContent', $text);
}
class FakeTemplate {
public $_data = [];
public $_name = '';
@ -56,11 +47,13 @@ class Component
public $component_id;
public $component_title;
public $COMPONENTS_WEB;
public /*.Settings.*/$registry;
public /*.Registry.*/$config;
public /*.Database.*/$db;
public /*.Collection.*/$parameter;
public $output = 'html';
public $module;
@ -70,7 +63,12 @@ class Component
function before() {
}
function get($request, $key, $default) {
static function replaceContent($match) {
return \ctiso\Tales::phptal_component(htmlspecialchars_decode($match[3]));
}
static function applyComponents($text) {
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'ctiso\\Controller\\Component::replaceContent', $text);
}
function execute(HttpRequest $request, $has_id = true) {
@ -97,8 +95,9 @@ class Component
return new FakeTemplate($name);
}
/*.Settings.*/$registry = $this->registry;
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
/*.Registry.*/$config = $this->config;
$default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $default;
$selected = null;
foreach ($this->viewPath as $index => $viewPath) {
@ -121,13 +120,14 @@ class Component
$tpl->stripComments(true);
$tpl->addPreFilter(new PHPTAL_PreFilter_Normalize());
$tpl->set('common', Path::join(WWW_PATH, '../', 'common'));
$tpl->set('script', Path::join(WWW_PATH, 'js'));
$tpl->set('media', Path::join(TEMPLATE_WEB, $template));
if ($registry) {
$tpl->set('site_template', SITE_WWW_PATH . '/templates' . $registry->readKey(array('system', 'template')));
$tpl->set('common', Path::join($this->config->get('system', 'web'), '../', 'common'));
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
$tpl->set('media', Path::join($this->config->get('system', 'templates_web'), $template));
if ($default) {
$tpl->set('site_template', $this->config->get('site', 'web') . '/templates/' . $default);
}
$tpl->set('base', SITE_WWW_PATH);
$tpl->set('base', $this->config->get('site', 'web'));
$tpl->set('component_base', $this->webPath[$selected]);
$tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template));
@ -199,7 +199,7 @@ class Component
public function setParameters(/*.Composite.*/ $view)
{
$form = new Form();
$options = new OptionFactory($this->db, $this->registry);
$options = new OptionFactory($this->db, $this->config);
$settings = $this->getInfo();
$form->addFieldList($settings['parameter'], $options);
@ -226,7 +226,7 @@ class Component
}
$name = $path;
$path = Path::join (BASE_PATH, 'components', $name, $name . '.php');
$path = Path::join ($this->config->get('site', 'path'), 'components', $name, $name . '.php');
$className = 'Component_' . $name;
/*.Component.*/$component = null;
@ -235,26 +235,26 @@ class Component
require_once ($path);
$component = new $className();
$component->viewPath = array(BASE_PATH . '/components/' . $name . '/');
$component->webPath = array(SITE_WWW_PATH . '/components/' . $name);
$component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/';
$component->viewPath = array($this->config->get('site', 'path') . '/components/' . $name . '/');
$component->webPath = array($this->config->get('site', 'web') . '/components/' . $name);
$component->COMPONENTS_WEB = $this->config->get('site', 'web') . '/components/';
} else {
$path = Path::join (COMPONENTS, $name, $name . '.php');
$path = Path::join ($this->config->get('system', 'components'), $name, $name . '.php');
require_once ($path);
$component = new $className();
$component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/');
$component->viewPath = array($this->config->get('system', 'components') . '/' . $name . '/', $this->config->get('site', 'path') . '/components/' . $name . '/');
if (defined('COMPONENTS_WEB')) {
$component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name);
$component->COMPONENTS_WEB = COMPONENTS_WEB;
$component->webPath = array($this->config->get('system', 'components_web') . '/' . $name, $this->config->get('site', 'web') . '/components/' . $name);
$component->COMPONENTS_WEB = $this->config->get('system', 'components_web');
}
}
$db = $site->db;
$component->db = $db;
$component->registry = $site->registry;
$component->config = $site->config;
$component->site = $site;
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");

View file

@ -26,9 +26,9 @@ class Front extends Action
/**
* @param Settings $settings
*/
public function __construct($db, $settings, $user, $default) {
public function __construct($db, $config, $user, $default) {
parent::__construct();
$this->settings = $settings;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->default = $default;
@ -50,11 +50,11 @@ class Front extends Action
$module = $this->modules[$name];
return $module->access->execute($request);
}
$config = $this->config;
/*.Settings.*/$system = $this->settings['system'];
$moulesPath = Path::join($config->get('system', 'path'), 'modules');
$logPath = Path::join($config->get('site', 'path'), $config->get('system', 'access.log'));
$moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules']));
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
$moduleFile = Path::join($moulesPath, $name, 'classes', $controller ? $controller : $name);
$ucname = ucfirst($name);
@ -66,14 +66,14 @@ class Front extends Action
$module->modulePath = $modPath;
$module->name = $name;
//
$module->settings = $this->settings;
$module->config = $this->config;
$module->db = $this->db;
$module->user = $this->user;
// Ведение лога
$logger = new ActionLogger($module, $logPath, $this->user);
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));
// Управление доступом
$module->access = new ActionAccess($logger);
$module->access = new ActionAccess($logger, $this->user);
$module->access->access = $this->loadSettings(Path::join($modPath, 'filter', 'access.php'));
$module->setUp();

View file

@ -35,7 +35,7 @@ class Installer
// Проверка версии обновления
function isChanged($name) // Информация о модулях
{
$item = $this->_registry->readKey(array($name));
$item = $this->_registry->get('system', $name);
if ($item) {
$setup = $this->getSetupFile($name);
if (file_exists($setup) && (filemtime($setup) > $item['time'])) {
@ -81,7 +81,7 @@ class Installer
$settings = new Settings($setup);
$settings->read();
$item = $registry->readKey(array($name));
$item = $registry->get('system', $name);
$version_new = $settings->get('version');
if ($item) {
@ -101,8 +101,9 @@ class Installer
// Обновление версии меню
$registry->removeKey($name);
$registry->writeKey(array($name), $settings->get('settings'));
$registry->writeKey(array($name),
$registry->set($name, $settings->get('settings'));
$registry->set($name,
array('version' => $version_new,
'time' => filemtime($setup)));
}

View file

@ -5,13 +5,14 @@
*/
namespace ctiso\Controller;
use ctiso\Path,
ctiso\Registry,
ctiso\Database\PDOStatement;
class Service
{
public $viewPath = [];
public $webPath = [];
public $registry; // Registry->getInstance
public /*.Registry.*/$config;
public $template;
public $templatePath;
public $COMPONENTS_WEB;
@ -33,7 +34,7 @@ class Service
*/
private function getModelPath($name)
{
return Path::join (CMS_PATH, "model", $name . ".php");
return Path::join ($this->config->get('system', 'path'), "model", $name . ".php");
}
/**

View file

@ -1,7 +1,8 @@
<?php
namespace ctiso\Controller;
use ctiso\Controller\Action;
use ctiso\Controller\Action,
ctiso\Url;
class State
{

View file

@ -92,7 +92,7 @@ class Document {
$this->createStyles($doc);
foreach ($this->table as $table) {
if ($table instanceof Excel_Table) {
if ($table instanceof Table) {
$table->createTable($doc);
} else {
$table_data = call_user_func($table);

View file

@ -4,7 +4,9 @@
* Клетка таблицы
*/
namespace ctiso\Excel;
use XMLWriter;
use XMLWriter,
ctiso\Excel\DateTime as Excel_DateTime,
ctiso\Excel\Number as Excel_Number;
class TableCell
{

View file

@ -5,15 +5,18 @@
*/
namespace ctiso\Filter;
use ctiso\Filter\UserAccess,
ctiso\HttpRequest;
ctiso\HttpRequest,
ctiso\Role\User;
class ActionAccess
{
public $access = array();
public $processor;
public /*.User.*/$user;
function __construct(/*.Filter.*/$processor) {
function __construct(/*.Filter.*/$processor, $user) {
$this->processor = $processor;
$this->user = $user;
}
/**

View file

@ -5,38 +5,41 @@ namespace ctiso\Filter;
class Authorization {
const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#';
const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign';
public $group;
static function isLogged($group = 'access') {
function __construct($group) {
$this->group = $group;
}
function isLogged() {
// echo session_status();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$hash = self::getBrowserSign();
// Если $hash не совпадает $_SESSION['hash'] то удаляем сессию
if (isset($_SESSION[$group]) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) {
if (isset($_SESSION[$this->group]) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) {
if ($hash == $_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME]) {
// UserAccess::getUserById($_SESSION ['access']); // Поиск по идентификатору
return true;
} else {
return false;
return false;
}
}
return false;
}
static function enter($id, $group = 'access')
{
function enter($id) {
// $db->executeQuery("UPDATE visitor SET sid = '' WHERE id_visitor = " . $result->getInt('id_user'));
// session_register("access");
// session_register("time");
// $_SESSION ["group"] = $result->getInt('access');
$_SESSION [$group] = $id; // id_user
$_SESSION [$this->group] = $id;
$_SESSION [self::SESSION_BROWSER_SIGN_KEYNAME] = self::getBrowserSign();
$_SESSION ["time"] = time();
$_SESSION ["time"] = time();
}
private static function getBrowserSign()
static function getBrowserSign()
{
$rawSign = self::SESSION_BROWSER_SIGN_SECRET;
// $signParts = array('HTTP_USER_AGENT', 'HTTP_ACCEPT_ENCODING');
@ -48,7 +51,7 @@ class Authorization {
return md5($rawSign);
}
static function logout() {
function logout() {
session_destroy();
}
}

View file

@ -13,6 +13,7 @@ use ctiso\Filter\Filter,
ctiso\HttpRequest,
ctiso\Settings,
ctiso\Database,
ctiso\Role\User,
ctiso\Collection;
class Login extends Filter
@ -22,7 +23,7 @@ class Login extends Filter
public $mode = 'ajax';
public $user;
public $role;
public /*.User.*/$role;
public $whitelist;
function __construct($processor, $role, $whitelist = []) {
@ -140,7 +141,7 @@ class Login extends Filter
// Параметры при неправильной авторизации
// Действия по умолчанию !! Возможно переход на форму регистрации
if ($request->get('mode') == 'ajax') {
if (!$this->requestIsWhite($request, $this->whiteRequestList)) {
if (!$this->requestIsWhite($request, $this->whitelist)) {
return json_encode(array('result' => 'fail', 'message' =>"NOT_AUTHORIZED"));
}
} else {

View file

@ -38,7 +38,7 @@ class OptionFactory {
try {
$query_result = $this->db->executeQuery("SELECT * FROM $table");
$field->options = $this->optionsDB($key, $value, $query_result);
} catch(Exception $ex) {
} catch(\Exception $ex) {
$field->options = [];
}
} elseif (isset($input['options.pair'])) {

View file

@ -372,7 +372,7 @@ class Path
*/
public function getContent($allow = null, $ignore = array())
{
$ignore = array_merge(array(".", ".."), $ignore);
$ignore = array_merge(array(".", ".."), $ignore);
return self::fileList($this->__toString(), $allow, $ignore);
}

40
src/Registry.php Normal file
View file

@ -0,0 +1,40 @@
<?php
namespace ctiso;
use ctiso\File,
Exception;
class Registry {
public $namespace = [];
function importFile($namespace, $filePath = null) {
$data = json_decode(File::getContents($filePath), true);
$data['_file'] = $filePath;
$this->namespace[$namespace] = [
'path' => $filePath,
'data' => $data
];
}
function importArray($namespace, $data = []) {
if (isset($this->namespace[$namespace])) {
$data = array_merge($this->namespace[$namespace]['data'], $data);
}
$this->namespace[$namespace] = [
'path' => null,
'data' => $data
];
}
public function get($ns, $key) {
return $this->namespace[$ns]['data'][$key];
}
public function has($ns, $key) {
return isset($this->namespace[$ns]['data'][$key]);
}
function set($ns, $key, $value) {
$this->namespace[$ns]['data'][$key] = $value;
}
}

View file

@ -10,12 +10,12 @@
* Имя необходимо чтобы потом легко было удалить ненужные ветки дерева
*/
namespace ctiso;
use ctiso\Collection,
ctiso\File,
use ctiso\File,
Exception;
class Settings extends Collection
class Settings
{
public $data;
protected $file;
protected $format = 'php';
@ -45,7 +45,8 @@ class Settings extends Collection
if (!is_array($settings)) {
throw new Exception($this->file);
}
return $this->import($settings);
$this->data = $settings;
}
/**
@ -175,11 +176,20 @@ class Settings extends Collection
file_put_contents (($file) ? $file : $this->file, $result);
}
/**
* Список модулей
*/
public function getModules()
public function set($key, $value) {
$this->data[$key] = $value;
}
public function get($key, $default = null)
{
return array_keys($this->data);
return isset($this->data[$key]) && $this->data[$key] != '' ? $this->data[$key] : $default;
}
function export() {
return $this->data;
}
function import($data) {
$this->data = $data;
}
}

View file

@ -32,7 +32,7 @@ class Tales_Component implements PHPTAL_Tales
}
class Tales {
static $site;
static /*.Site.*/$site;
static function phptal_date ($e) {
return date("d.m.Y", $e);

View file

@ -4,7 +4,7 @@ namespace ctiso;
class Url {
public $parts = [];
public $parent;
public /*.Url.*/$parent;
function __construct() {
}

View file

@ -30,7 +30,7 @@ class Count extends AbstractRule
$count = count(array_filter(array_map('trim',
explode(";", $container->get($this->field))), array($this, 'not_empty')));
return $count >= $this->size && $count <= $this->max;
return $count >= $this->size && $count <= ((int)$this->max);
}
}

View file

@ -2,7 +2,7 @@
namespace ctiso\View;
use ctiso\View\View,
App\Controller\Site,
App\Controller\Site, /* Нужно импортровать интерфейс */
ctiso\Controller\Component,
ctiso\HttpRequest;
@ -10,7 +10,7 @@ class Page extends View
{
private $counter;
public $text;
public $site;
public /*.Site.*/$site;
function __construct($data, $site)
{
@ -55,8 +55,7 @@ class Page extends View
function replaceContent($match, $offset)
{
/*.Component.*/$component = null;
$component = $this->site->loadComponent($match);
/*.Component.*/$component = $this->site->loadComponent($match);
$req = new HttpRequest();
unset($req['active_page']);

View file

@ -29,7 +29,7 @@ class Top extends Composite {
private function groupFiles(array $list, $debugMode = true)
{
$debug = ($debugMode) ? 'debug=1' : '';
$path = parse_url(WWW_PATH, PHP_URL_PATH);
$path = parse_url($this->config->get('system', 'web'), PHP_URL_PATH);
$groups = array();
$use = array();
@ -120,7 +120,7 @@ class Top extends Composite {
$this->set('deps', implode(",", array_values($this->require)));
$this->set('title', $this->getTitle());
$this->set('jspath', enableHttps(WWW_PATH));
$this->set('jspath', enableHttps($this->config->get('system', 'web')));
//
return $this->execute(); // execute+phptal ??
}

View file

@ -2,6 +2,6 @@
namespace ctiso;
class WrongRequestException extends Exception
class WrongRequestException extends \Exception
{
}