Framework: Database & UserControl
This commit is contained in:
parent
e9fca64d16
commit
9dcf00eb11
@ -1,4 +1,4 @@
|
||||
<?php namespace UElearning\Config;
|
||||
<?php namespace UElearning\Config\Exception;
|
||||
/**
|
||||
* @file
|
||||
* 設定檔的例外
|
||||
|
@ -8,11 +8,47 @@
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*/
|
||||
require_once UELEARNING_LIB_ROOT.'Database/Database.php';
|
||||
require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php';
|
||||
|
||||
/**
|
||||
* 資料庫整體管理
|
||||
*
|
||||
* 對資料庫的管理操作。
|
||||
*
|
||||
* 建立資料庫連結,若直接使用`config.php`設定的參數,使用以下即可:
|
||||
*
|
||||
* require_once __DIR__.'/config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'Database/DBAdmin.php';
|
||||
* use UElearning\Database;
|
||||
* $db = new Database\DBAdmin();
|
||||
*
|
||||
* 若要自行指定連結參數,請使用:
|
||||
*
|
||||
* use UElearning\Database;
|
||||
* $db = new Database\DBAdmin(array(
|
||||
* 'type' => 'mysql',
|
||||
* 'host' => 'localhost',
|
||||
* 'port' => '3306',
|
||||
* 'user' => 'user',
|
||||
* 'password' => '123456',
|
||||
* 'dbname' => 'chu-elearning',
|
||||
* 'prefix' => 'chu_'
|
||||
* ));
|
||||
*
|
||||
* 可參考以下範例:
|
||||
*
|
||||
* require_once __DIR__.'/config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'Database/DBAdmin.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
* try {
|
||||
* $db = new Database\DBAdmin();
|
||||
* } catch (Database\Exception\DatabaseNoSupportException $e) {
|
||||
* echo 'No Support in ', $e->getType();
|
||||
* } catch (Exception $e) {
|
||||
* echo 'Caught other exception: ', $e->getMessage();
|
||||
* }
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 3.0
|
||||
@ -21,4 +57,24 @@
|
||||
*/
|
||||
class DBAdmin extends Database {
|
||||
|
||||
/**
|
||||
* 建立資料庫
|
||||
*
|
||||
* 在資料庫系統內建立一個資料庫。
|
||||
* (注意!需有建立資料庫的權限)
|
||||
*
|
||||
*/
|
||||
public function createDB() {
|
||||
// TODO: Fill code in
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立所有所需的資料表
|
||||
*
|
||||
*/
|
||||
public function createAllTable() {
|
||||
// TODO: Fill code in
|
||||
|
||||
}
|
||||
}
|
@ -5,10 +5,24 @@
|
||||
*
|
||||
* 此檔案針對使用者資料表的功能。
|
||||
*
|
||||
* @filesource
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*/
|
||||
require_once UELEARNING_LIB_ROOT.'Database/Database.php';
|
||||
require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php';
|
||||
|
||||
class DBUser {
|
||||
/**
|
||||
* 使用者帳號資料表
|
||||
*
|
||||
* 對資料庫中的使用者資料表進行操作。
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 3.0
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBUser extends Database {
|
||||
/**
|
||||
* 資料表名稱
|
||||
* @type string
|
||||
|
@ -10,16 +10,17 @@
|
||||
*/
|
||||
require_once UELEARNING_LIB_ROOT.'Database/MySQLDB.php';
|
||||
require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php';
|
||||
use UElearning\Database\Exception;
|
||||
|
||||
/**
|
||||
* 資料庫整體管理
|
||||
* 資料庫操作抽象類別
|
||||
*
|
||||
* 所有對於資料庫的操作(包含查詢、新增、修改、刪除),一律使用這個物件來操作。
|
||||
* 請根據一個資料表創建一個類別,並繼承此類別。所有對於資料表的操作(包含查詢、新增、修改、刪除),一律使用新創已繼承的類別物件。
|
||||
*
|
||||
* 例如:
|
||||
* 基本的操作方式例如:
|
||||
*
|
||||
* use UElearning\Database;
|
||||
* $db = new Database(array(
|
||||
* $db = new Database\[資料表類別](array(
|
||||
* 'type' => 'mysql',
|
||||
* 'host' => 'localhost',
|
||||
* 'port' => '3306',
|
||||
@ -29,14 +30,14 @@ require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php';
|
||||
* 'prefix' => 'chu_'
|
||||
* ));
|
||||
*
|
||||
* 一個資料表為一個類別,如果要對某資料表進行操作,請參閱
|
||||
* 實際範例可參考 `DBAdmin` 類別的說明文件
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 3.0
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*/
|
||||
class Database {
|
||||
abstract class Database {
|
||||
|
||||
/**
|
||||
* 資料庫伺服器類型
|
||||
@ -107,6 +108,7 @@ class Database {
|
||||
* 'prefix' => 'chu_' )
|
||||
* 若不填寫將會直接使用設定在`config.php`的常數
|
||||
*
|
||||
* @throws UElearning\Database\Exception\DatabaseNoSupportException
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@ -137,7 +139,7 @@ class Database {
|
||||
$this->connDB = new MySQLDB($this->db_name, $this->db_host, $this->db_port, $this->db_user, $this->db_passwd);
|
||||
}
|
||||
else {
|
||||
throw new DatabaseNoSupportException($this->db_type);
|
||||
throw new Exception\DatabaseNoSupportException($this->db_type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,25 +165,4 @@ class Database {
|
||||
// TODO: Fill code in
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立資料庫
|
||||
*
|
||||
* 在資料庫系統內建立一個資料庫。
|
||||
* (注意!需有建立資料庫的權限)
|
||||
*
|
||||
*/
|
||||
public function createDB() {
|
||||
// TODO: Fill code in
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立所有所需的資料表
|
||||
*
|
||||
*/
|
||||
public function createAllTable() {
|
||||
// TODO: Fill code in
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
<?php namespace UElearning\Database;
|
||||
<?php namespace UElearning\Database\Exception;
|
||||
/**
|
||||
* @file
|
||||
* 設定檔的例外
|
||||
*
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 沒有支援的資料庫系統例外
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class DatabaseNoSupportException extends \UnexpectedValueException {
|
||||
private $type;
|
||||
|
@ -1,24 +0,0 @@
|
||||
<?php namespace UElearning\User;
|
||||
/**
|
||||
* @file
|
||||
* 管理使用者的操作
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 使用者管理
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
class UserAdmin {
|
||||
|
||||
/**
|
||||
* 建立使用者
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function createUser() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php namespace UElearning\User;
|
||||
/**
|
||||
* @file
|
||||
* 管理使用者的操作
|
||||
*
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
|
||||
/**
|
||||
* 使用者帳號管理
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 3.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
class UserControl {
|
||||
|
||||
/**
|
||||
* 建立使用者
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function create() {
|
||||
// TODO: Fill code in
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否已有相同名稱的帳號名稱
|
||||
*
|
||||
* @param string $userName 帳號名稱
|
||||
* @return bool 已有相同的帳號名稱
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function isHave($userName) {
|
||||
// TODO: Fill code in
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用者登入
|
||||
* @param string $userId 帳號名稱
|
||||
* @param string $password 密碼
|
||||
* @return string 登入session token
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function login($userId, $password) {
|
||||
// TODO: Fill code in
|
||||
// 如果登入錯誤,就丟例外
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user