This commit is contained in:
kemasama 2022-05-22 11:40:31 +09:00
commit 4b429c2429
7 changed files with 137 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
config.php

12
config.sample.php Normal file
View File

@ -0,0 +1,12 @@
<?php
return [
"mysql" => [
"hostname" => "localhost",
"dbname" => "timecard",
"username" => "root",
"password" => ""
],
"canonical" => "http://localhost/timecard/",
];

4
index.php Normal file
View File

@ -0,0 +1,4 @@
<?php
require_once __DIR__ . '/provide/autoload.php';

57
provide/ClassLoader.php Normal file
View 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
View 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
View 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;
}
}

View File

@ -0,0 +1,15 @@
<?php
class Timecard
{
public function __construct($pdo)
{
$this->pdo = $pdo;
}
protected $pdo;
public function InsertTime()
{
}
}