init
This commit is contained in:
commit
4b429c2429
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
config.php
|
||||
|
||||
|
12
config.sample.php
Normal file
12
config.sample.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"mysql" => [
|
||||
"hostname" => "localhost",
|
||||
"dbname" => "timecard",
|
||||
"username" => "root",
|
||||
"password" => ""
|
||||
],
|
||||
|
||||
"canonical" => "http://localhost/timecard/",
|
||||
];
|
4
index.php
Normal file
4
index.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/provide/autoload.php';
|
||||
|
57
provide/ClassLoader.php
Normal file
57
provide/ClassLoader.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
// ***************
|
||||
// ClassLoader
|
||||
// ***************
|
||||
|
||||
class ClassLoaderXProvide {
|
||||
private static $dirs;
|
||||
|
||||
public static function loadFunc($class)
|
||||
{
|
||||
foreach (self::directories() as $directory) {
|
||||
$file_name = $directory . DIRECTORY_SEPARATOR . $class . ".php";
|
||||
if (is_file($file_name) && is_readable($file_name)) {
|
||||
require_once $file_name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function loadClass($class) {
|
||||
$classPath = ltrim($class, '\\');
|
||||
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $classPath);
|
||||
foreach (self::directories() as $directory) {
|
||||
$file_name = $directory . DIRECTORY_SEPARATOR . $classPath . ".php";
|
||||
|
||||
if (is_file($file_name) && is_readable($file_name)) {
|
||||
require_once $file_name;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function regLibrary($dir) {
|
||||
self::$dirs[] = $dir;
|
||||
}
|
||||
|
||||
private static function directories() {
|
||||
if (empty(self::$dirs)) {
|
||||
$base = __DIR__;
|
||||
self::$dirs = array(
|
||||
$base . "/classes",
|
||||
);
|
||||
|
||||
if (defined("CLASS_DIR")) {
|
||||
self::$dirs[] = CLASS_DIR;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$dirs;
|
||||
}
|
||||
}
|
23
provide/autoload.php
Normal file
23
provide/autoload.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 DevRas All rights reserved.
|
||||
*/
|
||||
|
||||
@session_start();
|
||||
|
||||
require_once __DIR__ . '/ClassLoader.php';
|
||||
spl_autoload_register(array("ClassLoaderXProvide", "loadClass"));
|
||||
|
||||
$config = require_once __DIR__ . '/../config.php';
|
||||
$db = new IDB();
|
||||
if (!$db->Connect($config["mysql"]["hostname"],
|
||||
$config["mysql"]["dbname"],
|
||||
$config["mysql"]["username"],
|
||||
$config["mysql"]["password"])
|
||||
)
|
||||
{
|
||||
echo 'can not connect to mysql server.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = $db->getDB();
|
23
provide/classes/IDB.php
Normal file
23
provide/classes/IDB.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class IDB {
|
||||
public function __construct() {
|
||||
$this->pdo = null;
|
||||
}
|
||||
|
||||
private $pdo;
|
||||
|
||||
public function Connect($host, $name, $user, $pass) {
|
||||
try {
|
||||
$this->pdo = new PDO("mysql:dbname=" . $name . ";host=" . $host, $user, $pass);
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDB() {
|
||||
return $this->pdo;
|
||||
}
|
||||
}
|
||||
|
15
provide/classes/Timecard.php
Normal file
15
provide/classes/Timecard.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
class Timecard
|
||||
{
|
||||
public function __construct($pdo)
|
||||
{
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
protected $pdo;
|
||||
|
||||
public function InsertTime()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user