diff --git a/src/ComponentRequest.php b/src/ComponentRequest.php new file mode 100644 index 0000000..3d56041 --- /dev/null +++ b/src/ComponentRequest.php @@ -0,0 +1,35 @@ +component_id = $c; + $this->r = $r; + } + + function get($key, $default = null) { + if ($key == 'active_page') { + return $this->r->get($key); + } + if ($arr = $this->r->get($key)) { + if (is_array($arr)) { + return Arr::get($arr, $this->component_id, $default); + } else { + return $arr; + } + } + return $default; + } + + function getAction() { + return $this->r->getAction(); + } +} \ No newline at end of file diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 750b25e..ca3a547 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -10,6 +10,8 @@ use ctiso\Shortcut, ctiso\HttpRequest, ctiso\Functions, ctiso\Settings, + ctiso\View\Composite, + ctiso\View\View, ctiso\Controller\State; /** @@ -82,18 +84,15 @@ class Action return Path::join($basePath, "modules", $name); } - public function addSuggest(View $view, $name) - { + public function addSuggest(View $view, $name) { $suggest = array(); $file = Path::join($this->modulePath, 'help', $name . '.suggest'); if (file_exists($file)) { - include($file); - $view->suggestions = $suggest; + $view->suggestions = include($file); } } - function findIcon($icon, $size) - { + function findIcon($icon, $size) { $webPath = $this->settings['web']; return Path::join($webPath, 'icons', $size . 'x' . $size, $icon . '.png'); } @@ -122,7 +121,7 @@ class Action if(file_exists($template)) { break; } } - /*.View_Composite.*/$tpl = new $viewClass($template); + /*.Composite.*/$tpl = new $viewClass($template); $stylePath = Path::join($webPath, "assets", "css"); $iconsPath = Path::join($webPath, 'icons'); @@ -170,7 +169,7 @@ class Action $action = "actionIndex"; } $view = $this->forward($action, $request); - if ($view instanceof View_View) { + if ($view instanceof View) { $view->active_module = get_class($this); $view->module_action = $action; } @@ -208,7 +207,7 @@ class Action */ public function nUrl($name, array $param = array()) { - /*.Filter_ActionAccess.*/$access = $this->access; + /*.ActionAccess.*/$access = $this->access; if ($access == null || $access->checkAction($name)) { $param = array_merge(array( @@ -295,12 +294,12 @@ class Action /** * Добавление widget к отображению */ - public function addChild(/*Widgets_Widget*/ $section, $node) + public function addChild($section, $node) { $this->childNodes[$section] = $node; } - public function setValue(/*Widgets_Widget*/ $name, $value) + public function setValue($name, $value) { $this->ctrlValues[$name] = $value; } @@ -308,7 +307,7 @@ class Action /** * Добавление дочернего отображения к текущему отображению */ - public function addView(/*CompositeView*/ $section, $node) + public function addView($section, $node) { $this->childViews[$section] = $node; } @@ -322,7 +321,7 @@ class Action if ($this->view instanceof View_View) { $this->view->assignValues($this->ctrlValues); - /*.Widgets_Widget.*/$node = null; + /*.Composite.*/$node = null; foreach ($this->childNodes as $name => $node) { $node->make($this); $this->view->setView($name, $node->view); @@ -335,8 +334,7 @@ class Action return $this->view; } - function getPageId(HttpRequest $request) - { + function getPageId(HttpRequest $request) { $pageId = time(); $request->session()->set('page', $pageId); return $pageId; @@ -353,19 +351,17 @@ class Action return $result; } - function _getActionPath() - { + function _getActionPath() { return new State('index'); } // Тоже убрать в метод Controller_Model - function getActionPath(HttpRequest $request, $action = null) - { + function getActionPath(HttpRequest $request, $action = null) { $this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction()); } function redirect($action) { - header('location: ' . $this->fUrl($action)); + header('location: ' . $action->toString()); exit(); } } diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 1fcc8a8..1e94b27 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -2,16 +2,19 @@ namespace ctiso\Controller; use ctiso\HttpRequest, + ctiso\ComponentRequest, ctiso\Arr, ctiso\Path, - PHPTAL, - PHPTAL_PreFilter_Normalize, ctiso\File, ctiso\Form\Form, ctiso\Form\OptionFactory, ctiso\Database, + ctiso\Database\PDOStatement, ctiso\Collection, - ctiso\Controller\Site; + ctiso\Settings, + App\Controller\Site, + PHPTAL, + PHPTAL_PreFilter_Normalize; function replaceContent($match) { $result = Tales\Component::phptal_component(htmlspecialchars_decode($match[3])); @@ -22,35 +25,6 @@ function applyComponents($text) { return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'replaceContent', $text); } -class ComponentRequest { - public $component_id; - public $component_title; - public $r; - - function __construct($c, HttpRequest $r) { - $this->component_id = $c; - $this->r = $r; - } - - function get($key, $default = null) { - if ($key == 'active_page') { - return $this->r->get($key); - } - if ($arr = $this->r->get($key)) { - if (is_array($arr)) { - return Arr::get($arr, $this->component_id, $default); - } else { - return $arr; - } - } - return $default; - } - - function getAction() { - return $this->r->getAction(); - } -} - class FakeTemplate { public $_data = []; public $_name = ''; @@ -183,7 +157,7 @@ class Component return $model; } - public function options($key, $val, /*.Database_PDOStatement.*/$res) { + public function options($key, $val, /*.PDOStatement.*/$res) { $result = array(); while($res->next()) { $result[] = array('value' => $res->getString($key), 'name' => $res->getString($val)); @@ -221,7 +195,7 @@ class Component /** * Генерация интерфейса для выбора галлереи фотографии */ - public function setParameters(/*.View_Composite.*/$view) + public function setParameters(/*.Composite.*/$view) { $form = new Form(); $options = new OptionFactory($this->db, $this->registry); @@ -234,7 +208,7 @@ class Component $view->component_title = $settings['title']; } - static function loadComponent($expression, Database $db, /*.Registry.*/ $registry) + static function loadComponent($expression, Database $db, /*.Settings.*/ $registry) { $expression = htmlspecialchars_decode($expression); @@ -254,7 +228,7 @@ class Component $path = Path::join (BASE_PATH, 'components', $name, $name . '.php'); $className = 'Component_' . $name; - /*.Controller_Component.*/$component = null; + /*.Component.*/$component = null; if (file_exists($path)) { require_once ($path); @@ -313,7 +287,7 @@ class Component $editor = $component->getEditUrl(); if ($editor) { - if(class_exists("Controller_Site")) { //Если мы в CMS2 + if (class_exists("Controller_Site")) { //Если мы в CMS2 $instance = Site::getInstance(); $instance->componentsConfig[] = $editor; } else { diff --git a/src/Controller/Front.php b/src/Controller/Front.php index b9fa014..9e55c82 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -98,7 +98,7 @@ class Front extends Action return $this->loadModule($name[0], $request, $controller); } catch (UserMessageException $ex) { //Исключение с понятным пользователю сообщением $mode = $request->get('mode'); - if($mode == 'ajax' || $mode == 'json') { + if ($mode == 'ajax' || $mode == 'json') { return json_encode(['result'=>'fail', 'message'=> $ex->userMessage]); } else { return $ex->userMessage; diff --git a/src/Controller/Request.php b/src/Controller/Request.php index 50a3039..e67ed7d 100644 --- a/src/Controller/Request.php +++ b/src/Controller/Request.php @@ -1,6 +1,7 @@ next()) { $result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val)); diff --git a/src/Database.php b/src/Database.php index 0a8e103..bd013e0 100644 --- a/src/Database.php +++ b/src/Database.php @@ -12,6 +12,7 @@ namespace { namespace ctiso { use PDO, ctiso\Database\Statement, + ctiso\Database\PDOStatement, ctiso\Database\IdGenerator; /** @@ -61,7 +62,7 @@ class Database extends PDO public function executeQuery($query, $values=null) { - /*.Database_PDOStatement.*/$stmt = $this->prepare($query); + /*.PDOStatement.*/$stmt = $this->prepare($query); $stmt->execute($values); $stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -79,7 +80,7 @@ class Database extends PDO */ public function fetchAllArray($query, $values = null) { - /*.Database_PDOStatement.*/$sth = $this->prepare($query); + /*.PDOStatement.*/$sth = $this->prepare($query); $prep = $this->prepareValues($values); $sth->execute($prep); return $sth->fetchAll(PDO::FETCH_ASSOC); @@ -90,7 +91,7 @@ class Database extends PDO */ public function fetchOneArray($query, $values = null) { - /*.Database_PDOStatement.*/$sth = $this->prepare($query); + /*.PDOStatement.*/$sth = $this->prepare($query); $prep = $this->prepareValues($values); $sth->execute($prep); return $sth->fetch(PDO::FETCH_ASSOC); @@ -180,9 +181,12 @@ class Database extends PDO return $result['nextval']; } - function close() - { + function prepare($query) { + /*.PDOStatement.*/$result = $this->prepare($query); + return $result; + } + + function close() { return null; } -} -} \ No newline at end of file +}} diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 48e591a..7d5b3fe 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -3,6 +3,7 @@ namespace ctiso\Database; use ctiso\Database\StatementIterator, + ctiso\Tools\StringUtil, PDO; class PDOStatement extends \PDOStatement implements \IteratorAggregate @@ -91,7 +92,7 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate } function getArray($name) { - return strToArray($this->fields[$name]); + return StringUtil::strToArray($this->fields[$name]); } function getRecordCount() { diff --git a/src/Database/Statement.php b/src/Database/Statement.php index 69d7cf2..f47278f 100644 --- a/src/Database/Statement.php +++ b/src/Database/Statement.php @@ -4,7 +4,8 @@ * Класс оболочка для PDOStatement для замены Creole */ namespace ctiso\Database; -use PDO; +use PDO, + ctiso\Database; class Statement { @@ -50,7 +51,7 @@ class Statement if ($this->limit) { $this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}"; } - /*.Database_PDOStatement.*/$stmt = $this->conn->prepare($this->query); + /*.PDOStatement.*/$stmt = $this->conn->prepare($this->query); foreach ($this->binds as $bind) { list($n, $value, $type) = $bind; $stmt->bindValue($n, $value, (int) $type); diff --git a/src/Database/StatementIterator.php b/src/Database/StatementIterator.php index 02a5c3a..6286a6d 100644 --- a/src/Database/StatementIterator.php +++ b/src/Database/StatementIterator.php @@ -3,7 +3,7 @@ namespace ctiso\Database; use PDO; -class StatementIterator implements Iterator +class StatementIterator implements \Iterator { private $result; @@ -11,7 +11,7 @@ class StatementIterator implements Iterator private $fetchmode; private $row_count; - public function __construct(/*.Database_PDOStatement.*/ $rs) { + public function __construct(/*.PDOStatement.*/ $rs) { $this->result = $rs; $this->row_count = $rs->getRecordCount(); } diff --git a/src/Excel/Table.php b/src/Excel/Table.php index bb28499..1861a36 100644 --- a/src/Excel/Table.php +++ b/src/Excel/Table.php @@ -4,6 +4,7 @@ * Клетка таблицы */ namespace ctiso\Excel; +use XMLWriter; class TableCell { @@ -310,4 +311,3 @@ class Table $doc->endElement(); } } - diff --git a/src/Filter/ActionAccess.php b/src/Filter/ActionAccess.php index 0bb031c..da01325 100644 --- a/src/Filter/ActionAccess.php +++ b/src/Filter/ActionAccess.php @@ -12,7 +12,7 @@ class ActionAccess public $access = array(); public $processor; - function __construct(/*.Filter_Filter.*/$processor) { + function __construct(/*.Filter.*/$processor) { $this->processor = $processor; } @@ -23,7 +23,7 @@ class ActionAccess */ function checkAction($action) { // Импликация !! http://ru.wikipedia.org/wiki/Импликация - return (!isset($this->access[$action]) || in_array(UserAccess::$access, $this->access[$action])); + return (!isset($this->access[$action]) || in_array($this->user->access, $this->access[$action])); } function execute(HttpRequest $request) { diff --git a/src/Filter/ActionLogger.php b/src/Filter/ActionLogger.php index 4718da8..d7da199 100644 --- a/src/Filter/ActionLogger.php +++ b/src/Filter/ActionLogger.php @@ -11,7 +11,7 @@ class ActionLogger public $action; public $processor; - function __construct(/*.Filter_Filter.*/$processor, $logPath, $user) { + function __construct(/*.Filter.*/$processor, $logPath, $user) { $this->processor = $processor; $this->user = $user; $this->file = fopen($logPath, "a"); diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index b61b5c8..864e898 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -4,12 +4,14 @@ * Попытка реализовать фильтр для запросов */ namespace ctiso\Filter; -use ctiso\HttpRequest; + +use ctiso\Controller\Action, + ctiso\HttpRequest; class Filter { public $processor; - public function __construct(/*.Controller_Action.*/$processor) + public function __construct(/*.Action.*/$processor) { $this->processor = $processor; } diff --git a/src/Filter/Login.php b/src/Filter/Login.php index eb94070..851e966 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -19,8 +19,11 @@ class Login extends Filter { const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; + public $mode = 'ajax'; public $user; + public $role; + public $whitelist; function __construct($processor, $role, $whitelist = []) { parent::__construct($processor); @@ -63,7 +66,7 @@ class Login extends Filter if ($result) { $temp = md5($result->getString('password') . $result->getString('login') . $result->getString('sid')); if ($password == $temp) { - $this->enter($db, $result); + $this->enter($result); return true; } } diff --git a/src/Form/OptionFactory.php b/src/Form/OptionFactory.php index 70904bb..42ae288 100644 --- a/src/Form/OptionFactory.php +++ b/src/Form/OptionFactory.php @@ -2,7 +2,7 @@ namespace ctiso\Form; use ctiso\Form\Select, - ctiso\Model\Resources, + App\Model\Resources, ctiso\Model\Factory; class OptionFactory { diff --git a/src/Model/Factory.php b/src/Model/Factory.php index 868da5a..2e57587 100644 --- a/src/Model/Factory.php +++ b/src/Model/Factory.php @@ -1,7 +1,8 @@ stack[count($this->stack) - 1]; + /*.\SimpleXMLElement.*/$item = $this->stack[count($this->stack) - 1]; $root = $item->children(); foreach ($root as $node) { diff --git a/src/Tales.php b/src/Tales.php index c3f2155..58a341d 100644 --- a/src/Tales.php +++ b/src/Tales.php @@ -5,7 +5,7 @@ */ namespace ctiso; use PHPTAL_Php_TalesInternal, - ctiso\Controller\Site, + App\Controller\Site, ctiso\Controller\Component, ctiso\HttpRequest, PHPTAL_Tales, @@ -48,7 +48,7 @@ class Tales { */ static function phptal_component ($expression) { $begin = floatval(microtime(true)); - /*.Controller_Component.*/$component = null; + /*.Component.*/$component = null; if (class_exists("ctiso\\Controller\\Site")) { //Если мы в CMS2 $component = Site::loadComponent($expression); diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index fbde7c1..fad2434 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -122,7 +122,7 @@ class TemplateImage return ""; } - function imageText($text, /*.stdClass.*/$value) + function imageText($text, /*.\stdClass.*/$value) { assert(is_string($text)); diff --git a/src/Url.php b/src/Url.php index 3137d16..f52baec 100644 --- a/src/Url.php +++ b/src/Url.php @@ -3,6 +3,8 @@ namespace ctiso; class Url { + public $parts; + function __construct($parts = []) { $this->parts = $parts; } diff --git a/src/Validator/Rule/Abstract.php b/src/Validator/Rule/AbstractRule.php similarity index 92% rename from src/Validator/Rule/Abstract.php rename to src/Validator/Rule/AbstractRule.php index 15e6cb9..4ab8307 100644 --- a/src/Validator/Rule/Abstract.php +++ b/src/Validator/Rule/AbstractRule.php @@ -1,9 +1,9 @@ Rule_Abstract + public function skip(/*.AbstractRule.*/$rule, /*.Collection.*/$container) // -> Rule_Abstract { if ($rule->skipEmpty()) { $data = $container->get($rule->field); diff --git a/src/View/List.php b/src/View/ListView.php similarity index 89% rename from src/View/List.php rename to src/View/ListView.php index 45ca726..16945ff 100644 --- a/src/View/List.php +++ b/src/View/ListView.php @@ -3,7 +3,7 @@ namespace ctiso\View; use ctiso\View\View; -class List extends View +class ListView extends View { function execute() { diff --git a/src/View/Page.php b/src/View/Page.php index 2c0a4ab..10e40ec 100644 --- a/src/View/Page.php +++ b/src/View/Page.php @@ -2,7 +2,7 @@ namespace ctiso\View; use ctiso\View\View, - ctiso\Controller\Site, + App\Controller\Site, ctiso\Controller\Component, ctiso\HttpRequest; @@ -54,10 +54,9 @@ class Page extends View function replaceContent($match, $offset) { //$result = phptal_component($match, $offset); - /*.Controller_Component.*/$component = null; + /*.Component.*/$component = null; - - if(class_exists("Controller_Site")){ //Если мы в CMS2 + if (class_exists("App\\Controller\\Site")) { //Если мы в CMS2 $component = Site::loadComponent($match); } else { global $db, $registry; // diff --git a/src/View/Top.php b/src/View/Top.php index 3c2ed6c..eb67c02 100644 --- a/src/View/Top.php +++ b/src/View/Top.php @@ -102,7 +102,7 @@ class Top extends Composite { $init = array(); foreach($s->_section as $key => $item) { - /*.View_View.*/$ss = $item; + /*.View.*/$ss = $item; if ($ss->codeGenerator !== null) { // функцию которая вычисляет а не результат $part = call_user_func($ss->codeGenerator, $this, $key, $value);