ref Исправление типов
This commit is contained in:
parent
a09fc396d8
commit
28429039a4
8 changed files with 24 additions and 98 deletions
|
|
@ -101,9 +101,9 @@ class Action
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Создает представление
|
* Создает представление
|
||||||
* @param $name String
|
* @param string
|
||||||
* @param $viewClass String
|
* @param string $viewClass
|
||||||
* @return View_Composite
|
* @return Composite
|
||||||
*/
|
*/
|
||||||
public function getView($name, $viewClass = 'ctiso\\View\\Composite')
|
public function getView($name, $viewClass = 'ctiso\\View\\Composite')
|
||||||
{
|
{
|
||||||
|
|
@ -163,7 +163,7 @@ class Action
|
||||||
* Т.к действия являются методами класса то
|
* Т.к действия являются методами класса то
|
||||||
* 1. Можно переопределить действия
|
* 1. Можно переопределить действия
|
||||||
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
|
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
|
||||||
* @param $request Обьект запроса
|
* @param HttpRequest $request запроса
|
||||||
*/
|
*/
|
||||||
public function preProcess(HttpRequest $request)
|
public function preProcess(HttpRequest $request)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class Component
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateName($_registry/*: Settings*/) {
|
public function getTemplateName($_registry/*: \ctiso\Settings*/) {
|
||||||
return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template']))
|
return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template']))
|
||||||
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
|
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,7 @@ class Component
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplatePath($name) {
|
public function getTemplatePath($name) {
|
||||||
$registry/*: Settings*/ = $this->config;
|
$registry/*: \ctiso\Settings*/ = $this->config;
|
||||||
// Брать настройки из куков если есть
|
// Брать настройки из куков если есть
|
||||||
$template = ($this->template) ? $this->template : $this->getTemplateName($registry);
|
$template = ($this->template) ? $this->template : $this->getTemplateName($registry);
|
||||||
foreach ($this->viewPath as $index => $viewPath) {
|
foreach ($this->viewPath as $index => $viewPath) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace ctiso\Database;
|
||||||
use ctiso\Database\StatementIterator,
|
use ctiso\Database\StatementIterator,
|
||||||
ctiso\Tools\StringUtil,
|
ctiso\Tools\StringUtil,
|
||||||
PDO;
|
PDO;
|
||||||
|
use TheSeer\Tokenizer\Exception;
|
||||||
|
|
||||||
class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
||||||
{
|
{
|
||||||
|
|
@ -12,7 +13,7 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
||||||
public $cache = array();
|
public $cache = array();
|
||||||
public $fields;
|
public $fields;
|
||||||
|
|
||||||
function getIterator(): Iterator {
|
function getIterator(): \Iterator {
|
||||||
return new StatementIterator($this);
|
return new StatementIterator($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +74,7 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
|
||||||
|
|
||||||
function getInt($name) {
|
function getInt($name) {
|
||||||
if (!$this->fields) {
|
if (!$this->fields) {
|
||||||
throw new Error('no fields');
|
throw new \Exception('no fields');
|
||||||
}
|
}
|
||||||
return (int)$this->fields[$name];
|
return (int)$this->fields[$name];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class Form_OptionFactory {
|
|
||||||
public $db;
|
|
||||||
public $registry;
|
|
||||||
|
|
||||||
function __construct($db, $registry = null) {
|
|
||||||
$this->db = $db;
|
|
||||||
$this->registry = $registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create(Form_Select $field, $input) {
|
|
||||||
if (isset($input['options.resid'])) {
|
|
||||||
$type = $input['options.resid'];
|
|
||||||
|
|
||||||
$res = new Model_Resources($this->db);
|
|
||||||
$field->options = $this->optionsArray('id_section', 'title', $res->getSubsections('', $type));
|
|
||||||
|
|
||||||
} else if (isset($input['options.res'])) {
|
|
||||||
$type = $input['options.res'];
|
|
||||||
|
|
||||||
$res = new Model_Resources($this->db);
|
|
||||||
$field->options = $this->optionsArray('path', 'title', $res->getSubsections('', $type));
|
|
||||||
|
|
||||||
} else if (isset($input['options.all_res'])) {
|
|
||||||
$type = $input['options.all_res'];
|
|
||||||
|
|
||||||
$res = new Model_Resources($this->db);
|
|
||||||
$field->options = $this->optionsArray('id_resource', 'subtitle', $res->getAllResource($type));
|
|
||||||
|
|
||||||
} else if (isset($input['options.db'])) {
|
|
||||||
list($table, $keyvalue) = explode(":", $input['options.db']);
|
|
||||||
list($key, $value) = explode(",", $keyvalue);
|
|
||||||
try {
|
|
||||||
$query_result = $this->db->executeQuery("SELECT * FROM $table");
|
|
||||||
$field->options = $this->optionsDB($key, $value, $query_result);
|
|
||||||
} catch(Exception $ex) {
|
|
||||||
$field->options = [];
|
|
||||||
}
|
|
||||||
} elseif (isset($input['options.pair'])) {
|
|
||||||
$field->options = $this->optionsPair($input['options.pair']);
|
|
||||||
} elseif (isset($input['options.model'])) {
|
|
||||||
$factory = new Model_Factory($this->db, $this->registry);
|
|
||||||
$model = $factory->getModel($input['options.model']);
|
|
||||||
$field->options = $model->getAllAsOptions();
|
|
||||||
} else {
|
|
||||||
$field->options = $input['options'];
|
|
||||||
}
|
|
||||||
if (isset($input['default'])) {
|
|
||||||
array_unshift($field->options, ['value' => 0, 'name' => $input['default']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ставим корневой каталог в начало списка (скорее всего он будет в конце массива)
|
|
||||||
if ($field->options)
|
|
||||||
{
|
|
||||||
$root_elem = array_pop($field->options);
|
|
||||||
if ($root_elem['value'] == '/')
|
|
||||||
array_unshift($field->options, $root_elem);
|
|
||||||
else
|
|
||||||
array_push($field->options, $root_elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function optionsDB($key, $val, $res) {
|
|
||||||
$result = array();
|
|
||||||
while($res->next()) {
|
|
||||||
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function optionsArray($key, $val, $res) {
|
|
||||||
$result = array();
|
|
||||||
foreach($res as $item) {
|
|
||||||
$result[] = array('value' => $item->{$key}, 'name' => $item->{$val});
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function optionsPair($list, $selected = false) {
|
|
||||||
$result = array();
|
|
||||||
foreach ($list as $key => $value) {
|
|
||||||
$result [] = array('value' => $key, 'name' => $value, 'selected' => $key == $selected);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
src/Model/BaseMapper.php
Normal file
6
src/Model/BaseMapper.php
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ctiso\Model;
|
||||||
|
|
||||||
|
class BaseMapper {
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ class Factory
|
||||||
/**
|
/**
|
||||||
* Создает модель
|
* Создает модель
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Model
|
* @return BaseMapper
|
||||||
*/
|
*/
|
||||||
public function getModel ($name)
|
public function getModel ($name)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,13 @@ class Registry {
|
||||||
throw new Exception('Unknown key ' . $ns . '::' . $key);
|
throw new Exception('Unknown key ' . $ns . '::' . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOpt($ns, $key) {
|
||||||
|
if (isset($this->namespace[$ns]['data'][$key])) {
|
||||||
|
return $this->namespace[$ns]['data'][$key];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function has($ns, $key) {
|
public function has($ns, $key) {
|
||||||
return isset($this->namespace[$ns]['data'][$key]);
|
return isset($this->namespace[$ns]['data'][$key]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@
|
||||||
* @see Controller_Front
|
* @see Controller_Front
|
||||||
*/
|
*/
|
||||||
namespace ctiso;
|
namespace ctiso;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class UserMessageException extends Exception {
|
class UserMessageException extends \Exception {
|
||||||
public $userMessage;
|
public $userMessage;
|
||||||
public function __construct($message) {
|
public function __construct($message) {
|
||||||
parent::__construct($message);
|
parent::__construct($message);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue