Другая интерпретация реестра
This commit is contained in:
parent
40fad0e75b
commit
aaa9c2e1bf
21 changed files with 156 additions and 92 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = ?");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Controller\Action;
|
||||
use ctiso\Controller\Action,
|
||||
ctiso\Url;
|
||||
|
||||
class State
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue