Обьединение с namespace
This commit is contained in:
commit
8b38b2a3cc
90 changed files with 601 additions and 222 deletions
|
|
@ -1,5 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Shortcut,
|
||||
Exception,
|
||||
ctiso\Path,
|
||||
ctiso\View\View,
|
||||
ctiso\Model\Factory,
|
||||
ctiso\HttpRequest,
|
||||
ctiso\Functions,
|
||||
ctiso\Settings,
|
||||
ctiso\Controller\State;
|
||||
|
||||
function forceUrl($name)
|
||||
{
|
||||
if (is_callable($name)) {
|
||||
|
|
@ -11,7 +22,7 @@ function forceUrl($name)
|
|||
/**
|
||||
* Контроллер страниц
|
||||
*/
|
||||
class Controller_Action
|
||||
class Action
|
||||
{
|
||||
|
||||
const TEMPLATE_EXTENSION = ".html"; // Расширение для шаблонов
|
||||
|
|
@ -78,7 +89,7 @@ class Controller_Action
|
|||
return Path::join(CMS_PATH, "modules", $name);
|
||||
}
|
||||
|
||||
public function addSuggest(View_View $view, $name)
|
||||
public function addSuggest(View $view, $name)
|
||||
{
|
||||
$suggest = array();
|
||||
$file = Path::join($this->viewPath, 'help', $name . '.suggest');
|
||||
|
|
@ -141,7 +152,7 @@ class Controller_Action
|
|||
public function getModel($name)
|
||||
{
|
||||
if (!$this->factory) {
|
||||
$this->factory = new Model_Factory($this->db, $this->_registry);
|
||||
$this->factory = new Factory($this->db, $this->_registry);
|
||||
}
|
||||
return $this->factory->getModel($name);
|
||||
}
|
||||
|
|
@ -364,7 +375,7 @@ class Controller_Action
|
|||
|
||||
function _getActionPath()
|
||||
{
|
||||
return new Controller_State('index');
|
||||
return new State('index');
|
||||
}
|
||||
|
||||
// Тоже убрать в метод Controller_Model
|
||||
|
|
|
|||
|
|
@ -1,7 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\HttpRequest,
|
||||
ctiso\Arr,
|
||||
ctiso\Path,
|
||||
PHPTAL,
|
||||
PHPTAL_PreFilter_Normalize,
|
||||
ctiso\File,
|
||||
ctiso\Form\Form,
|
||||
ctiso\Form\OptionFactory,
|
||||
ctiso\Database,
|
||||
ctiso\Collection,
|
||||
ctiso\Controller\Site;
|
||||
|
||||
function replaceContent($match) {
|
||||
$result = phptal_component(htmlspecialchars_decode($match[3]));
|
||||
$result = Tales\Component::phptal_component(htmlspecialchars_decode($match[3]));
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -38,10 +51,27 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Класс компонента
|
||||
*/
|
||||
class Controller_Component
|
||||
class Component
|
||||
{
|
||||
public $viewPath = array();
|
||||
public $webPath = array();
|
||||
|
|
@ -56,6 +86,7 @@ class Controller_Component
|
|||
public /*.Settings.*/$registry;
|
||||
public /*.Database.*/$db;
|
||||
public /*.Collection.*/$parameter;
|
||||
public $output = 'html';
|
||||
|
||||
public $module;
|
||||
public $item_module;
|
||||
|
|
@ -86,6 +117,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 +199,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;
|
||||
|
|
@ -178,8 +223,8 @@ class Controller_Component
|
|||
*/
|
||||
public function setParameters(/*.View_Composite.*/$view)
|
||||
{
|
||||
$form = new Form_Form();
|
||||
$options = new Form_OptionFactory($this->db, $this->registry);
|
||||
$form = new Form();
|
||||
$options = new OptionFactory($this->db, $this->registry);
|
||||
|
||||
$settings = $this->getInfo();
|
||||
$form->addFieldList($settings['parameter'], $options);
|
||||
|
|
@ -262,14 +307,14 @@ 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
|
||||
$instance = Controller_Site::getInstance();
|
||||
if(class_exists("Controller_Site")) { //Если мы в CMS2
|
||||
$instance = Site::getInstance();
|
||||
$instance->componentsConfig[] = $editor;
|
||||
} else {
|
||||
global $componentsConfig;
|
||||
|
|
@ -324,10 +369,9 @@ class Controller_Component
|
|||
*/
|
||||
|
||||
function addRequireJsPath($name, $path, $shim = null) {
|
||||
Controller_Site::addRequireJsPath($name, $path, $shim);
|
||||
Site::addRequireJsPath($name, $path, $shim);
|
||||
}
|
||||
|
||||
function actionIndex(/*.ComponentRequest.*/ $request) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,18 @@
|
|||
* Первичный контроллер контроллер страниц
|
||||
* @package system.controller
|
||||
*/
|
||||
class Controller_Front extends Controller_Action
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Controller\Action,
|
||||
ctiso\Settings,
|
||||
ctiso\Database,
|
||||
ctiso\Collection,
|
||||
ctiso\Filter\ActionAccess,
|
||||
ctiso\Filter\ActionLogger,
|
||||
ctiso\Path;
|
||||
ctiso\UserMessageException,
|
||||
ctiso\HttpRequest;
|
||||
|
||||
class Front extends Action
|
||||
{
|
||||
|
||||
/** @var Shortcut */
|
||||
|
|
@ -18,16 +29,14 @@ class Controller_Front extends Controller_Action
|
|||
* @param Settings $_registry
|
||||
* @param Shortcut $_shortcut
|
||||
*/
|
||||
public function __construct($db, $settings, $default) // $db, $installer, $shortcut
|
||||
{
|
||||
public function __construct($db, $settings, $default) {
|
||||
parent::__construct();
|
||||
$this->settings = $settings;
|
||||
$this->db = $db;
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
public function isLoaded($name)
|
||||
{
|
||||
public function isLoaded($name) {
|
||||
return isset($this->modules[$name]);
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +46,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];
|
||||
|
|
@ -47,7 +56,9 @@ class Controller_Front extends Controller_Action
|
|||
$basePath = $this->settings['system']->readKey(['path', 'modules']);
|
||||
$moduleFile = Path::join($basePath, $name, 'classes', $controller ? $controller : $name);
|
||||
|
||||
$module = $this->loadClass($moduleFile, null, 'Module_');
|
||||
$ucname = ucfirst($name);
|
||||
$moduleClass = "Module\\$ucname\\$ucname";
|
||||
$module = new $moduleClass();
|
||||
if ($module) {
|
||||
// Инициализация модуля
|
||||
$modPath = Path::join($basePath, $name);
|
||||
|
|
@ -57,10 +68,10 @@ class Controller_Front extends Controller_Action
|
|||
$module->settings = $this->settings;
|
||||
$module->db = $this->db;
|
||||
// Ведение лога
|
||||
$logger = new Filter_ActionLogger($module);
|
||||
$logger = new ActionLogger($module);
|
||||
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));
|
||||
// Управление доступом
|
||||
$module->access = new Filter_ActionAccess($logger);
|
||||
$module->access = new ActionAccess($logger);
|
||||
$module->access->access = $this->loadSettings(Path::join($modPath, 'filter', 'access.php'));
|
||||
|
||||
$module->setUp();
|
||||
|
|
@ -72,13 +83,14 @@ class Controller_Front extends Controller_Action
|
|||
return null; // throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
public function execute(HTTPRequest $request)
|
||||
|
||||
public function execute(HttpRequest $request)
|
||||
{
|
||||
$name = explode("_", $request->get('module', $this->default));
|
||||
$name = explode("\\", $request->get('module', $this->default));
|
||||
if (count($name) >= 2) {
|
||||
$controller = $name[1];
|
||||
} else {
|
||||
$controller = false;
|
||||
$controller = null;
|
||||
}
|
||||
try {
|
||||
return $this->loadModule($name[0], $request, $controller);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
<?php
|
||||
|
||||
class Controller_Installer
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Settings,
|
||||
ctiso\Path,
|
||||
ctiso\Database\JsonInstall;
|
||||
|
||||
class Installer
|
||||
{
|
||||
protected $db_manager;
|
||||
protected $installPath;
|
||||
|
|
@ -44,7 +49,7 @@ class Controller_Installer
|
|||
function installSQL(array $sql, $version_new, $version_old, $name)
|
||||
{
|
||||
$result = [];
|
||||
$json_installer = new Database_JsonInstall($this->db_manager);
|
||||
$json_installer = new JsonInstall($this->db_manager);
|
||||
foreach ($sql as $version => $install) {
|
||||
if (version_compare($version, $version_new, "<=") && version_compare($version, $version_old, ">")) {
|
||||
$file = Path::join(call_user_func($this->installPath, $name), "sql", $install);
|
||||
|
|
@ -58,7 +63,7 @@ class Controller_Installer
|
|||
function uninstall($name){
|
||||
$uninstall = $this->getUninstallFile($name);
|
||||
if (file_exists($uninstall)) {
|
||||
$json_installer = new Database_JsonInstall($this->db_manager);
|
||||
$json_installer = new JsonInstall($this->db_manager);
|
||||
$json_installer->install($uninstall,null);
|
||||
}
|
||||
$this->_registry->removeKey($name);
|
||||
|
|
@ -108,7 +113,7 @@ class Controller_Installer
|
|||
}
|
||||
|
||||
function install($dbinit_path, $dbfill_path = null) {
|
||||
$json_installer = new Database_JsonInstall($this->db_manager);
|
||||
$json_installer = new JsonInstall($this->db_manager);
|
||||
$json_installer->install($dbinit_path, $dbfill_path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Controller_Request {
|
||||
function __construct($request, $id) {
|
||||
namespace ctiso\Controller;
|
||||
|
||||
class Request {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,20 @@
|
|||
/**
|
||||
* Класс сервиса = Упрощенный компонент
|
||||
*/
|
||||
class Controller_Service
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Path;
|
||||
|
||||
class 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);
|
||||
|
|
@ -43,7 +49,7 @@ class Controller_Service
|
|||
return $model;
|
||||
}
|
||||
|
||||
public function options($key, $val, $res) {
|
||||
public function options($key, $val, /*.Database_PDOStatement.*/$res) {
|
||||
$result = array();
|
||||
while($res->next()) {
|
||||
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
class Controller_State
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Controller\Action;
|
||||
|
||||
class State
|
||||
{
|
||||
public $action = '';
|
||||
public $states = array();
|
||||
|
|
@ -13,7 +16,7 @@ class Controller_State
|
|||
|
||||
static function make($action)
|
||||
{
|
||||
return new Controller_State($action);
|
||||
return new State($action);
|
||||
}
|
||||
|
||||
public function addTitle($name, $url = array())
|
||||
|
|
@ -22,7 +25,7 @@ class Controller_State
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addState(Controller_State $state)
|
||||
public function addState(State $state)
|
||||
{
|
||||
$this->states [$state->getAction()] = $state;
|
||||
return $this;
|
||||
|
|
@ -49,7 +52,7 @@ class Controller_State
|
|||
return false;
|
||||
}
|
||||
|
||||
function makeTitle(Controller_Action $module)
|
||||
function makeTitle(Action $module)
|
||||
{
|
||||
foreach ($this->titles as $item) {
|
||||
$module->path->addMenuItem($module->nUrl($this->action, $item[1]), $item[0]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue