diff --git a/src/Controller/Front.php b/src/Controller/Front.php index d5e6d12..ed9148a 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -78,10 +78,11 @@ class Front extends Action $module->front = $this; // Ведение лога $logger = new ActionLogger($module, $logPath, $this->user); - $logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php')); + $filename = Path::join($modPath, 'filters', 'logger.json'); + $logger->before = $this->loadSettings($filename); // Управление доступом $module->access = new ActionAccess($logger, $this->user); - $module->access->access = $this->loadSettings(Path::join($modPath, 'filter', 'access.php')); + $module->access->access = $this->loadSettings(Path::join($modPath, 'filters', 'access.json')); $module->setUp(); diff --git a/src/Controller/Installer.php b/src/Controller/Installer.php index 2adff19..72be02b 100644 --- a/src/Controller/Installer.php +++ b/src/Controller/Installer.php @@ -28,14 +28,14 @@ class Installer return $setup; } - function getUninstallFile($name){ + function getUninstallFile($name) { return Path::join(call_user_func($this->installPath, $name), "sql", "uninstall.json"); } // Проверка версии обновления function isChanged($name) // Информация о модулях { - $item = $this->_registry->get('system', $name); + $item = $this->_registry->get($name); if ($item) { $setup = $this->getSetupFile($name); if (file_exists($setup) && (filemtime($setup) > $item['time'])) { @@ -78,10 +78,11 @@ class Installer if (file_exists($setup) && ($this->isChanged($name) || $force)) { $registry = $this->_registry; + $settings = new Settings($setup); $settings->read(); - $item = $registry->get('system', $name); + $item = $registry->get($name); $version_new = $settings->get('version'); if ($item) { @@ -106,7 +107,7 @@ class Installer 'version' => $version_new, 'time' => filemtime($setup) ]); - $registry->writeKey([$name], $settings->get('settings')); + // $registry->writeKey([$name], $settings->export()); $registry->write(); } diff --git a/src/Database/JsonInstall.php b/src/Database/JsonInstall.php index 9fc0c2f..eef8f8b 100644 --- a/src/Database/JsonInstall.php +++ b/src/Database/JsonInstall.php @@ -63,8 +63,10 @@ class JsonInstall { $table_name = $action["table_name"]; if (isset($refs[$table_name])) { foreach ($refs[$table_name] as $value) { - $action['fields'][$value['column']]['references'] = - $value['refTable']."(".$value['refColumn'].")"; + $action['fields'][$value['column']]['references'] = [ + "refTable" => $value['refTable'], + 'refColumn' => $value['refColumn'] + ]; } } diff --git a/src/Database/Manager.php b/src/Database/Manager.php index 669b570..9e8c044 100644 --- a/src/Database/Manager.php +++ b/src/Database/Manager.php @@ -145,7 +145,7 @@ class Manager $constraint = isset($data['constraint']) ? " ".$data['constraint'] : ""; $references = ""; if (isset($data['references'])) { - $references = " REFERENCES ".$data['references']; + $references = " REFERENCES " . $data['references']['refTable'] . '(' .$data['references']['refColumn'] . ')'; } if (isset($data["not_null"]) && $data["not_null"]) { $constraint .=" NOT NULL"; diff --git a/src/Filter/Login.php b/src/Filter/Login.php index e17205b..a6591bd 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -202,7 +202,7 @@ class Login extends Filter $module = $request->get('module'); $action = $request->get('action'); - $moduleDir = explode('_',$module)[0]; + $moduleDir = explode('\\',$module)[0]; $file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json'); if (file_exists($file)) { $whiteList = json_decode(file_get_contents($file), true); diff --git a/src/Tales.php b/src/Tales.php index 5937db2..7cbd91c 100644 --- a/src/Tales.php +++ b/src/Tales.php @@ -51,7 +51,7 @@ class Tales { return date("H:i", $e); } - static function phptal_asset($s) { + static function phptal_asset($s) { self::$site->addStyleSheet($s); return ""; } @@ -59,7 +59,7 @@ class Tales { /** * Функция подключения компонента */ - static function phptal_component ($expression) { + static function phptal_component($expression) { $begin = floatval(microtime(true)); $component/*: Component*/ = null; diff --git a/src/Validator/Rule/PregMatch.php b/src/Validator/Rule/PregMatch.php new file mode 100644 index 0000000..3d400bb --- /dev/null +++ b/src/Validator/Rule/PregMatch.php @@ -0,0 +1,21 @@ +pattern,$container->get($this->field)); + } +} diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 88fd870..1d625e0 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -3,7 +3,7 @@ /// /** - * Проверка коллекции + * Проверка коллекции */ namespace ctiso\Validator; use Exception, @@ -14,35 +14,39 @@ class Validator { protected $chain = array(); // Массив правил protected $errorMsg = array(); // Массив ошибок + protected $type = array( + 'date' => 'ctiso\\Validator\\Rule\\Date', + 'email' => 'ctiso\\Validator\\Rule\\Email', + 'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList', + 'match' => 'ctiso\\Validator\\Rule\\MatchRule', + 'time' => 'ctiso\\Validator\\Rule\\Time', + 'alpha' => 'ctiso\\Validator\\Rule\\Alpha', + 'require' => 'ctiso\\Validator\\Rule\\Notnull', + 'numeric' => 'ctiso\\Validator\\Rule\\Numeric', + 'unique' => 'ctiso\\Validator\\Rule\\Unique', + 'filename' => 'ctiso\\Validator\\Rule\\FileName', + 'count' => 'ctiso\\Validator\\Rule\\Count', + 'isfile' => 'ctiso\\Validator\\Rule\\IsFile', + 'code' => 'ctiso\\Validator\\Rule\\Code', + 'reg' => 'ctiso\\Validator\\Rule\\PregMatch', + ); function __construct($rules = array()) { $this->addRuleList($rules); } + function addRuleType($name, $className) { + $this->type[$name] = $className; + } + /** * Добавление списка правил в специальном формате * array(array('name' => fieldname, 'validate' => ruletext), ...) - * fieldname - Имя переменой для проверки + * fieldname - Имя переменой для проверки * ruletext - Описание правила см. формат правила ниже */ public function addRuleList(array $input) { - $type = array( - 'date' => 'ctiso\\Validator\\Rule\\Date', - 'email' => 'ctiso\\Validator\\Rule\\Email', - 'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList', - 'match' => 'ctiso\\Validator\\Rule\\MatchRule', - 'time' => 'ctiso\\Validator\\Rule\\Time', - 'alpha' => 'ctiso\\Validator\\Rule\\Alpha', - 'require' => 'ctiso\\Validator\\Rule\\Notnull', - 'numeric' => 'ctiso\\Validator\\Rule\\Numeric', - 'unique' => 'ctiso\\Validator\\Rule\\Unique', - 'filename' => 'ctiso\\Validator\\Rule\\FileName', - 'count' => 'ctiso\\Validator\\Rule\\Count', - 'isfile' => 'ctiso\\Validator\\Rule\\IsFile', - 'code' => 'ctiso\\Validator\\Rule\\Code' - ); - // Разбор правила проверки // Формат правила 'rule1|rule2,param1=value1|rule3,param1=value1,param2=value2' foreach ($input as $value) { @@ -55,8 +59,8 @@ class Validator $rule_param = explode(",", $rule); $name = array_shift($rule_param); - if (isset($type[$name])) { - $constructor = $type[$name]; + if (isset($this->type[$name])) { + $constructor = $this->type[$name]; $ruleObj = new $constructor($value['name'], false); // Нужны шаблонные сообщения для правил if (isset($value['context'])) { $ruleObj->setContext($value['context']); @@ -74,15 +78,15 @@ class Validator } } - public function addRule($rule/*: any*/) { + public function addRule($rule/*:z any*/) { if (is_array($rule)) { $this->chain = array_merge($this->chain, $rule); } else { $this->chain[] = $rule; } } - - public function skip($rule/*: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract + + public function skip($rule/*z: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract { if ($rule->skipEmpty()) { $data = $container->get($rule->field); @@ -90,10 +94,10 @@ class Validator $value = trim($data); return $value == ''; } - } + } return false; } - + public function validate(Collection $container, $rule = null, $status = null) { $fields = array(); diff --git a/src/View/View.php b/src/View/View.php index 088cd43..a30e9fa 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -15,8 +15,9 @@ class View protected $_title = null; // Заголовок текущего шаблона - public $active_module; - public $module_action; + public $active_module; + public $module_action; + public $prefix; public $suggestions; //подсказки @@ -59,7 +60,7 @@ class View */ public function addScript($name) { - $output = $this->resolveName($this->alias, $name); + $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix)); $this->_script [] = $output; } @@ -77,6 +78,10 @@ class View } } + public function setPrefix($name, $val) { + $this->prefix[$name] = $val; + } + /** * Добавляет стили к текущему шаблону * @@ -84,8 +89,8 @@ class View */ public function addStyleSheet($name) { - $output = $this->resolveName($this->alias, $name); - $this->_stylesheet [] = $output; + $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix)); + $this->_stylesheet [] = $output; } /**