Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • ArrayIterator
  • DateInterval
  • DOMNode
  • Kotchasan
  • Kotchasan\Accordion
  • Kotchasan\ApiController
  • Kotchasan\ArrayTool
  • Kotchasan\Cache\ApcCache
  • Kotchasan\Cache\Cache
  • Kotchasan\Cache\CacheItem
  • Kotchasan\Cache\FileCache
  • Kotchasan\CKEditor
  • Kotchasan\Collection
  • Kotchasan\Config
  • Kotchasan\Controller
  • Kotchasan\Country
  • Kotchasan\Csv
  • Kotchasan\Curl
  • Kotchasan\Currency
  • Kotchasan\Database
  • Kotchasan\Database\Db
  • Kotchasan\Database\DbCache
  • Kotchasan\Database\Driver
  • Kotchasan\Database\PdoMysqlDriver
  • Kotchasan\Database\Query
  • Kotchasan\Database\QueryBuilder
  • Kotchasan\Database\Schema
  • Kotchasan\Database\Sql
  • Kotchasan\DataTable
  • Kotchasan\Date
  • Kotchasan\DOMNode
  • Kotchasan\DOMParser
  • Kotchasan\Email
  • Kotchasan\File
  • Kotchasan\Files
  • Kotchasan\Form
  • Kotchasan\Grid
  • Kotchasan\Html
  • Kotchasan\Htmldoc
  • Kotchasan\HtmlTable
  • Kotchasan\Http\AbstractMessage
  • Kotchasan\Http\AbstractRequest
  • Kotchasan\Http\Message
  • Kotchasan\Http\NotFound
  • Kotchasan\Http\Request
  • Kotchasan\Http\Response
  • Kotchasan\Http\Stream
  • Kotchasan\Http\UploadedFile
  • Kotchasan\Http\Uri
  • Kotchasan\Image
  • Kotchasan\InputItem
  • Kotchasan\Inputs
  • Kotchasan\KBase
  • Kotchasan\Language
  • Kotchasan\ListItem
  • Kotchasan\Log\AbstractLogger
  • Kotchasan\Log\Logger
  • Kotchasan\Login
  • Kotchasan\Menu
  • Kotchasan\Mime
  • Kotchasan\Model
  • Kotchasan\Number
  • Kotchasan\ObjectTool
  • Kotchasan\Orm\Field
  • Kotchasan\Orm\Recordset
  • Kotchasan\Password
  • Kotchasan\Pdf
  • Kotchasan\Province
  • Kotchasan\Router
  • Kotchasan\Session
  • Kotchasan\Singleton
  • Kotchasan\Tab
  • Kotchasan\TableRow
  • Kotchasan\Template
  • Kotchasan\Text
  • Kotchasan\Validator
  • Kotchasan\View
  • PHPMailer
  • Psr\Log\AbstractLogger
  • Psr\Log\LogLevel
  • Psr\Log\NullLogger
  • SMTP

Interfaces

  • ArrayAccess
  • Countable
  • DateTimeInterface
  • Iterator
  • IteratorAggregate
  • Psr\Cache\CacheItemInterface
  • Psr\Cache\CacheItemPoolInterface
  • Psr\Http\Message\MessageInterface
  • Psr\Http\Message\RequestInterface
  • Psr\Http\Message\ResponseInterface
  • Psr\Http\Message\ServerRequestInterface
  • Psr\Http\Message\StreamInterface
  • Psr\Http\Message\UploadedFileInterface
  • Psr\Http\Message\UriInterface
  • Psr\Log\LoggerAwareInterface
  • Psr\Log\LoggerInterface
  • SeekableIterator
  • Serializable
  • Traversable

Traits

  • Psr\Log\LoggerTrait

Exceptions

  • Exception
  • InvalidArgumentException
  • Kotchasan\ApiException
  • Kotchasan\Cache\Exception
  • Kotchasan\Database\Exception
  • Kotchasan\InputItemException
  • LogicException
  • phpmailerException
  • RuntimeException

