Вход Регистрация
Файл: MobileCMS-2.7.0-beta/System/Deprecated/Router.php
Строк: 166
<?php
/**
 * MobileCMS
 *
 * Open source content management system for mobile sites
 *
 * @author KpuTuK <bykputuk@ya.ru>
 * @copyright Copyright (c) 2015, MobileCMS Team
 * @license MIT License
 */

namespace SystemDeprecated;

/**
 * Description of Router
 * @deprecated с версии 2.6.1, будет удален с версии 3.0 Используйте SystemKernelRoutingRouter
 * @author KpuTuK
 */
class Router {

    
/**
     * Путь к контроллеру
     */
    
public $controller_path = NULL;

    
/**
     * Название контроллера
     */
    
public $controller_name = NULL;

    
/**
     * Получаемый action
     */
    
public $action = NULL;

    
/**
     * Флаг существования контроллера
     */
    
public $controller_exists = TRUE;

    
/**
     * Модуль
     */
    
public $module;

    
/**
     * Сегменты
     */
    
public $segment1 = null;
    public 
$segment2 = null;
    public 
$segment3 = null;
    public function 
__construct() {
        @
trigger_error('Данный класс кстарел с версии 2.6.1, будет удален с версии 3.0 Используйте SystemKernelRoutingRouter');
    }
    
/**
     * Конструктор
     */
    
public function handle($segments) {
        
$_GET = array_merge($_GET, $segments);
        if (isset(
$segments['segment1'])) {
            
$this->segment1 = str_replace('.php', '', $segments['segment1']);
        }
        if (isset(
$segments['segment2'])) {
            
$this->segment2 = str_replace('.php', '', $segments['segment2']);
        }
        if (isset(
$segments['segment3'])) {
            
$this->segment3 = str_replace('.php', '', $segments['segment3']);
        }
        
$this->route();
        
$this->run();
    }
    public function 
run() {
        
$controller = a_load_class(ROUTE_CONTROLLER_PATH, 'controller');
        
// Выполняем метод контроллера
        
if (!empty($this->action)) {
            
$action_method = 'action_' . $this->action;

            if (
method_exists($controller, $action_method)) {
                
$controller->$action_method();
            } else
                
header('Location: ' . a_url('main/page_not_found', '', true));
        }
        else {
            if (
method_exists($controller, 'action_index')) {
                
$controller->action_index();
            } else
                
header('Location: ' . a_url('main/page_not_found', '', true));
        }
    }
    
/**
     * Функция определяет контроллер и action
     */
    
public function route() {
        
# Если нет сегментов, подключаем модуль по умолчанию
        
if (empty($this->segment1)) {
            if (
file_exists(ROOT . 'modules/' . DEFAULT_MODULE . '/controllers/' . DEFAULT_MODULE . '.php')) {
                
$this->controller_path = 'modules/' . DEFAULT_MODULE . '/controllers/' . DEFAULT_MODULE . '.php';
                
$this->controller_name = DEFAULT_MODULE;
                
$this->action = '';
                
$this->module = DEFAULT_MODULE;
            } else {
                
$this->controller_exists = FALSE;
            }
        }
        
# Если указаны все 3 сегмента
        
if (!empty($this->segment1) && !empty($this->segment2) && !empty($this->segment3)) {
            if (
file_exists(ROOT . 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '_' . $this->segment2 . '.php')) {
                
$this->controller_path = 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '_' . $this->segment2 . '.php';
                
$this->controller_name = $this->segment1 . '_' . $this->segment2;
                
$this->action = $this->segment3;
                
$this->module = $this->segment1;
            } else {
                
$this->controller_exists = FALSE;
            }
        }
        
# Если указаны 2 сегмента
        
elseif (!empty($this->segment1) && !empty($this->segment2)) {
            if (
file_exists(ROOT . 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '_' . $this->segment2 . '.php')) {
                
$this->controller_path = 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '_' . $this->segment2 . '.php';
                
$this->controller_name = $this->segment1 . '_' . $this->segment2;
                
$this->action = '';
                
$this->module = $this->segment1;
            } elseif (
file_exists(ROOT . 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '.php')) {
                
$this->controller_path = 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '.php';
                
$this->controller_name = $this->segment1;
                
$this->action = $this->segment2;
                
$this->module = $this->segment1;
            } else
                
$this->controller_exists = FALSE;
        }
        
# Если указан только 1 сегмент
        
elseif (!empty($this->segment1)) {
            if (
file_exists(ROOT . 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '.php')) {
                
$this->controller_path = 'modules/' . $this->segment1 . '/controllers/' . $this->segment1 . '.php';
                
$this->controller_name = $this->segment1;
                
$this->action = '';
                
$this->module = $this->segment1;
            } else {
                
$this->controller_exists = FALSE;
           }
       }

        if (
$this->controller_exists) {
            
define('ROUTE_CONTROLLER_PATH', $this->controller_path);
            
define('ROUTE_CONTROLLER_NAME', $this->controller_name);
            
define('ROUTE_ACTION', $this->action);
            
define('ROUTE_MODULE', $this->module);
        } else
           
header('Location: ' . a_url('main/page_not_found', '', true));
    }
}
Онлайн: 2
Реклама