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