Изменен механизм расширения ссылок. Избавление от глобальных переменных
This commit is contained in:
parent
524b27936a
commit
40fad0e75b
11 changed files with 77 additions and 61 deletions
|
|
@ -5,12 +5,12 @@ use ctiso\Shortcut,
|
|||
Exception,
|
||||
ctiso\Path,
|
||||
ctiso\Url,
|
||||
ctiso\View\View,
|
||||
ctiso\Model\Factory,
|
||||
ctiso\HttpRequest,
|
||||
ctiso\Functions,
|
||||
ctiso\Settings,
|
||||
ctiso\View\Composite,
|
||||
ctiso\Filter\ActionAccess,
|
||||
ctiso\View\View,
|
||||
ctiso\Controller\State;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ class Action
|
|||
|
||||
private $factory = null; // Ссылка на обьект создания модели
|
||||
private $helpers = array(); // Помошники для действий
|
||||
public $param = array(); // Параметры для ссылки
|
||||
public $part = null; // Параметры для ссылки
|
||||
|
||||
public /*.Settings.*/$settings; // Ссылка на настройки
|
||||
public $user; // Обьект пользователя
|
||||
|
|
@ -55,6 +55,7 @@ class Action
|
|||
public $childViews = array();
|
||||
|
||||
function __construct() {
|
||||
$this->part = new Url();
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
|
|
@ -198,6 +199,10 @@ class Action
|
|||
return "";
|
||||
}
|
||||
|
||||
public function addUrlPart($key, $value) {
|
||||
$this->part->addQueryParam($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация ссылки c учетом прав пользователя на ссылки
|
||||
* @param string $name Действие
|
||||
|
|
@ -208,16 +213,20 @@ class Action
|
|||
public function nUrl($name, array $param = array())
|
||||
{
|
||||
/*.ActionAccess.*/$access = $this->access;
|
||||
$url = new Url();
|
||||
|
||||
if ($access == null || $access->checkAction($name)) {
|
||||
$param = array_merge(array(
|
||||
'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')),
|
||||
"action" => $name
|
||||
|
||||
), $param);
|
||||
|
||||
return new Url($param);
|
||||
$url->setParent($this->part);
|
||||
$url->setQuery($param);
|
||||
}
|
||||
return new Url();
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -318,7 +327,7 @@ class Action
|
|||
*/
|
||||
public function render()
|
||||
{
|
||||
if ($this->view instanceof View_View) {
|
||||
if ($this->view instanceof View) {
|
||||
$this->view->assignValues($this->ctrlValues);
|
||||
|
||||
/*.Composite.*/$node = null;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use ctiso\HttpRequest,
|
|||
ctiso\File,
|
||||
ctiso\Form\Form,
|
||||
ctiso\Form\OptionFactory,
|
||||
ctiso\View\Composite,
|
||||
ctiso\Database,
|
||||
ctiso\Database\PDOStatement,
|
||||
ctiso\Collection,
|
||||
|
|
@ -38,7 +39,7 @@ class FakeTemplate {
|
|||
}
|
||||
|
||||
function execute() {
|
||||
return $this->_data;
|
||||
return json_encode($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +65,7 @@ class Component
|
|||
|
||||
public $module;
|
||||
public $item_module;
|
||||
public $site;
|
||||
|
||||
function before() {
|
||||
}
|
||||
|
|
@ -95,7 +97,6 @@ class Component
|
|||
return new FakeTemplate($name);
|
||||
}
|
||||
|
||||
//
|
||||
/*.Settings.*/$registry = $this->registry;
|
||||
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
|
||||
|
||||
|
|
@ -208,7 +209,7 @@ class Component
|
|||
$view->component_title = $settings['title'];
|
||||
}
|
||||
|
||||
static function loadComponent($expression, Database $db, /*.Settings.*/ $registry)
|
||||
static function loadComponent($expression, /*.Site.*/ $site)
|
||||
{
|
||||
|
||||
$expression = htmlspecialchars_decode($expression);
|
||||
|
|
@ -232,22 +233,16 @@ class Component
|
|||
|
||||
if (file_exists($path)) {
|
||||
require_once ($path);
|
||||
|
||||
$component = new $className();
|
||||
$component->db = $db;
|
||||
$component->registry = $registry;
|
||||
|
||||
$component->viewPath = array(BASE_PATH . '/components/' . $name . '/');
|
||||
$component->webPath = array(SITE_WWW_PATH . '/components/' . $name);
|
||||
|
||||
$component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/';
|
||||
|
||||
} else {
|
||||
$path = Path::join (COMPONENTS, $name, $name . '.php');
|
||||
require_once ($path);
|
||||
$component = new $className();
|
||||
$component->db = $db;
|
||||
$component->registry = $registry;
|
||||
|
||||
$component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/');
|
||||
if (defined('COMPONENTS_WEB')) {
|
||||
|
|
@ -256,6 +251,12 @@ class Component
|
|||
}
|
||||
}
|
||||
|
||||
$db = $site->db;
|
||||
|
||||
$component->db = $db;
|
||||
$component->registry = $site->registry;
|
||||
$component->site = $site;
|
||||
|
||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
||||
$stmt->setString(1, $expression);
|
||||
$cid = $stmt->executeQuery();
|
||||
|
|
@ -282,18 +283,13 @@ class Component
|
|||
|
||||
$params = new Collection();
|
||||
$params->import($arguments);
|
||||
|
||||
$component->parameter = $params;
|
||||
$component->template = $params->get('template', false);
|
||||
|
||||
$editor = $component->getEditUrl();
|
||||
if ($editor) {
|
||||
if (class_exists("Controller_Site")) { //Если мы в CMS2
|
||||
$instance = Site::getInstance();
|
||||
$instance->componentsConfig[] = $editor;
|
||||
} else {
|
||||
global $componentsConfig;
|
||||
$componentsConfig[] = $editor;
|
||||
}
|
||||
$site->componentsConfig[] = $editor;
|
||||
}
|
||||
|
||||
return $component;
|
||||
|
|
@ -338,12 +334,8 @@ class Component
|
|||
return '?' . http_build_query($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated В CMS2 перенесено в контроллер сайта!
|
||||
*/
|
||||
|
||||
function addRequireJsPath($name, $path, $shim = null) {
|
||||
Site::addRequireJsPath($name, $path, $shim);
|
||||
$this->site->addRequireJsPath($name, $path, $shim);
|
||||
}
|
||||
|
||||
function actionIndex(/*.ComponentRequest.*/ $request) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Front extends Action
|
|||
return $module->access->execute($request);
|
||||
}
|
||||
|
||||
$system = $this->settings['system'];
|
||||
/*.Settings.*/$system = $this->settings['system'];
|
||||
|
||||
$moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules']));
|
||||
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
|
||||
|
|
|
|||
|
|
@ -181,8 +181,8 @@ class Database extends PDO
|
|||
return $result['nextval'];
|
||||
}
|
||||
|
||||
function prepare($query) {
|
||||
/*.PDOStatement.*/$result = $this->prepare($query);
|
||||
function prepare($query, $options = NULL) {
|
||||
/*.PDOStatement.*/$result = parent::prepare($query);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace ctiso\Filter;
|
||||
use ctiso\HttpRequest;
|
||||
|
||||
/* Переделать формат Логов на список json */
|
||||
class ActionLogger
|
||||
{
|
||||
public $before = array();
|
||||
|
|
@ -14,13 +15,19 @@ class ActionLogger
|
|||
function __construct(/*.Filter.*/$processor, $logPath, $user) {
|
||||
$this->processor = $processor;
|
||||
$this->user = $user;
|
||||
$this->file = fopen($logPath, "a");
|
||||
$file = fopen($logPath, "a");
|
||||
if (is_resource($file)) {
|
||||
$this->file = $file;
|
||||
} else {
|
||||
throw new \Exception('Ошибка открытия файла ' . $logPath);
|
||||
}
|
||||
}
|
||||
|
||||
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: " . $this->user->name . "\n");
|
||||
$message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->name];
|
||||
fwrite($this->file, json_encode($message) . "\n");
|
||||
}
|
||||
return $this->processor->execute($request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ class Login extends Filter
|
|||
/* ---------------------
|
||||
* Проверка на попадание реквеста в белый список
|
||||
*/
|
||||
public function requestIsWhite(Collection $request, $whiteRequestList){
|
||||
public function requestIsWhite(HttpRequest $request, $whiteRequestList){
|
||||
$module = $request->get('module');
|
||||
$action = $request->get('action');
|
||||
foreach ($whiteRequestList as $whiteRequest) {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ use Exception,
|
|||
ctiso\Collection,
|
||||
ctiso\Session;
|
||||
|
||||
class WrongRequestException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
// HTTPRequest = ArrayAccess
|
||||
class HttpRequest extends Collection implements ArrayAccess
|
||||
{
|
||||
|
|
@ -132,4 +128,8 @@ class HttpRequest extends Collection implements ArrayAccess
|
|||
|
||||
public function offsetGet($key) {
|
||||
}
|
||||
|
||||
static function getProtocol() {
|
||||
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ class Tales_Component implements PHPTAL_Tales
|
|||
}
|
||||
|
||||
class Tales {
|
||||
static $db;
|
||||
static $registry;
|
||||
static $site;
|
||||
|
||||
static function phptal_date ($e) {
|
||||
return date("d.m.Y", $e);
|
||||
|
|
@ -50,11 +49,7 @@ class Tales {
|
|||
$begin = floatval(microtime(true));
|
||||
/*.Component.*/$component = null;
|
||||
|
||||
if (class_exists("ctiso\\Controller\\Site")) { //Если мы в CMS2
|
||||
$component = Site::loadComponent($expression);
|
||||
} else {
|
||||
$component = Component::loadComponent($expression, self::$db, self::$registry);
|
||||
}
|
||||
$component = self::$site->loadComponent($expression);
|
||||
$req = new HttpRequest();
|
||||
$result = $component->execute($req);
|
||||
|
||||
|
|
@ -63,9 +58,8 @@ class Tales {
|
|||
}
|
||||
|
||||
|
||||
static function register($db, $registry) {
|
||||
self::$db = $db;
|
||||
self::$registry = $registry;
|
||||
static function register($site) {
|
||||
self::$site = $site;
|
||||
|
||||
/* Регистрация нового префикса для подключения компонента */
|
||||
$tales = PHPTAL_TalesRegistry::getInstance();
|
||||
|
|
|
|||
18
src/Url.php
18
src/Url.php
|
|
@ -3,13 +3,25 @@
|
|||
namespace ctiso;
|
||||
|
||||
class Url {
|
||||
public $parts;
|
||||
public $parts = [];
|
||||
public $parent;
|
||||
|
||||
function __construct($parts = []) {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function setParent($parent) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
function setQuery($parts) {
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
function addQueryParam($key, $value) {
|
||||
$this->parts[$key] = $value;
|
||||
}
|
||||
|
||||
function toString() {
|
||||
return '?' . http_build_query($this->parts);
|
||||
return '?' . http_build_query(array_merge($this->parts, $this->parent->parts));
|
||||
}
|
||||
}
|
||||
|
|
@ -10,9 +10,11 @@ class Page extends View
|
|||
{
|
||||
private $counter;
|
||||
public $text;
|
||||
public $site;
|
||||
|
||||
function __construct($data)
|
||||
function __construct($data, $site)
|
||||
{
|
||||
$this->site = $site;
|
||||
// Вставка компонентов на странице
|
||||
$pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u';
|
||||
$matches = array();
|
||||
|
|
@ -53,15 +55,8 @@ class Page extends View
|
|||
|
||||
function replaceContent($match, $offset)
|
||||
{
|
||||
//$result = phptal_component($match, $offset);
|
||||
/*.Component.*/$component = null;
|
||||
|
||||
if (class_exists("App\\Controller\\Site")) { //Если мы в CMS2
|
||||
$component = Site::loadComponent($match);
|
||||
} else {
|
||||
global $db, $registry; //
|
||||
$component = Component::loadComponent($match, $db, $registry);
|
||||
}
|
||||
$component = $this->site->loadComponent($match);
|
||||
|
||||
$req = new HttpRequest();
|
||||
unset($req['active_page']);
|
||||
|
|
|
|||
7
src/WrongRequestException.php
Normal file
7
src/WrongRequestException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso;
|
||||
|
||||
class WrongRequestException extends Exception
|
||||
{
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue