ref Исправление типов

This commit is contained in:
origami11@yandex.ru 2022-11-24 19:12:00 +03:00
parent a09fc396d8
commit 28429039a4
8 changed files with 24 additions and 98 deletions

View file

@ -101,9 +101,9 @@ class Action
/**
* Создает представление
* @param $name String
* @param $viewClass String
* @return View_Composite
* @param string
* @param string $viewClass
* @return Composite
*/
public function getView($name, $viewClass = 'ctiso\\View\\Composite')
{
@ -163,7 +163,7 @@ class Action
* Т.к действия являются методами класса то
* 1. Можно переопределить действия
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
* @param $request Обьект запроса
* @param HttpRequest $request запроса
*/
public function preProcess(HttpRequest $request)
{

View file

@ -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']))
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
}
@ -147,7 +147,7 @@ class Component
}
public function getTemplatePath($name) {
$registry/*: Settings*/ = $this->config;
$registry/*: \ctiso\Settings*/ = $this->config;
// Брать настройки из куков если есть
$template = ($this->template) ? $this->template : $this->getTemplateName($registry);
foreach ($this->viewPath as $index => $viewPath) {

View file

@ -5,6 +5,7 @@ namespace ctiso\Database;
use ctiso\Database\StatementIterator,
ctiso\Tools\StringUtil,
PDO;
use TheSeer\Tokenizer\Exception;
class PDOStatement extends \PDOStatement implements \IteratorAggregate
{
@ -12,7 +13,7 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
public $cache = array();
public $fields;
function getIterator(): Iterator {
function getIterator(): \Iterator {
return new StatementIterator($this);
}
@ -73,7 +74,7 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
function getInt($name) {
if (!$this->fields) {
throw new Error('no fields');
throw new \Exception('no fields');
}
return (int)$this->fields[$name];
}

View file

@ -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
View file

@ -0,0 +1,6 @@
<?php
namespace ctiso\Model;
class BaseMapper {
}

View file

@ -18,7 +18,7 @@ class Factory
/**
* Создает модель
* @param string $name
* @return Model
* @return BaseMapper
*/
public function getModel ($name)
{

View file

@ -34,6 +34,13 @@ class Registry {
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) {
return isset($this->namespace[$ns]['data'][$key]);
}

View file

@ -4,9 +4,8 @@
* @see Controller_Front
*/
namespace ctiso;
use Exception;
class UserMessageException extends Exception {
class UserMessageException extends \Exception {
public $userMessage;
public function __construct($message) {
parent::__construct($message);