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/Http/AbstractRequest.php
  4:  *
  5:  * @copyright 2016 Goragod.com
  6:  * @license http://www.kotchasan.com/license/
  7:  *
  8:  * @see http://www.kotchasan.com/
  9:  */
 10: 
 11: namespace Kotchasan\Http;
 12: 
 13: /**
 14:  * Class สำหรับจัดการ URL.
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class AbstractRequest extends AbstractMessage implements \Psr\Http\Message\RequestInterface
 21: {
 22:     /**
 23:      * @var string
 24:      */
 25:     protected $method = null;
 26:     /**
 27:      * @var string
 28:      */
 29:     protected $requestTarget;
 30:     /**
 31:      * @var \Kotchasan\Http\Uri
 32:      */
 33:     protected $uri;
 34: 
 35:     /**
 36:      * สร้างคลาสจากลิงค์ และ รวมค่าที่มาจาก $_GET ด้วย
 37:      *
 38:      * @param string $uri     ค่าเริ่มต้นคือ index.php
 39:      * @param array  $exclude รายการแอเรย์ของ $_GET ที่ไม่ต้องการให้รวมอยู่ใน URL
 40:      *
 41:      * @return Uri
 42:      */
 43:     public static function createUriWithGet($uri = 'index.php', $exclude = array())
 44:     {
 45:         $query = array();
 46:         self::map($query, $_GET, $exclude);
 47:         if (!empty($query)) {
 48:             $uri .= (strpos($uri, '?') === false ? '?' : '&').http_build_query($query);
 49:         }
 50:         return Uri::createFromUri($uri);
 51:     }
 52: 
 53:     /**
 54:      * สร้างคลาสจากลิงค์ และ รวมค่าที่มาจาก $_GET และ $_POST ด้วย
 55:      *
 56:      * @param string $uri     ค่าเริ่มต้นคือ index.php
 57:      * @param array  $exclude รายการแอเรย์ของ $_GET และ $_POST ที่ไม่ต้องการให้รวมอยู่ใน URL
 58:      *
 59:      * @return Uri
 60:      */
 61:     public function createUriWithGlobals($uri = 'index.php', $exclude = array())
 62:     {
 63:         $query_str = array();
 64:         self::map($query_str, $_GET, $exclude);
 65:         self::map($query_str, $_POST, $exclude);
 66:         if (!empty($query_str)) {
 67:             $uri .= (strpos($uri, '?') === false ? '?' : '&').http_build_query($query_str);
 68:         }
 69:         return Uri::createFromUri($uri);
 70:     }
 71: 
 72:     /**
 73:      * สร้างคลาสจากลิงค์ และ รวมค่าที่มาจาก $_POST ด้วย
 74:      *
 75:      * @param string $uri     ค่าเริ่มต้นคือ index.php
 76:      * @param array  $exclude รายการแอเรย์ของ $_POST ที่ไม่ต้องการให้รวมอยู่ใน URL
 77:      *
 78:      * @return Uri
 79:      */
 80:     public static function createUriWithPost($uri = 'index.php', $exclude = array())
 81:     {
 82:         $query = array();
 83:         self::map($query, $_POST, $exclude);
 84:         if (!empty($query)) {
 85:             $uri .= (strpos($uri, '?') === false ? '?' : '&').http_build_query($query);
 86:         }
 87:         return Uri::createFromUri($uri);
 88:     }
 89: 
 90:     /**
 91:      * อ่านค่า HTTP method
 92:      * returns the request method.
 93:      *
 94:      * @return string
 95:      */
 96:     public function getMethod()
 97:     {
 98:         if ($this->method === null) {
 99:             $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
100:             if ($this->method === 'POST' && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
101:                 $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
102:             }
103:         }
104:         return $this->method;
105:     }
106: 
107:     /**
108:      * อ่านค่า request target
109:      *
110:      * @return string
111:      */
112:     public function getRequestTarget()
113:     {
114:         if ($this->requestTarget === null) {
115:             $this->requestTarget = $this->uri;
116:         }
117:         return $this->requestTarget;
118:     }
119: 
120:     /**
121:      * อ่าน Uri
122:      *
123:      * @return \Kotchasan\Http\Uri
124:      */
125:     public function getUri()
126:     {
127:         if ($this->uri === null) {
128:             $this->uri = Uri::createFromGlobals();
129:         }
130:         return $this->uri;
131:     }
132: 
133:     /**
134:      * รวมแอเรย์ $_GET $_POST เป็นข้อมูลเดียวกัน
135:      *
136:      * @param array $result  ตัวแปรเก็บผลลัพท์ สำหรับนำไปใช้งานต่อ
137:      * @param array $array   ตัวแปรที่ต้องการรวม เช่น $_GET $_POST
138:      * @param array $exclude รายการคีย์ของแอเรย์ ที่ไม่ต้องการให้รวมอยู่ในผลลัพท์
139:      */
140:     public static function map(&$result, $array, $exclude = array())
141:     {
142:         foreach ($array as $key => $value) {
143:             if (!in_array($key, $exclude)) {
144:                 if (is_array($value)) {
145:                     foreach ($value as $k => $v) {
146:                         $result[$key.'['.$k.']'] = $v;
147:                     }
148:                 } else {
149:                     $result[$key] = $value;
150:                 }
151:             }
152:         }
153:     }
154: 
155:     /**
156:      * กำหนดค่า HTTP method
157:      *
158:      * @param string $method
159:      *
160:      * @return \static
161:      */
162:     public function withMethod($method)
163:     {
164:         $clone = clone $this;
165:         $clone->method = $method;
166:         return $clone;
167:     }
168: 
169:     /**
170:      * กำหนดค่า request target
171:      *
172:      * @param mixed $requestTarget
173:      *
174:      * @return \static
175:      */
176:     public function withRequestTarget($requestTarget)
177:     {
178:         $clone = clone $this;
179:         $clone->requestTarget = $requestTarget;
180:         return $clone;
181:     }
182: 
183:     /**
184:      * กำหนดค่า Uri
185:      *
186:      * @param \Kotchasan\Http\UriInterface $uri
187:      * @param bool                         $preserveHost
188:      *
189:      * @return \static
190:      */
191:     public function withUri(\Psr\Http\Message\UriInterface $uri, $preserveHost = false)
192:     {
193:         $clone = clone $this;
194:         $clone->uri = $uri;
195:         if (!$preserveHost) {
196:             if ($uri->getHost() !== '') {
197:                 $clone->headers['Host'] = $uri->getHost();
198:             }
199:         } else {
200:             if ($this->uri->getHost() !== '' && (!$this->hasHeader('Host') || $this->getHeader('Host') === null)) {
201:                 $clone->headers['Host'] = $uri->getHost();
202:             }
203:         }
204:         return $clone;
205:     }
206: }
207: 
Kotchasan API documentation generated by ApiGen