23:33
Этот коммит содержится в:
46
frm/App.php
46
frm/App.php
@@ -22,29 +22,65 @@ class App {
|
||||
error_reporting(E_ALL);
|
||||
$this->user_agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$this->user_IP = $_SERVER['REMOTE_ADDR'];
|
||||
$this->setRoute('/^\/$/','Index','index');
|
||||
$this->setRoute( '|^/$|', 'Index', 'index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* Получение useragent пользователя
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUseragent() {
|
||||
public function getUserAgent() {
|
||||
return $this->user_agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* Получение IP пользователя
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserIP() {
|
||||
return $this->user_IP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка маршрута
|
||||
*
|
||||
* @param string $regexp регулярное выражение описывающее путь
|
||||
* @param string $controller котроллер.
|
||||
* @param string $action действие. по умолчанию 'index'
|
||||
*/
|
||||
public function setRoute( $regexp, $controller, $action = 'index') {
|
||||
$this->route_table[] = array($regexp,$controller,$action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Редирект
|
||||
*
|
||||
* @param string $url адрес переброса
|
||||
*/
|
||||
public function Redirect( $url ) {
|
||||
header( 'Location: ' . $url );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Запуск маршрутов
|
||||
*/
|
||||
public function run(){
|
||||
|
||||
foreach ( $this->route_table as $route_array ) {
|
||||
if ( preg_match( $route_array[0], $_SERVER['REQUEST_URI'], $matches ) ) {
|
||||
$a = $this->config->controller_namespace . $route_array[1] . 'Controller';
|
||||
$obj = new $a;
|
||||
$param_arr = [];
|
||||
foreach ( $matches as $key => $value ) {
|
||||
if ( ! is_int( $key ) ) {
|
||||
$param_arr[] = $value;
|
||||
}
|
||||
}
|
||||
call_user_func_array( [ $obj, $route_array[2] . 'Action' ], $param_arr );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
frm/View.php
24
frm/View.php
@@ -12,10 +12,30 @@ namespace PFRM;
|
||||
class View {
|
||||
public $app;
|
||||
|
||||
function __construct() {
|
||||
private $view_filename;
|
||||
|
||||
public $site_name;
|
||||
|
||||
function __construct( $filename ) {
|
||||
global $app;
|
||||
$this->app = $app;
|
||||
$this->view_filename = $this->app->config->views_dir . $filename . '.php';
|
||||
$this->site_name = $this->app->config->site_name;
|
||||
}
|
||||
|
||||
public function render( ) {
|
||||
/**
|
||||
* Установка HTTP-заголовка
|
||||
*
|
||||
* @param string $header http-заголовок
|
||||
*/
|
||||
public function setHTTPHeader( $header ) {
|
||||
header( $header, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Запуск php-шаблона
|
||||
*/
|
||||
public function render( ) {
|
||||
require $this->view_filename;
|
||||
}
|
||||
}
|
Ссылка в новой задаче
Block a user