Functions

  • createClass
  • debug
  • getClassPath
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @filesource Kotchasan/load.php
  4:  *
  5:  * ไฟล์หลักสำหรับกำหนดค่าเริ่มต้นในการโหลดเฟรมเวิร์ค
  6:  * ต้อง include ไฟล์นี้ก่อนเสมอ
  7:  *
  8:  * @copyright 2016 Goragod.com
  9:  * @license http://www.kotchasan.com/license/
 10:  *
 11:  * @see http://www.kotchasan.com/
 12:  */
 13: 
 14: /**
 15:  * การแสดงข้อผิดพลาด
 16:  * 0 บันทึกข้อผิดพลาดร้ายแรงลง error_log .php (ขณะใช้งานจริง)
 17:  * 1 บันทึกข้อผิดพลาดและคำเตือนลง error_log .php
 18:  * 2 แสดงผลข้อผิดพลาดและคำเตือนออกทางหน้าจอ (เฉพาะตอนออกแบบเท่านั้น).
 19:  *
 20:  * @var int
 21:  */
 22: if (!defined('DEBUG')) {
 23:     define('DEBUG', 0);
 24: }
 25: /* display error */
 26: if (DEBUG > 0) {
 27:     /* ขณะออกแบบ แสดง error และ warning ของ PHP */
 28:     ini_set('display_errors', 1);
 29:     ini_set('display_startup_errors', 1);
 30:     error_reporting(-1);
 31: } else {
 32:     /* ขณะใช้งานจริง */
 33:     error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
 34: }
 35: /*
 36:  * Framework Version
 37:  *
 38:  * @var string
 39:  */
 40: define('VERSION', '4.0.0');
 41: /*
 42:  * กำหนดการบันทึกการ query ฐานข้อมูล
 43:  * ควรกำหนดเป็น false ขณะใช้งานจริง
 44:  *
 45:  * $var bool
 46:  */
 47: if (!defined('DB_LOG')) {
 48:     define('DB_LOG', false);
 49: }
 50: /**
 51:  * ไดเรคทอรี่ของ Framework.
 52:  */
 53: $vendorDir = str_replace('load.php', '', __FILE__);
 54: if (DIRECTORY_SEPARATOR != '/') {
 55:     $vendorDir = str_replace('\\', '/', $vendorDir);
 56: }
 57: define('VENDOR_DIR', $vendorDir);
 58: /*
 59:  * พาธของ Server ตั้งแต่ระดับราก เช่น D:/htdocs/Somtum/
 60:  */
 61: $docRoot = dirname($vendorDir);
 62: if (!defined('ROOT_PATH')) {
 63:     define('ROOT_PATH', $docRoot.'/');
 64: }
 65: /**
 66:  *  document root (Server).
 67:  */
 68: $contextPrefix = '';
 69: if (isset($_SERVER['APPL_PHYSICAL_PATH'])) {
 70:     $docRoot = rtrim(realpath($_SERVER['APPL_PHYSICAL_PATH']), DIRECTORY_SEPARATOR);
 71:     if (DIRECTORY_SEPARATOR != '/' && $docRoot != '') {
 72:         $docRoot = str_replace('\\', '/', $docRoot);
 73:     }
 74: } elseif (strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']) !== false) {
 75:     $docRoot = rtrim(realpath($_SERVER['DOCUMENT_ROOT']), DIRECTORY_SEPARATOR);
 76:     if (DIRECTORY_SEPARATOR != '/' && $docRoot != '') {
 77:         $docRoot = str_replace('\\', '/', $docRoot);
 78:     }
 79: } else {
 80:     $dir = basename($docRoot);
 81:     $ds = explode($dir, dirname($_SERVER['SCRIPT_NAME']), 2);
 82:     if (count($ds) > 1) {
 83:         $contextPrefix = $ds[0].$dir;
 84:         $appPath = $ds[1];
 85:         if (DIRECTORY_SEPARATOR != '/') {
 86:             $contextPrefix = str_replace('\\', '/', $contextPrefix);
 87:         }
 88:     }
 89:     if (!defined('APP_PATH')) {
 90:         define('APP_PATH', $docRoot.$appPath.'/');
 91:     }
 92:     if (!defined('BASE_PATH')) {
 93:         define('BASE_PATH', $contextPrefix.$appPath.'/');
 94:     }
 95: }
 96: 
 97: /*
 98:  * พาธของ Application เช่น D:/htdocs/kotchasan/
 99:  */
