Packages

  • dibi
    • drivers
    • nette
    • reflection
  • None
  • PHP

Classes

  • dibi
  • DibiConnection
  • DibiDataSource
  • DibiDateTime
  • DibiEvent
  • DibiFileLogger
  • DibiFirePhpLogger
  • DibiFluent
  • DibiObject
  • DibiResult
  • DibiResultIterator
  • DibiRow
  • DibiTranslator

Interfaces

  • IDataSource
  • IDibiDriver
  • IDibiReflector
  • IDibiResultDriver

Exceptions

  • DibiDriverException
  • DibiException
  • DibiNotImplementedException
  • DibiNotSupportedException
  • DibiPcreException
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the "dibi" - smart database abstraction layer.
  5:  *
  6:  * Copyright (c) 2005 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: 
 13: 
 14: /**
 15:  * Result set single row.
 16:  *
 17:  * @author     David Grudl
 18:  * @package    dibi
 19:  */
 20: class DibiRow implements ArrayAccess, IteratorAggregate, Countable
 21: {
 22: 
 23:     public function __construct($arr)
 24:     {
 25:         foreach ($arr as $k => $v) $this->$k = $v;
 26:     }
 27: 
 28: 
 29: 
 30:     public function toArray()
 31:     {
 32:         return (array) $this;
 33:     }
 34: 
 35: 
 36: 
 37:     /**
 38:      * Converts value to DateTime object.
 39:      * @param  string key
 40:      * @param  string format
 41:      * @return DateTime
 42:      */
 43:     public function asDateTime($key, $format = NULL)
 44:     {
 45:         $time = $this[$key];
 46:         if (!$time instanceof DibiDateTime) {
 47:             if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
 48:                 return NULL;
 49:             }
 50:             $time = new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
 51:         }
 52:         return $format === NULL ? $time : $time->format($format);
 53:     }
 54: 
 55: 
 56: 
 57:     /**
 58:      * Converts value to UNIX timestamp.
 59:      * @param  string key
 60:      * @return int
 61:      */
 62:     public function asTimestamp($key)
 63:     {
 64:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
 65:         $time = $this[$key];
 66:         return (int) $time === 0 // '', NULL, FALSE, '0000-00-00', ...
 67:             ? NULL
 68:             : (is_numeric($time) ? (int) $time : strtotime($time));
 69:     }
 70: 
 71: 
 72: 
 73:     /**
 74:      * Converts value to boolean.
 75:      * @param  string key
 76:      * @return mixed
 77:      */
 78:     public function asBool($key)
 79:     {
 80:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
 81:         return $this[$key];
 82:     }
 83: 
 84: 
 85: 
 86:     /** @deprecated */
 87:     public function asDate($key, $format = NULL)
 88:     {
 89:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
 90:         if ($format === NULL) {
 91:             return $this->asTimestamp($key);
 92:         } else {
 93:             return $this->asDateTime($key, $format === TRUE ? NULL : $format);
 94:         }
 95:     }
 96: 
 97: 
 98: 
 99:     /********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
100: 
101: 
102: 
103:     final public function count()
104:     {
105:         return count((array) $this);
106:     }
107: 
108: 
109: 
110:     final public function getIterator()
111:     {
112:         return new ArrayIterator($this);
113:     }
114: 
115: 
116: 
117:     final public function offsetSet($nm, $val)
118:     {
119:         $this->$nm = $val;
120:     }
121: 
122: 
123: 
124:     final public function offsetGet($nm)
125:     {
126:         return $this->$nm;
127:     }
128: 
129: 
130: 
131:     final public function offsetExists($nm)
132:     {
133:         return isset($this->$nm);
134:     }
135: 
136: 
137: 
138:     final public function offsetUnset($nm)
139:     {
140:         unset($this->$nm);
141:     }
142: 
143: }
144: 
dibi API documentation API documentation generated by ApiGen 2.3.0