Этот коммит содержится в:
2017-01-23 23:33:16 +03:00
родитель 40a11965e5
Коммит 8034ea23c7
15 изменённых файлов: 209 добавлений и 18 удалений

Просмотреть файл

@@ -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;
}
}
}
}