100: if (!defined('APP_PATH')) {
101:     $appPath = dirname($_SERVER['SCRIPT_NAME']);
102:     if (DIRECTORY_SEPARATOR != '/') {
103:         $appPath = str_replace('\\', '/', $appPath);
104:     }
105:     define('APP_PATH', rtrim($docRoot.$appPath, '/').'/');
106: }
107: /*
108:  *  http หรือ https
109:  */
110: if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
111:     $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'].'://';
112: } elseif ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) {
113:     $scheme = 'https://';
114: } else {
115:     $scheme = 'http://';
116: }
117: if (!defined('HTTPS')) {
118:     define('HTTPS', $scheme == 'https://');
119: }
120: /*
121:  * host name
122:  */
123: if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
124:     $host = trim(current(explode(',', $_SERVER['HTTP_X_FORWARDED_HOST'])));
125: } elseif (empty($_SERVER['HTTP_HOST'])) {
126:     $host = $_SERVER['SERVER_NAME'];
127: } else {
128:     $host = $_SERVER['HTTP_HOST'];
129: }
130: if (!defined('HOST')) {
131:     define('HOST', str_replace('www.', '', $host));
132: }
133: /*
134:  * ไดเร็คทอรี่ที่ติดตั้งเว็บไซต์ตั้งแต่ DOCUMENT_ROOT
135:  * เช่น kotchasan/
136:  */
137: if (!defined('BASE_PATH')) {
138:     if (empty($_SERVER['CONTEXT_DOCUMENT_ROOT'])) {
139:         define('BASE_PATH', str_replace($docRoot, '', APP_PATH));
140:     } else {
141:         $basePath = str_replace($_SERVER['CONTEXT_DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_NAME']));
142:         if (DIRECTORY_SEPARATOR != '/') {
143:             $basePath = str_replace('\\', '/', $basePath);
144:         }
145:         define('BASE_PATH', rtrim($basePath, '/').'/');
146:     }
147: }
148: /*
149:  * URL ของเว็บไซต์รวม path เช่น http://domain.tld/folder
150:  */
151: if (!defined('WEB_URL')) {
152:     define('WEB_URL', $scheme.$host.$contextPrefix.str_replace($docRoot, '', ROOT_PATH));
153: }
154: /*
155:  * กำหนดจำนวนครั้งในการตรวจสอบ token
156:  * ถ้ามีการตรวจสอบ token เกินกว่าที่กำหนดจะถูกลบออก
157:  * ป้องกันการ buteforce
158:  *
159:  * @var int
160:  */
161: if (!defined('TOKEN_LIMIT')) {
162:     define('TOKEN_LIMIT', 10);
163: }
164: /*
165:  * อายุของ token (วินาที)
166:  * ค่าเริ่มต้นคือ 60 นาที
167:  *
168:  * @var int
169:  */
170: if (!defined('TOKEN_AGE')) {
171:     define('TOKEN_AGE', 3600);
172: }
173: 
174: /**
175:  * ฟังก์ชั่นใช้สำหรับสร้างคลาส.
176:  *
177:  * @param string $className ชื่อคลาส
178:  * @param mixed  $param
179:  *
180:  * @return object
181:  */
182: function createClass($className, $param = null)
183: {
184:     return new $className($param);
185: }
186: 
187: /**
188:  * แสดงข้อมูลตัวแปรออกทาง Console ของบราวเวอร์ (debug).
189:  *
190:  * @param mixed $expression
191:  */
192: function debug($expression)
193: {
194:     if (is_array($expression) || is_object($expression)) {
195:         $content = json_encode((array) $expression);
196:     } else {
197:         $content = '"'.str_replace(array('/', '"'), array('\/', '\"'), $expression).'"';
198:     }
199:     echo '<script>console.log('.$content.')</script>';
200: }
201: /*
202:  * custom error handler
203:  * ถ้าอยู่ใน mode debug จะแสดง error ถ้าไม่จะเขียนลง log อย่างเดียว
204:  */
205: if (DEBUG != 2) {
206:     set_error_handler(function ($errno, $errstr, $errfile, $errline) {
207:         switch ($errno) {
208:             case E_WARNING:
209:                 $type = 'PHP warning';
210:                 break;
211:             case E_NOTICE:
212:                 $type = 'PHP notice';
213:                 break;
214:             case E_USER_ERROR:
215:                 $type = 'User error';
216:                 break;
217:             case E_USER_WARNING:
218:                 $type = 'User warning';
219:                 break;
220:             case E_USER_NOTICE:
221:                 $type = 'User notice';
222:                 break;
223:             case E_RECOVERABLE_ERROR:
224:                 $type = 'Recoverable error';
225:                 break;
226:             default:
227:                 $type = 'PHP Error';
228:         }
229:         \Kotchasan\Log\Logger::create()->error('<br>'.$type.' : <em>'.$errstr.'</em> in <b>'.$errfile.'</b> on line <b>'.$errline.'</b>');
230:     });
231:     set_exception_handler(function ($e) {
232:         $tract = $e->getTrace();
233:         if (empty($tract)) {
234:             $tract = array(
235:                 'file' => $e->getFile(),
236:                 'line' => $e->getLine(),
237:             );
238:         } else {
239:             $tract = next($tract);
240:         }
241:         \Kotchasan\Log\Logger::create()->error('<br>Exception : <em>'.$e->getMessage().'</em> in <b>'.$tract['file'].'</b> on line <b>'.$tract['line'].'</b>');
242:     });
243: }
244: 
245: /**
246:  * ตรวจสอบและคืนค่าชื่อไฟล์รวมพาธของคลาส.
247:  *
248:  * @param string $className
249:  *
250:  * @return string|null คืนค่าไฟล์รวมพาธของคลาส ถ้าไม่พบคืนค่า null
251:  */
252: function getClassPath($className)
253: {
254:     if (preg_match_all('/([\/\\])([a-zA-Z0-9]+)/', $className, $match)) {
255:         $className = implode(DIRECTORY_SEPARATOR, $match[1]).'.php';
256:         if (is_file(ROOT_PATH.$className)) {
257:             return ROOT_PATH.$className;
258:         } elseif (isset($match[1][2])) {
259:             if (isset($match[1][3])) {
260:                 $className = strtolower('modules'.DIRECTORY_SEPARATOR.$match[1][0].DIRECTORY_SEPARATOR.$match[1][3].'s'.DIRECTORY_SEPARATOR.$match[1][1].DIRECTORY_SEPARATOR.$match[1][2].'.php');
261:             } else {
262:                 $className = strtolower('modules'.DIRECTORY_SEPARATOR.$match[1][0].DIRECTORY_SEPARATOR.$match[1][2].'s'.DIRECTORY_SEPARATOR.$match[1][1].'.php');
263:             }
264:             if (is_file(APP_PATH.$className)) {
265:                 return APP_PATH.$className;
266:             } elseif (is_file(ROOT_PATH.$className)) {
267:                 return ROOT_PATH.$className;
268:             }
269:         }
270:     }
271: 
272:     return null;
273: }
274: /*
275:  * โหลดคลาสโดยอัตโนมัติตามชื่อของ Classname เมื่อมีการเรียกใช้งานคลาส
276:  * PSR-4
277:  *
278:  * @param string $className
279:  */
280: spl_autoload_register(function ($className) {
281:     $files = array(
282:         'Kotchasan\Cache\ApcCache' => 'Cache/ApcCache.php',
283:         'Kotchasan\Cache\Cache' => 'Cache/Cache.php',
284:         'Kotchasan\Cache\CacheItem' => 'Cache/CacheItem.php',
285:         'Kotchasan\Cache\Exception' => 'Cache/Exception.php',
286:         'Kotchasan\Cache\FileCache' => 'Cache/FileCache.php',
287:         'Kotchasan\Database\Db' => 'Database/Db.php',
288:         'Kotchasan\Database\DbCache' => 'Database/DbCache.php',
289:         'Kotchasan\Database\Driver' => 'Database/Driver.php',
290:         'Kotchasan\Database\Exception' => 'Database/Exception.php',
291:         'Kotchasan\Database\PdoMysqlDriver' => 'Database/PdoMysqlDriver.php',
292:         'Kotchasan\Database\Query' => 'Database/Query.php',
293:         'Kotchasan\Database\QueryBuilder' => 'Database/QueryBuilder.php',
294:         'Kotchasan\Database\Schema' => 'Database/Schema.php',
295:         'Kotchasan\Database\Sql' => 'Database/Sql.php',
296:         'Kotchasan\Http\Message' => 'Http/Message.php',
297:         'Kotchasan\Http\NotFound' => 'Http/NotFound.php',
298:         'Kotchasan\Http\Response' => 'Http/Response.php',
299:         'Kotchasan\Http\Stream' => 'Http/Stream.php',
300:         'Kotchasan\Http\UploadedFile' => 'Http/UploadedFile.php',
301:         'Kotchasan\Log\AbstractLogger' => 'Log/AbstractLogger.php',
302:         'Kotchasan\Log\Logger' => 'Log/Logger.php',
303:         'Kotchasan\Orm\Field' => 'Orm/Field.php',
304:         'Kotchasan\Orm\Recordset' => 'Orm/Recordset.php',
305:         'Kotchasan\PHPMailer\class' => 'PHPMailer/class.php',
306:         'Kotchasan\PHPMailer\class.smtp' => 'PHPMailer/class.smtp.php',
307:         'Psr\Cache\CacheItemInterface' => 'Psr/Cache/CacheItemInterface.php',
308:         'Psr\Cache\CacheItemPoolInterface' => 'Psr/Cache/CacheItemPoolInterface.php',
309:         'Psr\Http\Message\ResponseInterface' => 'Psr/Http/Message/ResponseInterface.php',
310:         'Psr\Http\Message\ServerRequestInterface' => 'Psr/Http/Message/ServerRequestInterface.php',
311:         'Psr\Http\Message\StreamInterface' => 'Psr/Http/Message/StreamInterface.php',
312:         'Psr\Http\Message\UploadedFileInterface' => 'Psr/Http/Message/UploadedFileInterface.php',
313:         'Psr\Log\AbstractLogger' => 'Psr/Log/AbstractLogger.php',
314:         'Psr\Log\LogLevel' => 'Psr/Log/LogLevel.php',
315:         'Psr\Log\LoggerAwareInterface' => 'Psr/Log/LoggerAwareInterface.php',
316:         'Psr\Log\LoggerInterface' => 'Psr/Log/LoggerInterface.php',
317:         'Psr\Log\LoggerTrait' => 'Psr/Log/LoggerTrait.php',
318:         'Psr\Log\NullLogger' => 'Psr/Log/NullLogger.php',
319:         'Kotchasan\Accordion' => 'Accordion.php',
320:         'Kotchasan\ArrayTool' => 'ArrayTool.php',
321:         'Kotchasan\CKEditor' => 'CKEditor.php',
322:         'Kotchasan\Collection' => 'Collection.php',
323:         'Kotchasan\Country' => 'Country.php',
324:         'Kotchasan\Csv' => 'Csv.php',
325:         'Kotchasan\Curl' => 'Curl.php',
326:         'Kotchasan\Currency' => 'Currency.php',
327:         'Kotchasan\DOMNode' => 'DOMNode.php',
328:         'Kotchasan\DOMParser' => 'DOMParser.php',
329:         'Kotchasan\DataTable' => 'DataTable.php',
330:         'Kotchasan\Database' => 'Database.php',
331:         'Kotchasan\Date' => 'Date.php',
332:         'Kotchasan\Email' => 'Email.php',
333:         'Kotchasan\File' => 'File.php',
334:         'Kotchasan\Files' => 'Files.php',
335:         'Kotchasan\Form' => 'Form.php',
336:         'Kotchasan\Grid' => 'Grid.php',
337:         'Kotchasan\Html' => 'Html.php',
338:         'Kotchasan\HtmlTable' => 'HtmlTable.php',
339:         'Kotchasan\Htmldoc' => 'Htmldoc.php',
340:         'Kotchasan\Image' => 'Image.php',
341:         'Kotchasan\InputItem' => 'InputItem.php',
342:         'Kotchasan\Inputs' => 'Inputs.php',
343:         'Kotchasan\Language' => 'Language.php',
344:         'Kotchasan\ListItem' => 'ListItem.php',
345:         'Kotchasan\Login' => 'Login.php',
346:         'Kotchasan\Menu' => 'Menu.php',
347:         'Kotchasan\Mime' => 'Mime.php',
348:         'Kotchasan\Model' => 'Model.php',
349:         'Kotchasan\Number' => 'Number.php',
350:         'Kotchasan\Password' => 'Password.php',
351:         'Kotchasan\Pdf' => 'Pdf.php',
352:         'Kotchasan\Province' => 'Province.php',
353:         'Kotchasan\Singleton' => 'Singleton.php',
354:         'Kotchasan\Tab' => 'Tab.php',
355:         'Kotchasan\Template' => 'Template.php',
356:         'Kotchasan\Text' => 'Text.php',
357:         'Kotchasan\Validator' => 'Validator.php',
358:         'Kotchasan\View' => 'View.php',
359:         'Kotchasan\load' => 'load.php',
360:         'Kotchasan\ObjectTool' => 'ObjectTool.php',
361:         'Kotchasan\InputItemException' => 'InputItemException.php',
362:     );
363:     if (isset($files[$className])) {
364:         $file = VENDOR_DIR.$files[$className];
365:     } else {
366:         $file = getClassPath($className);
367:     }
368:     if ($file !== null) {
369:         require $file;
370:     }
371: });
372: 
373: /**
374:  * โหลดคลาสเริ่มต้น
375:  */
376: require VENDOR_DIR.'KBase.php';
377: require VENDOR_DIR.'Config.php';
378: require VENDOR_DIR.'Psr/Http/Message/MessageInterface.php';
379: require VENDOR_DIR.'Psr/Http/Message/RequestInterface.php';
380: require VENDOR_DIR.'Psr/Http/Message/UriInterface.php';
381: require VENDOR_DIR.'Http/AbstractMessage.php';
382: require VENDOR_DIR.'Http/AbstractRequest.php';
383: require VENDOR_DIR.'Http/Request.php';
384: require VENDOR_DIR.'Http/Uri.php';
385: require VENDOR_DIR.'Router.php';
386: require VENDOR_DIR.'Kotchasan.php';
387: require VENDOR_DIR.'Controller.php';
388: 
Kotchasan API documentation generated by ApiGen