[+] Добавлен шаблонизатор твиг и роутинг под него
This commit is contained in:
1 parent
69243e97f1
commit
4e8ea1514e
14 files changed
+395
-18
No files matched your search
+3
-1
@@ -14,5 +14,7 @@
|
||||
"email": "rsgrinko@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"require": {
|
||||
"twig/twig": "^3.0"
|
||||
}
|
||||
}
|
||||
Generated
+244
-2
@@ -4,8 +4,250 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "76495c532399aad23bb670f0202d18a2",
|
||||
"packages": [],
|
||||
"content-hash": "686f24e92c5bf479bf32f07bc4124026",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.26.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
|
||||
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.26-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-05-24T11:49:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.26.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
|
||||
"reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.26-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-05-24T11:49:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "e939eae92386b69b49cfa4599dd9bead6bf4a342"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/e939eae92386b69b49cfa4599dd9bead6bf4a342",
|
||||
"reference": "e939eae92386b69b49cfa4599dd9bead6bf4a342",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony/polyfill-ctype": "^1.8",
|
||||
"symfony/polyfill-mbstring": "^1.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"psr/container": "^1.0",
|
||||
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Twig\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com",
|
||||
"homepage": "http://fabien.potencier.org",
|
||||
"role": "Lead Developer"
|
||||
},
|
||||
{
|
||||
"name": "Twig Team",
|
||||
"role": "Contributors"
|
||||
},
|
||||
{
|
||||
"name": "Armin Ronacher",
|
||||
"email": "armin.ronacher@active-4.com",
|
||||
"role": "Project Founder"
|
||||
}
|
||||
],
|
||||
"description": "Twig, the flexible, fast, and secure template language for PHP",
|
||||
"homepage": "https://twig.symfony.com",
|
||||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.4.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-05-17T05:48:52+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
|
||||
+15
-2
@@ -11,6 +11,7 @@
|
||||
}
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
|
||||
ob_start(function($buffer) {
|
||||
try {
|
||||
Template::set('CLEAR_CACHE_LINK_NAME', 'Сброс файлового кэша');
|
||||
@@ -28,6 +29,8 @@
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Реализация механизма автозагрузки классов
|
||||
*/
|
||||
@@ -43,7 +46,15 @@
|
||||
|
||||
require_once __DIR__ . '/routes.php';
|
||||
|
||||
Cache::init(ROOT_PATH . '/core/cache/', USE_CACHE);
|
||||
/**
|
||||
* Инициализация шаблонизатора
|
||||
*/
|
||||
$loader = new \Twig\Loader\FilesystemLoader(PATH_TO_TEMPLATES);
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
//'cache' => CACHE_DIR,
|
||||
]);
|
||||
|
||||
Cache::init(CACHE_DIR, USE_CACHE);
|
||||
|
||||
// очистка кэша
|
||||
if(isset($_REQUEST['clear_cache']) && $_REQUEST['clear_cache'] === CODE_VALUE_Y) {
|
||||
@@ -70,6 +81,8 @@
|
||||
$USER = null;
|
||||
}
|
||||
|
||||
// запускаем маршрутизатор, передавая ему запрошенный адрес
|
||||
/**
|
||||
* Запускаем маршрутизатор
|
||||
*/
|
||||
Router::execute();
|
||||
die();
|
||||
@@ -24,6 +24,11 @@
|
||||
const DB_PASSWORD = '2670135';
|
||||
const DB_NAME = 'rsgrinko_delta';
|
||||
|
||||
/**
|
||||
* Путь до шаблонов
|
||||
*/
|
||||
const PATH_TO_TEMPLATES = ROOT_PATH . '/templates';
|
||||
|
||||
/**
|
||||
* Токен телеграм бота
|
||||
*/
|
||||
@@ -43,6 +48,12 @@
|
||||
* Использование кэша
|
||||
*/
|
||||
const USE_CACHE = false;
|
||||
|
||||
/**
|
||||
* Папка кэша
|
||||
*/
|
||||
const CACHE_DIR = ROOT_PATH . '/core/cache';
|
||||
|
||||
/**
|
||||
* Время жизни кэша
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Core;
|
||||
|
||||
class App
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
global $twig;
|
||||
$navbarItems = [
|
||||
['name' => 'Главная', 'url' => '/', 'active' => true],
|
||||
['name' => 'Админка', 'url' => '/admin', 'active' => false],
|
||||
['name' => 'Командная PHP строка', 'url' => '/phpcmd.php', 'active' => false],
|
||||
['name' => 'Тест', 'url' => '/test', 'active' => false],
|
||||
];
|
||||
echo $twig->render('index.twig', ['navbarItems' => $navbarItems, 'name' => 'Roman Grinko']);
|
||||
}
|
||||
|
||||
public static function test(int $id = 1)
|
||||
{
|
||||
global $twig;
|
||||
$navbarItems = [
|
||||
['name' => 'Главная', 'url' => '/', 'active' => true],
|
||||
['name' => 'Админка', 'url' => '/admin', 'active' => false],
|
||||
['name' => 'Командная PHP строка', 'url' => '/phpcmd.php', 'active' => false],
|
||||
['name' => 'Тест', 'url' => '/test', 'active' => false],
|
||||
];
|
||||
|
||||
$res = (new \Core\Models\User($id))->getAllUserData();
|
||||
echo $twig->render('test.twig', ['navbarItems' => $navbarItems, 'userId' => $id, 'res' => print_r($res, true)]);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@
|
||||
*/
|
||||
public static function init(string $dir, $enabled = true): void
|
||||
{
|
||||
self::$cacheDir = $dir;
|
||||
self::$cacheDir = $dir . '/';
|
||||
self::$cacheEnabled = $enabled;
|
||||
}
|
||||
|
||||
|
||||
@@ -359,4 +359,16 @@
|
||||
}
|
||||
return $table;
|
||||
}
|
||||
|
||||
|
||||
public static function showPage()
|
||||
{
|
||||
$loader = new \Twig\Loader\FilesystemLoader(PATH_TO_TEMPLATES);
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => CACHE_DIR,
|
||||
]);
|
||||
|
||||
echo $twig->render('index.tpl', ['name' => 'Roman']);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Core\Models;
|
||||
|
||||
|
||||
class Router
|
||||
{
|
||||
|
||||
|
||||
+3
-12
@@ -1,11 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Core\Models\Router;
|
||||
use Core\Helpers\SystemFunctions;
|
||||
|
||||
Router::route('/', function () {
|
||||
echo 'Домашняя станица';
|
||||
});
|
||||
Router::route('/', '\Core\App::index');
|
||||
|
||||
Router::route('/404', function () {
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
@@ -19,14 +16,8 @@
|
||||
|
||||
|
||||
|
||||
class Test {
|
||||
public static function run($num = 0, $d = 0) {
|
||||
echo 'Hello World! ('.$num.') - ('.$d.')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Router::route('/test/(\w+)/(\d+)', 'Test::run');
|
||||
Router::route('/test', '\Core\App::test');
|
||||
Router::route('/test/(\d+)', '\Core\App::test');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{% extends 'layout.twig' %}
|
||||
|
||||
|
||||
|
||||
{% block title %}Главная страница{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
тут текст главной страницы
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
|
||||
<title>{% block title %}Тестовый заголовок{% endblock %}</title>
|
||||
<style>
|
||||
main > .container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
{{ include('parts/navbar/navbar.twig', {'navbarItems': navbarItems}) }}
|
||||
<div class="container">
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-md">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{{ include('parts/footer.twig') }}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<footer class="py-3 my-4">
|
||||
<ul class="nav justify-content-center border-bottom pb-3 mb-3">
|
||||
<li class="nav-item"><a href="#" class="nav-link px-2 text-muted">Home</a></li>
|
||||
<li class="nav-item"><a href="#" class="nav-link px-2 text-muted">Features</a></li>
|
||||
<li class="nav-item"><a href="#" class="nav-link px-2 text-muted">Pricing</a></li>
|
||||
<li class="nav-item"><a href="#" class="nav-link px-2 text-muted">FAQs</a></li>
|
||||
<li class="nav-item"><a href="#" class="nav-link px-2 text-muted">About</a></li>
|
||||
</ul>
|
||||
<p class="text-center text-muted">Дичь всякую творим ночью...</p> <p class="text-center text-muted">© 2022 Delta Project</p>
|
||||
</footer>
|
||||
@@ -0,0 +1,18 @@
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark" aria-label="Fourth navbar example">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Delta Framework</a>
|
||||
<button class="navbar-toggler collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="navbar-collapse collapse" id="navbarsExample04" style="">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-md-0">
|
||||
{% for item in navbarItems %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if item.active %}active{% endif %}" aria-current="page" href="{{ item.url }}">{{ item.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -0,0 +1,8 @@
|
||||
{% extends 'layout.twig' %}
|
||||
|
||||
{% block title %}тестинг{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
User id: {{ userId }}<br>
|
||||
<pre>{{ res }}</pre>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user