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

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

@ -22,29 +22,65 @@ class App {
error_reporting(E_ALL); error_reporting(E_ALL);
$this->user_agent = $_SERVER['HTTP_USER_AGENT']; $this->user_agent = $_SERVER['HTTP_USER_AGENT'];
$this->user_IP = $_SERVER['REMOTE_ADDR']; $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 $this->user_agent;
} }
/** /**
* @return mixed * Получение IP пользователя
*
* @return string
*/ */
public function getUserIP() { public function getUserIP() {
return $this->user_IP; return $this->user_IP;
} }
/**
* Установка маршрута
*
* @param string $regexp регулярное выражение описывающее путь
* @param string $controller котроллер.
* @param string $action действие. по умолчанию 'index'
*/
public function setRoute( $regexp, $controller, $action = 'index') { public function setRoute( $regexp, $controller, $action = 'index') {
$this->route_table[] = array($regexp,$controller,$action); $this->route_table[] = array($regexp,$controller,$action);
} }
/**
* Редирект
*
* @param string $url адрес переброса
*/
public function Redirect( $url ) {
header( 'Location: ' . $url );
exit(0);
}
/**
* Запуск маршрутов
*/
public function run(){ 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;
}
}
} }
} }

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

@ -12,10 +12,30 @@ namespace PFRM;
class View { class View {
public $app; 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;
} }
} }

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

@ -3,6 +3,10 @@
/** ptest css */ /** ptest css */
body
-ff _ffv
-fs 16
$link_color = #0063ff $link_color = #0063ff
$link_color_border = alpha($link_color,.3) $link_color_border = alpha($link_color,.3)
$link_hover_color = #ff475d $link_hover_color = #ff475d
@ -27,4 +31,25 @@ a
.page .page
&__container &__container
-wmax 800 -wmax 800
-m 0 auto
.header
-p 30
-bg #ffcc56
-bg -moz-repeating-linear-gradient(178deg, rgba(255,204,86,.5) 8px, rgba(255,140,0,.5) 18px);
-bg -webkit-repeating-linear-gradient(178deg, rgba(255,204,86,.5) 8px,rgba(255,140,0,.5) 18px);
-bg repeating-linear-gradient(178deg, rgba(255,204,86,.5) 8px,rgba(255,140,0,.5) 18px);
bx-shadow 2px 3px 15px #eb4 inset
b-radius 2
-mt 30
-mb 60
-ta center
&__title
line-height 1
-m 0
-ff _fftnr
-fst italic
-ts 1 1 1 #a76f19
-fs 52

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

