From 832bf929dc187a71fc4afb9c2bfb31a66c688c7a Mon Sep 17 00:00:00 2001 From: BitHeaven Date: Fri, 9 Aug 2024 21:30:13 +0500 Subject: [PATCH] Add my template project --- config/0000.root.php | 9 ++++++ config/0001.db.php | 13 ++++++++ engine/class/0000.root.php | 19 ++++++++++++ engine/class/0001.db.php | 60 +++++++++++++++++++++++++++++++++++++ engine/class/0002.debug.php | 37 +++++++++++++++++++++++ engine/core/api.php | 13 ++++++++ engine/core/api/v1/test.php | 5 ++++ engine/core/index.php | 3 ++ engine/core/main.php | 1 + engine/core/route.php | 5 ++++ index.php | 38 +++++++++++++++++++++++ installed | 1 + template/css/style.css | 0 template/footer.php | 8 +++++ template/header.php | 19 ++++++++++++ template/index.php | 4 +++ template/js/index.js | 0 template/main.php | 1 + template/route.php | 7 +++++ 19 files changed, 243 insertions(+) create mode 100644 config/0000.root.php create mode 100644 config/0001.db.php create mode 100644 engine/class/0000.root.php create mode 100644 engine/class/0001.db.php create mode 100644 engine/class/0002.debug.php create mode 100644 engine/core/api.php create mode 100644 engine/core/api/v1/test.php create mode 100644 engine/core/index.php create mode 100644 engine/core/main.php create mode 100644 engine/core/route.php create mode 100644 index.php create mode 100644 installed create mode 100644 template/css/style.css create mode 100644 template/footer.php create mode 100644 template/header.php create mode 100644 template/index.php create mode 100644 template/js/index.js create mode 100644 template/main.php create mode 100644 template/route.php diff --git a/config/0000.root.php b/config/0000.root.php new file mode 100644 index 0000000..6f5818f --- /dev/null +++ b/config/0000.root.php @@ -0,0 +1,9 @@ + 'Тестовый сайт', + 'description' => 'Описание сайта для embed ссылок', + 'keywords' => [ + 'ключевые', + 'слова', + ], + ]; diff --git a/config/0001.db.php b/config/0001.db.php new file mode 100644 index 0000000..151b3fd --- /dev/null +++ b/config/0001.db.php @@ -0,0 +1,13 @@ + [ + 'driver' => 'mysql', + 'user' => 'root', + 'password' => '', + 'name' => 'user-rest-api', + 'host' => '127.0.0.1', + 'port' => 3306, + 'charset' => 'utf8', + 'options' => [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] + ] + ]; diff --git a/engine/class/0000.root.php b/engine/class/0000.root.php new file mode 100644 index 0000000..14ff523 --- /dev/null +++ b/engine/class/0000.root.php @@ -0,0 +1,19 @@ + $data) { + $dsn = sprintf('%s:dbname=%s;host=%s;port=%d;charset=%s', + $data['driver'], + $data['name'], + $data['host'], + $data['port'], + $data['charset'] + ); + self::$pdos[$title] = new PDO($dsn, $data['user'], $data['password'], $data['options']); + } + return true; + } + catch(\Throwable $th) { + return false; + } + } + + public static function getQuery($db, $sql, $args = null) { + if(!is_array($args) && !empty($args)) + $args = [$args]; + + $stmt = self::$pdos[$db]->prepare($sql); + + try { + $stmt->execute($args); + } + catch(\Throwable $th) { + Debug::print($sql); + Debug::print($args); + Debug::print($th); + } + + if(stristr($sql, 'SELECT')) + return $stmt->fetch(PDO::FETCH_OBJ); + + if(stristr($sql, 'INSERT')) + return self::$pdos[$db]->lastInsertId(); + + return true; + } + + public static function getQueryAll($db, $sql, $args = null) { + if(!is_array($args) && !empty($args)) + $args = [$args]; + + $stmt = self::$pdos[$db]->prepare($sql); + $stmt->execute($args); + return $stmt->fetchAll(PDO::FETCH_OBJ); + } + } + + if(!DB::init($config['db'])) { + die('DB not connected! Recheck configs!'); + } diff --git a/engine/class/0002.debug.php b/engine/class/0002.debug.php new file mode 100644 index 0000000..44ef6d8 --- /dev/null +++ b/engine/class/0002.debug.php @@ -0,0 +1,37 @@ +'; + $b ? var_dump($a) : print_r($a); + echo ''; + } + + public static function log($string) { + $string = date('H:i:s d.m.Y', time()).' | '.$string; + DB::getQuery('main', 'INSERT INTO `debug_log` (`value`) VALUES (?)', $string); + return true; + } + } + +// Debug::init(); diff --git a/engine/core/api.php b/engine/core/api.php new file mode 100644 index 0000000..fe71f4f --- /dev/null +++ b/engine/core/api.php @@ -0,0 +1,13 @@ + true, + 'message' => 'Endpoint not exists.', + ]; + + echo json_encode($data); + exit(); diff --git a/engine/core/api/v1/test.php b/engine/core/api/v1/test.php new file mode 100644 index 0000000..01fd09d --- /dev/null +++ b/engine/core/api/v1/test.php @@ -0,0 +1,5 @@ + false, + 'message' => 'test', + ]; diff --git a/engine/core/index.php b/engine/core/index.php new file mode 100644 index 0000000..be8f494 --- /dev/null +++ b/engine/core/index.php @@ -0,0 +1,3 @@ + 3*60*60, + ]); + + try { + define('__URI__', strstr($_SERVER['REQUEST_URI'], '?', true) ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']); + define('__URL__', explode('/', substr(__URI__, 1))); + + define('__RD__', dirname(__FILE__).'/'); + define('__TD__', __RD__.'template/'); + define('__ED__', __RD__.'engine/'); + define('__CF__', __RD__.'config/'); + define('__CD__', __ED__.'core/'); + define('__CL__', __ED__.'class/'); + + define('__RS__', '/'); + define('__TS__', __RS__.'template/'); + define('__CS__', __TS__.'css/'); + define('__JS__', __TS__.'js/'); + define('__IS__', __TS__.'img/'); + define('__US__', __RS__.'uploads/'); + + $config = []; + foreach(scandir(__CF__) as $a) + if($a != '.' && $a != '..') + require __CF__.$a; + + foreach(scandir(__CL__) as $a) + if($a != '.' && $a != '..') + require __CL__.$a; + + require __CD__.'index.php'; + } + catch(\Throwable $th) { + echo '
';
+		print_r($th);
+	}
diff --git a/installed b/installed
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/installed
@@ -0,0 +1 @@
+0
diff --git a/template/css/style.css b/template/css/style.css
new file mode 100644
index 0000000..e69de29
diff --git a/template/footer.php b/template/footer.php
new file mode 100644
index 0000000..2aab5a0
--- /dev/null
+++ b/template/footer.php
@@ -0,0 +1,8 @@
+	
+
+	
+
+

© Тестовый сайт 2024

+
+ + diff --git a/template/header.php b/template/header.php new file mode 100644 index 0000000..cc009fa --- /dev/null +++ b/template/header.php @@ -0,0 +1,19 @@ + + + + + + + + + + + <?=$config['root']['title']?> + + +
+

Тестовый REST API сайт

+
+
+ +
diff --git a/template/index.php b/template/index.php new file mode 100644 index 0000000..eb0ad52 --- /dev/null +++ b/template/index.php @@ -0,0 +1,4 @@ +Прочтите README.md файл для получения информации по API.

diff --git a/template/route.php b/template/route.php new file mode 100644 index 0000000..efb7aa7 --- /dev/null +++ b/template/route.php @@ -0,0 +1,7 @@ +