Оптимизации и исправления топов.

This commit is contained in:
CORP\phedor 2018-03-23 12:35:10 +03:00
parent 77fa3dbd5e
commit 0f4b2fb722
25 changed files with 109 additions and 53 deletions

View file

@ -38,6 +38,23 @@ class ComponentRequest {
}
}
class FakeTemplate {
public $_data = [];
public $_name = '';
function __construct($name) {
$this->_name = $name;
}
function __set($key, $value) {
$this->_data[$key] = $value;
}
function execute() {
return $this->_data;
}
}
/**
* Класс компонента
*/
@ -56,6 +73,7 @@ class Controller_Component
public /*.Settings.*/$registry;
public /*.Database.*/$db;
public /*.Collection.*/$parameter;
public $output = 'html';
public $module;
public $item_module;
@ -86,6 +104,10 @@ class Controller_Component
public function getView($name)
{
if ($this->output == 'json') {
return new FakeTemplate($name);
}
//
/*.Settings.*/$registry = $this->registry;
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
@ -164,8 +186,18 @@ class Controller_Component
return $result;
}
function findFile($pathList, $name) {
foreach($pathList as $item) {
$filename = Path::join($item, $name);
if (file_exists($filename)) {
return $filename;
}
}
return null;
}
function getInfo() {
$filename = Path::join($this->viewPath[0], 'install.json');
$filename = $this->findFile($this->viewPath, 'install.json');
if (file_exists($filename)) {
$settings = json_decode(File::getContents($filename), true);
return $settings;
@ -262,13 +294,13 @@ class Controller_Component
}
$params = new Collection();
$params->import(array_merge($_GET, $arguments));
$params->import($arguments);
$component->parameter = $params;
$component->template = $params->get('template', false);
$editor = $component->getEditUrl();
if ($editor) {
if(class_exists("Controller_Site")){ //Если мы в CMS2
if(class_exists("Controller_Site")) { //Если мы в CMS2
$instance = Controller_Site::getInstance();
$instance->componentsConfig[] = $editor;
} else {

View file

@ -40,7 +40,7 @@ class Controller_Front extends Controller_Action
* @param request $request Имя модуля
* @return string
*/
public function loadModule($name, Collection $request, $controller = false)
public function loadModule($name, Collection $request, $controller = null)
{
if ($this->isLoaded($name)) {
$module = $this->modules[$name];
@ -93,13 +93,13 @@ class Controller_Front extends Controller_Action
$this->default = $name;
}
public function execute(HTTPRequest $request)
public function execute(HttpRequest $request)
{
$name = explode("_", $request->get($this->_param, $this->default));
if (count($name) >= 2) {
$controller = $name[1];
} else {
$controller = false;
$controller = null;
}
try{
return $this->loadModule($name[0], $request, $controller);

View file

@ -1,13 +1,17 @@
<?php
class Controller_Request {
function __construct($request, $id) {
public $r;
public $id;
function __construct(/*.HttpRequest.*/$request, $id) {
$this->r = $request;
$this->id = $id;
}
function get($name) {
function get($name, $def) {
$v = $this->r->get($name);
$id = $this->id;
if ($id && is_array($v)) {
return isset($v[$id]) ? $v[$id] : $def;
}

View file

@ -5,12 +5,15 @@
*/
class Controller_Service
{
public $viewPath = array();
public $viewPath = [];
public $webPath = [];
public $registry; // Registry->getInstance
public $template;
public $templatePath;
public $COMPONENTS_WEB;
public $db;
public function getTemplatePath($name)
{
return Path::join($this->viewPath[0], 'templates', 'modern', $name);