@ -1 +1 @@
html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template,[hidden]{display:none}a{color:#0063ff;text-decoration:none;border-bottom:1px solid rgba(0,99,255,.3)}a:visited{color:#cf00cf;border-bottom-color:rgba(207,0,207,.3)}a:hover,a:visited:hover{color:#ff475d;border-bottom-color:rgba(255,71,93,.24)}.page__container{max-width:800px} html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template,[hidden]{display:none}body{font-family:Verdana,"Geneva CY","DejaVu Sans",sans-serif;font-size:16px}a{color:#0063ff;text-decoration:none;border-bottom:1px solid rgba(0,99,255,.3)}a:visited{color:#cf00cf;border-bottom-color:rgba(207,0,207,.3)}a:hover,a:visited:hover{color:#ff475d;border-bottom-color:rgba(255,71,93,.24)}.page__container{max-width:800px;margin:0 auto}.header{padding:30px;background:#ffcc56;background:-moz-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:-webkit-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);-moz-box-shadow:2px 3px 15px #eb4 inset;-webkit-box-shadow:2px 3px 15px #eb4 inset;box-shadow:2px 3px 15px #eb4 inset;-webkit-border-radius:2px;-moz-border-radius:2px;-o-border-radius:2px;-ms-border-radius:2px;-khtml-border-radius:2px;border-radius:2px;margin-top:30px;margin-bottom:60px;text-align:center}.header__title{line-height:1;margin:0;font-family:"Times New Roman","Times CY","Nimbus Roman No9 L",serif;font-style:italic;text-shadow:1px 1px 1px #a76f19;font-size:52px}

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

@ -196,6 +196,10 @@ template {
display: none; display: none;
} }
/** ptest css */ /** ptest css */
body {
font-family: Verdana, "Geneva CY", "DejaVu Sans", sans-serif;
font-size: 16px;
}
a { a {
color: #0063ff; color: #0063ff;
text-decoration: none; text-decoration: none;
@ -212,4 +216,32 @@ a:visited:hover {
} }
.page__container { .page__container {
max-width: 800px; max-width: 800px;
margin: 0 auto;
}
.header {
padding: 30px;
background: #ffcc56;
background: -moz-repeating-linear-gradient(178deg, rgba(255,204,86,0.5) 8px, rgba(255,140,0,0.5) 18px);
background: -webkit-repeating-linear-gradient(178deg, rgba(255,204,86,0.5) 8px, rgba(255,140,0,0.5) 18px);
background: repeating-linear-gradient(178deg, rgba(255,204,86,0.5) 8px, rgba(255,140,0,0.5) 18px);
-moz-box-shadow: 2px 3px 15px #eb4 inset;
-webkit-box-shadow: 2px 3px 15px #eb4 inset;
box-shadow: 2px 3px 15px #eb4 inset;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-ms-border-radius: 2px;
-khtml-border-radius: 2px;
border-radius: 2px;
margin-top: 30px;
margin-bottom: 60px;
text-align: center;
}
.header__title {
line-height: 1;
margin: 0;
font-family: "Times New Roman", "Times CY", "Nimbus Roman No9 L", serif;
font-style: italic;
text-shadow: 1px 1px 1px #a76f19;
font-size: 52px;
} }

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

@ -6,10 +6,10 @@
* Time: 00:18 * Time: 00:18
*/ */
namespace PTEST\Controller; namespace PTEST\C;
class CAPTCHA { class CAPTCHAController {
public function indexAction() { public function indexAction() {

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

@ -6,15 +6,21 @@
* Time: 00:16 * Time: 00:16
*/ */
namespace PTEST\Controller; namespace PTEST\C;
use PFRM\Controller; use PFRM\Controller;
use PFRM\View as View;
class Index extends Controller { class IndexController extends Controller {
public function indexAction() { public function indexAction() {
print "index action"; $view = new View('index');
$view->page_title = "Доска объявлений";
$view->render();
} }
public function pageAction( $numder ) {
print "number = ".$numder;
}
} }

21
src/C/error404Controller.php Обычный файл
Просмотреть файл

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: Игорь
* Date: 23.01.2017
* Time: 18:04
*/
namespace PTEST\C;
use PFRM\Controller;
use PFRM\View as View;
class error404Controller extends Controller{
public function indexAction() {
$view = new View('404');
$view->setHTTPHeader('HTTP/1.0 404 Not Found');
$view->render();
}
}

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

@ -9,7 +9,7 @@
namespace PTEST\Model; namespace PTEST\Model;
class Ad { class AdModel {
protected $id; protected $id;

6
src/V/404.php Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
<?php
$this->page_title = "Ошибка: 404 Страница не найдена";
require __DIR__ . '/inc/head.php';
require __DIR__ . '/inc/body.php';

14
src/V/inc/body.php Обычный файл
Просмотреть файл

@ -0,0 +1,14 @@
<body class="page">
<div class="page__container">
<header class="header">
<h1 class="header__title"><?php echo $this->site_name; ?></h1>
</header>
<section role="main">
<h1><?php echo $this->page_title; ?></h1>
</section>
<footer>
<?php require 'footer.php'; ?>
</footer>
</div>
</body>
</html>

1
src/V/inc/footer.php Обычный файл
Просмотреть файл

@ -0,0 +1 @@
<?php echo "&copy;&nbsp;".date('Y');?>г. Igor V Belousov

8
src/V/inc/head.php Обычный файл
Просмотреть файл

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="ru-RU">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/style.css">
<script src="/js/script.js"></script>
<title><?php echo $this->page_title; ?></title>
</head>

3
src/V/index.php Обычный файл
Просмотреть файл

@ -0,0 +1,3 @@
<?php
require __DIR__ . '/inc/head.php';
require __DIR__ . '/inc/body.php';

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

@ -8,8 +8,27 @@
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
use \PFRM\App;
$app = new App(); setlocale(LC_ALL,'ru_RU.UTF-8');
$app->setRoute('/^CAPCHA.png$/','CAPTCHA');
$app = new PFRM\App();
$app->config = (object) [
"views_dir" => __DIR__ . '/V/',
"public_dir" => dirname(__DIR__) . '/public/',
"db" => (object) [
'host' => '127.0.0.1',
'port' => '3306',
'dbname' => 'test',
'user' => 'testuser',
'password' => 'testpassword',
],
"controller_namespace" => "\\PTEST\\C\\",
"site_name" => "Доска объявлений"
];
$app->setRoute( '/^\/CAPTCHA.png$/', 'CAPTCHA' );
$app->setRoute( '|^/page/(?<id>\d+)/$|', 'Index', 'page');
$app->setRoute( '/^.*$/', 'error404' );
$app->run(); $app->run();