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/Inputs.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;
 12: 
 13: /**
 14:  * รายการ input รูปแบบ Array
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class Inputs implements \Iterator
 21: {
 22:     /**
 23:      * ตัวแปรเก็บ properties ของคลาส
 24:      *
 25:      * @var array
 26:      */
 27:     private $datas = array();
 28: 
 29:     /**
 30:      * magic method คืนค่าข้อมูลสำหรับ input ชนิด array
 31:      *
 32:      * @param string $name
 33:      * @param array  $arguments
 34:      *
 35:      * @throws \InvalidArgumentException ถ้าไม่มี method ที่ต้องการ
 36:      *
 37:      * @return array
 38:      */
 39:     public function __call($name, $arguments)
 40:     {
 41:         if (method_exists('Kotchasan\InputItem', $name)) {
 42:             $result = array();
 43:             foreach ($this->datas as $key => $item) {
 44:                 $result[$key] = $this->collectInputs($item, $name, $arguments);
 45:             }
 46:             return $result;
 47:         } else {
 48:             throw new \InvalidArgumentException('Method '.$name.' not found');
 49:         }
 50:     }
 51: 
 52:     /**
 53:      * Class Constructer
 54:      *
 55:      * @param array       $items รายการ input
 56:      * @param string|null $type  ประเภท Input เช่น GET POST SESSION COOKIE หรือ null ถ้าไม่ได้มาจากรายการข้างต้น
 57:      */
 58:     public function __construct(array $items = array(), $type = null)
 59:     {
 60:         foreach ($items as $key => $value) {
 61:             if (is_array($value)) {
 62:                 foreach ($value as $k => $v) {
 63:                     $this->datas[$k][$key] = InputItem::create($v, $type);
 64:                 }
 65:             } else {
 66:                 $this->datas[$key] = InputItem::create($value, $type);
 67:             }
 68:         }
 69:     }
 70: 
 71:     /**
 72:      * เตรียมผลลัพท์สำหรับ input แบบ array
 73:      *
 74:      * @param Object $item
 75:      * @param string $name
 76:      * @param array  $arguments
 77:      *
 78:      * @return array|object
 79:      */
 80:     private function collectInputs($item, $name, $arguments)
 81:     {
 82:         if (is_array($item)) {
 83:             $array = array();
 84:             foreach ($item as $k => $v) {
 85:                 $array[$k] = $this->collectInputs($v, $name, $arguments);
 86:             }
 87:             return $array;
 88:         }
 89:         if (isset($arguments[1])) {
 90:             return $item->$name($arguments[0], $arguments[1]);
 91:         } elseif (isset($arguments[0])) {
 92:             return $item->$name($arguments[0]);
 93:         } else {
 94:             return $item->$name($arguments);
 95:         }
 96:     }
 97: 
 98:     /**
 99:      * คืนค่า InputItem รายการปัจจุบัน
100:      *
101:      * @return \Kotchasan\InputItem
102:      */
103:     public function current()
104:     {
105:         $var = current($this->datas);
106: 
107:         return $var;
108:     }
109: 
110:     /**
111:      * อ่าน Input ที่ต้องการ
112:      *
113:      * @param string|int $key รายการที่ต้องการ
114:      *
115:      * @return \Kotchasan\InputItem
116:      */
117:     public function get($key)
118:     {
119:         return $this->datas[$key];
120:     }
121: 
122:     /**
123:      * คืนค่าคีย์หรือลำดับของ InputItem ในลิสต์รายการ
124:      *
125:      * @return string
126:      */
127:     public function key()
128:     {
129:         $var = key($this->datas);
130:         return $var;
131:     }
132: 
133:     /**
134:      * คืนค่า InputItem รายการถัดไป
135:      *
136:      * @return \Kotchasan\InputItem
137:      */
138:     public function next()
139:     {
140:         $var = next($this->datas);
141:         return $var;
142:     }
143: 
144:     /**
145:      * inherited from Iterator
146:      */
147:     public function rewind()
148:     {
149:         reset($this->datas);
150:     }
151: 
152:     /**
153:      * @return bool
154:      */
155:     public function valid()
156:     {
157:         $key = key($this->datas);
158:         return $key !== null && $key !== false;
159:     }
160: }
161: 
Kotchasan API documentation generated by ApiGen