Add my template project

This commit is contained in:
2024-08-09 21:30:13 +05:00
parent 0e0ac4f094
commit 832bf929dc
19 changed files with 243 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
class Root {
private static $installed = false;
public static function init() {
self::$installed = floatval(file_get_contents(__RD__.'installed'));
}
public static function url($url, $force = true) {
header('Location: '.$url);
if($force) exit();
}
public static function installed() {
return self::$installed;
}
}
Root::init();

60
engine/class/0001.db.php Normal file
View File

@ -0,0 +1,60 @@
<?php
class DB {
private static $pdos = [];
public static function init($conf = []) {
try {
foreach($conf as $title => $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!');
}

View File

@ -0,0 +1,37 @@
<?php
// REQUIREMENTS:
// 0001.db.php
class Debug {
public static function init() {
if(!Root::installed())
self::createTables();
}
public static function createTables() {
DB::getQuery('main',
'CREATE TABLE IF NOT EXISTS `debug_log` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`value` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
CHARSET=utf8
COLLATE utf8_general_ci'
);
}
public static function print($a, $b = false) {
echo '<pre>';
$b ? var_dump($a) : print_r($a);
echo '</pre>';
}
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();

13
engine/core/api.php Normal file
View File

@ -0,0 +1,13 @@
<?php
header('Content-Type: application/json');
if(file_exists(__CD__.'api/'.__URL__[1].'/'.__URL__[2].'.php'))
require __CD__.'api/'.__URL__[1].'/'.__URL__[2].'.php';
else
$data = [
'error' => true,
'message' => 'Endpoint not exists.',
];
echo json_encode($data);
exit();

View File

@ -0,0 +1,5 @@
<?php
$data = [
'error' => false,
'message' => 'test',
];

3
engine/core/index.php Normal file
View File

@ -0,0 +1,3 @@
<?php
require __CD__.'route.php';
require __TD__.'index.php';

1
engine/core/main.php Normal file
View File

@ -0,0 +1 @@
<?php

5
engine/core/route.php Normal file
View File

@ -0,0 +1,5 @@
<?php
if(__URI__ == '/' || in_array(__URL__[0], ['index', 'route']))
Root::url('/main');
elseif(file_exists(__CD__.__URL__[0].'.php'))
require __CD__.__URL__[0].'.php';