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/ObjectTool.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:  * Object tools
15:  *
16:  * @author Goragod Wiriya <admin@goragod.com>
17:  *
18:  * @since 1.0
19:  */
20: class ObjectTool
21: {
22:     /**
23:      * คืนค่ารายการที่มีคอลัมน์ตามที่กำหนด.
24:      *
25:      * @assert (array((object)array('id' => 1, 'name' => 'one'), (object)array('id' => 2, 'name' => 'two'), (object)array('id' => 3, 'name' => 'three')), 'name') [==] (object)array(0 => 'one', 1 => 'two', 2 => 'three')
26:      * @assert (array((object)array('id' => 1, 'name' => 'one'), (object)array('id' => 2, 'name' => 'two'), (object)array('id' => 3, 'name' => 'three')), 'name', 'id') [==] (object)array(1 => 'one', 2 => 'two', 3 => 'three')
27:      *
28:      * @param array  $array
29:      * @param string $column_key ชื่อคอลัมน์ที่ต้องการ
30:      * @param mixed  $index_key  null คืนค่า index ของ $array, string คืนค่า index จากคอลัมน์ที่กำหนด
31:      *
32:      * @return array
33:      */
34:     public static function columns($array, $column_key, $index_key = null)
35:     {
36:         $result = array();
37:         if ($index_key == null) {
38:             foreach ($array as $i => $item) {
39:                 if (isset($item->$column_key)) {
40:                     $result[$i] = $item->$column_key;
41:                 }
42:             }
43:         } else {
44:             foreach ($array as $i => $item) {
45:                 if (isset($item->$column_key) && isset($item->$index_key)) {
46:                     $result[$item->$index_key] = $item->$column_key;
47:                 }
48:             }
49:         }
50: 
51:         return (object) $result;
52:     }
53: 
54:     /**
55:      * ฟังก์ชั่นรวม object แทนที่คีย์เดิม
56:      *
57:      * @assert ((object)array('one' => 1), array('two' => 2)) [==] (object)array('one' => 1, 'two' => 2)
58:      * @assert ((object)array('one' => 1), (object)array('two' => 2)) [==] (object)array('one' => 1, 'two' => 2)
59:      *
60:      * @param object       $a
61:      * @param array|object $b
62:      *
63:      * @return object
64:      */
65:     public static function replace($a, $b)
66:     {
67:         foreach ($b as $key => $value) {
68:             $a->$key = $value;
69:         }
70: 
71:         return $a;
72:     }
73: 
74:     /**
75:      * ค้นหา object จาก property
76:      * คืนค่าทุกรายการที่พบ รักษา index ตาม array ของ object ต้นฉบับ และ คืนค่าแอเรย์ว่างถ้าไม่พบ.
77:      *
78:      * @assert (array((object)array('id' => 1, 'name' => 'one'), (object)array('id' => 2, 'name' => 'two'), (object)array('id' => 3, 'name' => 'one')), 'name', 'one') [==] array(0 => (object)array('id' => 1, 'name' => 'one'), 2 => (object)array('id' => 3, 'name' => 'one'))
79:      * @assert (array((object)array('id' => 1, 'name' => 'one'), (object)array('id' => 2, 'name' => 'two'), (object)array('id' => 3, 'name' => 'one')), 'id', 'one') [==] array()
80:      *
81:      * @param array $input  ข้อมูลแอเรย์ ของ object
82:      * @param mixed $key    property ที่ต้องการค้นหา
83:      * @param mixed $search ข้อความค้นหา
84:      *
85:      * @return array
86:      */
87:     public static function search($input, $key, $search)
88:     {
89:         $result = array();
90:         foreach ($input as $i => $values) {
91:             if (isset($values->$key) && $values->$key == $search) {
92:                 $result[$i] = $values;
93:             }
94:         }
95: 
96:         return $result;
97:     }
98: }
99: 
Kotchasan API documentation generated by ApiGen