fix: Интерфейсы
This commit is contained in:
parent
36c81135f3
commit
5474090f85
5 changed files with 90 additions and 44 deletions
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\HttpRequest,
|
||||
ctiso\ComponentRequest,
|
||||
ctiso\Arr,
|
||||
ctiso\Path,
|
||||
ctiso\File,
|
||||
ctiso\Form\Form,
|
||||
ctiso\View\Composite,
|
||||
ctiso\Database,
|
||||
ctiso\Database\PDOStatement,
|
||||
ctiso\Collection,
|
||||
ctiso\Registry,
|
||||
ctiso\Controller\SiteInterface,
|
||||
PHPTAL,
|
||||
PHPTAL_PreFilter_Normalize;
|
||||
|
||||
use ctiso\HttpRequest;
|
||||
use ctiso\ComponentRequest;
|
||||
use ctiso\Arr;
|
||||
use ctiso\Path;
|
||||
use ctiso\File;
|
||||
use ctiso\Form\Form;
|
||||
use ctiso\View\Composite;
|
||||
use ctiso\Database;
|
||||
use ctiso\Collection;
|
||||
use ctiso\Registry;
|
||||
use ctiso\Controller\SiteInterface;
|
||||
use PHPTAL;
|
||||
use PHPTAL_PreFilter_Normalize;
|
||||
|
||||
class FakeTemplate {
|
||||
public $_data = [];
|
||||
|
|
@ -38,11 +38,11 @@ class FakeTemplate {
|
|||
*/
|
||||
class Component
|
||||
{
|
||||
public $viewPath = array();
|
||||
public $webPath = array();
|
||||
public $viewPath = [];
|
||||
public $webPath = [];
|
||||
|
||||
public $template = null;
|
||||
public $templatePath;
|
||||
public string $templatePath;
|
||||
|
||||
public $component_id;
|
||||
public $component_title;
|
||||
|
|
@ -59,7 +59,7 @@ class Component
|
|||
public $item_module;
|
||||
|
||||
/**
|
||||
* @var \App\Controller\Site
|
||||
* @var SiteInterface $site
|
||||
*/
|
||||
public $site;
|
||||
|
||||
|
|
@ -92,7 +92,11 @@ class Component
|
|||
}
|
||||
}
|
||||
|
||||
public function getTemplateName($_registry/*: \ctiso\Settings*/) {
|
||||
/**
|
||||
* Получить имя шаблона
|
||||
* @param Registry $_registry
|
||||
*/
|
||||
public function getTemplateName($_registry) {
|
||||
return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template']))
|
||||
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
|
||||
}
|
||||
|
|
@ -184,7 +188,12 @@ class Component
|
|||
return $model;
|
||||
}
|
||||
|
||||
public function options($key, $val, $res/*: PDOStatement*/) {
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $val
|
||||
* @param $res
|
||||
*/
|
||||
public function options(string $key, string $val, $res) {
|
||||
$result = [];
|
||||
while($res->next()) {
|
||||
$result[] = ['value' => $res->getString($key), 'name' => $res->getString($val)];
|
||||
|
|
@ -192,7 +201,7 @@ class Component
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function optionsPair($list, $selected = false) {
|
||||
public function optionsPair(array $list, $selected = false) {
|
||||
$result = [];
|
||||
foreach ($list as $key => $value) {
|
||||
$result [] = ['value' => $key, 'name' => $value, 'selected' => $key == $selected];
|
||||
|
|
@ -200,7 +209,13 @@ class Component
|
|||
return $result;
|
||||
}
|
||||
|
||||
function findFile($pathList, $name) {
|
||||
/**
|
||||
* Найти файл по пути
|
||||
* @param string[] $pathList
|
||||
* @param string $name
|
||||
* @return string|null
|
||||
*/
|
||||
function findFile(array $pathList, string $name) {
|
||||
foreach($pathList as $item) {
|
||||
$filename = Path::join($item, $name);
|
||||
if (file_exists($filename)) {
|
||||
|
|
@ -223,6 +238,8 @@ class Component
|
|||
|
||||
/**
|
||||
* Генерация интерфейса для выбора галлереи фотографии
|
||||
* @param Composite $view
|
||||
* @param \ctiso\Form\OptionsFactory $options
|
||||
*/
|
||||
public function setParameters(Composite $view, $options = null)
|
||||
{
|
||||
|
|
@ -245,10 +262,12 @@ class Component
|
|||
|
||||
/**
|
||||
* Обьеденить с ComponentFactory
|
||||
* @param string $expression
|
||||
* @param SiteInterface $site
|
||||
* @return Component
|
||||
*/
|
||||
static function loadComponent($expression, $site/*: SiteInterface*/)
|
||||
static function loadComponent(string $expression, $site)
|
||||
{
|
||||
|
||||
$expression = htmlspecialchars_decode($expression);
|
||||
$offset = strpos($expression, '?');
|
||||
$url = parse_url($expression);
|
||||
|
|
@ -261,16 +280,18 @@ class Component
|
|||
parse_str($query, $arguments);
|
||||
}
|
||||
$name = $path;
|
||||
$config = $site->config;
|
||||
$config = $site->getConfig();
|
||||
|
||||
$filename = ucfirst($name);
|
||||
$path = Path::join ($config->get('site', 'components'), $name, $filename . '.php');
|
||||
$className = implode("\\", ['Components', ucfirst($name), $filename]);
|
||||
|
||||
$component/*: Component*/ = null;
|
||||
/**
|
||||
* @var ?Component $component
|
||||
*/
|
||||
$component = null;
|
||||
|
||||
if (file_exists($path)) {
|
||||
// require_once ($path);
|
||||
$component = new $className();
|
||||
|
||||
$component->viewPath = [$config->get('site', 'components') . '/' . $name . '/'];
|
||||
|
|
@ -279,7 +300,7 @@ class Component
|
|||
|
||||
} else {
|
||||
$component = new $className();
|
||||
$template = $component->getTemplateName($site->config);
|
||||
$template = $component->getTemplateName($site->getConfig());
|
||||
|
||||
$component->viewPath = [
|
||||
// Сначало ищем локально
|
||||
|
|
@ -308,7 +329,7 @@ class Component
|
|||
$db = $site->getDatabase();
|
||||
|
||||
$component->db = $db;
|
||||
$component->config = $site->config;
|
||||
$component->config = $site->getConfig();
|
||||
$component->site = $site;
|
||||
|
||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
||||
|
|
@ -344,7 +365,7 @@ class Component
|
|||
|
||||
$editor = $component->getEditUrl();
|
||||
if ($editor) {
|
||||
$site->componentsConfig[] = $editor;
|
||||
$site->addComponentConfig($editor);
|
||||
}
|
||||
|
||||
return $component;
|
||||
|
|
@ -354,12 +375,15 @@ class Component
|
|||
return null;
|
||||
}
|
||||
|
||||
function raw_query($request/*: ComponentRequest*/)
|
||||
/**
|
||||
* @param ComponentRequest $request
|
||||
*/
|
||||
function raw_query($request)
|
||||
{
|
||||
$arr = $request->r->export('get');
|
||||
|
||||
$param = [];
|
||||
$parameter/*: Collection*/ = $this->parameter;
|
||||
$parameter = $this->parameter;
|
||||
foreach($parameter->export() as $key => $value) {
|
||||
$param[$key] = $value;
|
||||
}
|
||||
|
|
@ -377,7 +401,10 @@ class Component
|
|||
}
|
||||
|
||||
|
||||
function query($request/*: ComponentRequest*/, $list)
|
||||
/**
|
||||
* @param ComponentRequest $request
|
||||
*/
|
||||
function query($request, $list)
|
||||
{
|
||||
$arr = $request->r->export('get');
|
||||
|
||||
|
|
@ -393,6 +420,9 @@ class Component
|
|||
$this->site->addRequireJsPath($name, $path, $shim);
|
||||
}
|
||||
|
||||
function actionIndex($request/*: ComponentRequest*/) {
|
||||
/**
|
||||
* @param ComponentRequest $request
|
||||
*/
|
||||
function actionIndex($request) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,14 @@ namespace ctiso\Controller;
|
|||
|
||||
interface SiteInterface {
|
||||
function getResource();
|
||||
function loadComponent($expression);
|
||||
function getDatabase();
|
||||
function getConfig();
|
||||
function setComponentConfig($config);
|
||||
function addRequireJsPath($name, $path, $schim = null);
|
||||
function getTheme();
|
||||
function addComponentConfig($config);
|
||||
function addRequireJsPath(string $name, string $path, ?array $shim = null);
|
||||
function addStyleSheet(string $url);
|
||||
|
||||
function loadComponent(string $expression);
|
||||
function findTemplate(string $name);
|
||||
function replaceImg(string $src, int $width, int $height);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ use ctiso\Form\Field,
|
|||
* Форма для ввода
|
||||
*/
|
||||
class Form {
|
||||
public $field = array(); //Поля формы
|
||||
public $fieldsets = array(); //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам
|
||||
public $field = []; //Поля формы
|
||||
public $fieldsets = []; //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам
|
||||
|
||||
public $action = "";
|
||||
public $method = 'post';
|
||||
|
|
@ -26,9 +26,9 @@ class Form {
|
|||
protected $replace;
|
||||
protected $before;
|
||||
|
||||
public $_title = array();
|
||||
public $alias = array();
|
||||
private $constructor = array();
|
||||
public $_title = [];
|
||||
public $alias = [];
|
||||
private $constructor = [];
|
||||
|
||||
/**
|
||||
* Строим форму по ее структуре. Каждому типу соответствует определенный класс.
|
||||
|
|
@ -183,7 +183,7 @@ class Form {
|
|||
{
|
||||
$this->field[$name]->setValue($value);
|
||||
}
|
||||
|
||||
|
||||
function execute()
|
||||
{
|
||||
return $this;
|
||||
|
|
|
|||
7
src/Form/OptionsFactory.php
Normal file
7
src/Form/OptionsFactory.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Form;
|
||||
|
||||
interface OptionsFactory {
|
||||
function create(Select $field, array $options);
|
||||
}
|
||||
|
|
@ -5,8 +5,12 @@ use ctiso\Form\Field;
|
|||
|
||||
class Select extends Field
|
||||
{
|
||||
public $options = array();
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* @param array $input
|
||||
* @param OptionsFactory $factory
|
||||
*/
|
||||
public function __construct ($input, $factory) {
|
||||
parent::__construct($input);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue