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/Collection.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:  * Collection Class.
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class Collection implements \Countable, \IteratorAggregate, \ArrayAccess
 21: {
 22:     /**
 23:      * ตัวแปรเก็บสมาชิกของคลาส.
 24:      *
 25:      * @var array
 26:      */
 27:     private $datas = array();
 28: 
 29:     /**
 30:      * Create new collection.
 31:      *
 32:      * @param array $items สมาชิกเริ่มต้นของ Collection
 33:      */
 34:     public function __construct(array $items = array())
 35:     {
 36:         foreach ($items as $key => $value) {
 37:             $this->set($key, $value);
 38:         }
 39:     }
 40: 
 41:     /**
 42:      * ลบข้อมูลทั้งหมด.
 43:      */
 44:     public function clear()
 45:     {
 46:         $this->datas = array();
 47:     }
 48: 
 49:     /**
 50:      * คืนค่าจำนวนข้อมูลทั้งหมด.
 51:      *
 52:      * @return int
 53:      */
 54:     public function count()
 55:     {
 56:         return count($this->datas);
 57:     }
 58: 
 59:     /**
 60:      * อ่านข้อมูลที่ $key ถ้าไม่พบคืนค่า $default.
 61:      *
 62:      * @param string $key
 63:      * @param mixed  $default
 64:      *
 65:      * @return mixed
 66:      */
 67:     public function get($key, $default = null)
 68:     {
 69:         return $this->has($key) ? $this->datas[$key] : $default;
 70:     }
 71: 
 72:     /*   * **********************
 73:      * IteratorAggregate interface
 74:      * ************************* */
 75: 
 76:     /**
 77:      * Retrieve an external iterator.
 78:      *
 79:      * @return \ArrayIterator
 80:      */
 81:     public function getIterator()
 82:     {
 83:         return new \ArrayIterator($this->datas);
 84:     }
 85: 
 86:     /**
 87:      * ตรวจสอบว่ามีรายการ $key หรือไม่.
 88:      *
 89:      * @param string $key
 90:      *
 91:      * @return bool
 92:      */
 93:     public function has($key)
 94:     {
 95:         return array_key_exists($key, $this->datas);
 96:     }
 97: 
 98:     /**
 99:      * อ่านรายชื่อ keys
100:      * คืนค่าแอเรย์ของรายการ key ทั้งหมด.
101:      *
102:      * @return array
103:      */
104:     public function keys()
105:     {
106:         return array_keys($this->datas);
107:     }
108: 
109:     /*   * *****************
110:      * ArrayAccess interface
111:      * ********************* */
112: 
113:     /**
114:      * ตรวจสอบว่ามีรายการ $key หรือไม่.
115:      *
116:      * @param string $key
117:      *
118:      * @return bool
119:      */
120:     public function offsetExists($key)
121:     {
122:         return $this->has($key);
123:     }
124: 
125:     /**
126:      * อ่านข้อมูลที่ $key.
127:      *
128:      * @param string $key
129:      *
130:      * @return mixed
131:      */
132:     public function offsetGet($key)
133:     {
134:         return $this->get($key);
135:     }
136: 
137:     /**
138:      * กำหนดค่า $value ของ $key.
139:      *
140:      * @param string $key
141:      * @param mixed  $value
142:      */
143:     public function offsetSet($key, $value)
144:     {
145:         $this->set($key, $value);
146:     }
147: 
148:     /**
149:      * ลบรายการที่ $key.
150:      *
151:      * @param string $key
152:      */
153:     public function offsetUnset($key)
154:     {
155:         $this->remove($key);
156:     }
157: 
158:     /**
159:      * ลบรายการที่ $key.
160:      *
161:      * @param string $key
162:      */
163:     public function remove($key)
164:     {
165:         unset($this->datas[$key]);
166:     }
167: 
168:     /**
169:      * เพิ่มรายการใหม่ แทนที่รายการเดิม
170:      *
171:      * @param array $items array(array($key => $value), array($key => $value), ...)
172:      */
173:     public function replace(array $items)
174:     {
175:         foreach ($items as $key => $value) {
176:             $this->set($key, $value);
177:         }
178:     }
179: 
180:     /*   * ****************
181:      * Collection interface
182:      * ******************* */
183: 
184:     /**
185:      * กำหนดค่า $value ของ $key.
186:      *
187:      * @param string $key
188:      * @param mixed  $value
189:      */
190:     public function set($key, $value)
191:     {
192:         $this->datas[$key] = $value;
193:     }
194: 
195:     /**
196:      * คืนค่าข้อมูลทั้งหมดเป็น.
197:      *
198:      * @return array
199:      */
200:     public function toArray()
201:     {
202:         return $this->datas;
203:     }
204: }
205: 
Kotchasan API documentation generated by ApiGen