dbms_primeidc_init...1

This commit is contained in:
최준흠 2025-04-10 09:39:36 +09:00
parent 6e1d7e91a8
commit b831443582
9 changed files with 346 additions and 13 deletions

View File

@ -49,8 +49,10 @@ class PaymentController extends ClientController
//Client_Code = ["C219"=>WinIDC,"C116"=>IDC-JP"] -> 미지급금계산 제외 Client_Code
$exclude_clients = ['C116', 'C219'];
//mode 당일,1일전,2일전,3일전,custom
$today = date("Y-m-d");
switch ($params['mode']) {
$today = date("Y-m-d");;
echo var_dump($this->getRequest()->get());
exit;
switch ($this->getRequest()->get('mode')) {
case 'today':
$this->getServiceService()->getModel()->where("service_payment_date = CURDATE()");
$this->message = "[{$today} 기준 당일 ";

View File

@ -5,19 +5,13 @@ namespace lib\Core;
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Configs' . DIRECTORY_SEPARATOR . 'Constant.php';
use lib\Configs\View;
use lib\Http\Request;
abstract class Controller
{
private $_request = null;
private ?View $_view = null;
protected function __construct()
{
$this->_view = new View();
} //
final public function getView(): View
{
return $this->_view;
}
private ?Request $_request = null;
protected function __construct() {} //
final public function __get($name)
{
return $this->getView()->$name;
@ -26,8 +20,22 @@ abstract class Controller
{
$this->getView()->$name = $value;
}
final public function getView(): View
{
if ($this->_view === null) {
$this->_view = new View();
}
return $this->_view;
}
public function render(string $path)
{
return $this->getView()->render($path);
}
final public function getRequest(): Request
{
if ($this->_request === null) {
$this->_request = new Request();
}
return $this->_request;
}
} //Class

View File

@ -0,0 +1,15 @@
<?php
namespace lib\Http;
class BearerToken extends HTTP
{
public function token(): ?string
{
$header = $this->getHeader('Authorization');
if ($header && str_starts_with($header, 'Bearer ')) {
return substr($header, 7);
}
return null;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace lib\Http;
class Cookie
{
public function get(string $key, $default = null): mixed
{
return $_COOKIE[$key] ?? $default;
}
public function set(string $key, $value, int $expire = 3600, string $path = '/'): void
{
setcookie($key, $value, time() + $expire, $path);
}
public function remove(string $key): void
{
setcookie($key, '', time() - 3600, '/');
}
}

28
extdbms/lib/Http/Http.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace lib\Http;
class HTTP
{
protected array $headers = [];
public function __construct()
{
$this->headers = foreach ($_SERVER as $name => $value) {
if (str_starts_with($name, 'HTTP_')) {
$key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$headers[$key] = $value;
}
}
}
public function getHeaders(): array
{
return $this->headers;
}
public function getHeader(string $key): ?string
{
return $this->headers[$key] ?? null;
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace lib\Http;
class Request extends HTTP
{
protected array $get;
protected array $post;
protected array $data;
public function __construct()
{
parent::__construct();
$this->get = $_GET;
$this->post = $_POST;
$this->data = array_merge($_GET, $_POST, json_decode(file_get_contents('php://data'), true) ?? []);
}
public function all(): array
{
return $this->data;
}
public function get(?string $key = null, $default = null): mixed
{
if ($key === null) {
return $this->all();
}
return $this->data[$key] ?? $default;
}
public function only(array $keys): array
{
return array_intersect_key($this->data, array_flip($keys));
}
public function has(string $key): bool
{
return array_key_exists($key, $this->data);
}
/**
* Validator 연동
*/
//사용예:
// $request = new Request();
// $validation = $request->validate([
// 'username' => 'required|alpha_numeric|min[4]',
// 'email' => 'required|email',
// 'password' => 'required|min[6]'
// ]);
// if ($validation !== true) {
// // 에러 처리
// print_r($validation);
// } else {
// // 통과
// echo "유효성 검사 통과!";
// }
public function validate(array $rules, array $messages = []): bool|array
{
$validator = new Validator();
$validator->setData($this->all())->setRules($rules)->setMessages($messages);
if (!$validator->run()) {
return $validator->errors();
}
return true;
}
}

View File

@ -1,9 +1,14 @@
<?php
namespace lib\Core;
namespace lib\Http;
class Response
class Response extends HTTP
{
public function __construct()
{
parent::__construct();
}
public static function json($data, int $status = 200)
{
http_response_code($status);

View File

@ -0,0 +1,33 @@
<?php
namespace lib\Http;
class Session
{
public function start(): void
{
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
}
public function get(string $key, $default = null): mixed
{
return $_SESSION[$key] ?? $default;
}
public function set(string $key, $value): void
{
$_SESSION[$key] = $value;
}
public function remove(string $key): void
{
unset($_SESSION[$key]);
}
public function destroy(): void
{
session_destroy();
}
}

View File

@ -0,0 +1,148 @@
<?php
namespace lib\Http;
//사용법
// $validator = new \lib\Http\Validator();
// $validator->setData([
// 'username' => 'admin123',
// 'email' => 'admin@example.com',
// 'password' => '1234'
// ])->setRules([
// 'username' => 'required|alpha_numeric|min[4]|max[20]',
// 'email' => 'required|email',
// 'password' => 'required|min[6]'
// ]);
// if (!$validator->run()) {
// print_r($validator->errors());
// }
class Validator
{
protected array $data = [];
protected array $rules = [];
protected array $errors = [];
protected array $customMessages = [];
protected array $availableRules = [
'required',
'min',
'max',
'email',
'numeric',
'alpha',
'alpha_numeric'
];
public function setData(array $data): self
{
$this->data = $data;
return $this;
}
public function setRules(array $rules): self
{
$this->rules = $rules;
return $this;
}
public function setMessages(array $messages): self
{
$this->customMessages = $messages;
return $this;
}
public function run(): bool
{
$this->errors = [];
foreach ($this->rules as $field => $ruleStr) {
$rules = explode('|', $ruleStr);
$value = $this->data[$field] ?? null;
foreach ($rules as $rule) {
$param = null;
if (strpos($rule, '[') !== false) {
preg_match('/(\w+)\[(.*?)\]/', $rule, $matches);
$rule = $matches[1];
$param = $matches[2];
}
$method = "validate_$rule";
if (method_exists($this, $method)) {
$result = $this->$method($value, $param);
if (!$result) {
$this->addError($field, $rule, $param);
}
}
}
}
return empty($this->errors);
}
public function errors(): array
{
return $this->errors;
}
protected function addError(string $field, string $rule, $param = null): void
{
$message = $this->customMessages["$field.$rule"] ?? $this->defaultMessage($field, $rule, $param);
$this->errors[$field][] = $message;
}
protected function defaultMessage(string $field, string $rule, $param): string
{
return match ($rule) {
'required' => "$field is required.",
'min' => "$field must be at least $param characters.",
'max' => "$field must be at most $param characters.",
'email' => "$field must be a valid email address.",
'numeric' => "$field must be a number.",
'alpha' => "$field must contain only letters.",
'alpha_numeric' => "$field must contain only letters and numbers.",
default => "$field is invalid.",
};
}
// --- 기본 유효성 검사 메서드 ---
protected function validate_required($value): bool
{
return !empty($value) || $value === '0';
}
protected function validate_min($value, $param): bool
{
return strlen($value) >= (int)$param;
}
protected function validate_max($value, $param): bool
{
return strlen($value) <= (int)$param;
}
protected function validate_email($value): bool
{
return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
}
protected function validate_numeric($value): bool
{
return is_numeric($value);
}
protected function validate_alpha($value): bool
{
return ctype_alpha($value);
}
protected function validate_alpha_numeric($value): bool
{
return ctype_alnum($value);
}
// 사용자 정의 규칙도 등록할 수 있도록 향후 확장 가능
}