[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Copyright 2012-2014 Horde LLC (http://www.horde.org/) 4 * 5 * See the enclosed file COPYING for license information (LGPL). If you 6 * did not receive this file, see http://www.horde.org/licenses/lgpl21. 7 * 8 * @category Horde 9 * @copyright 2012-2014 Horde LLC 10 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 11 * @package Imap_Client 12 */ 13 14 /** 15 * Fetch results object for use with Horde_Imap_Client_Base#fetch(). 16 * 17 * @author Michael Slusarz <slusarz@horde.org> 18 * @category Horde 19 * @copyright 2012-2014 Horde LLC 20 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 21 * @package Imap_Client 22 * 23 * @property-read integer $key_type The key type (sequence or UID). 24 */ 25 class Horde_Imap_Client_Fetch_Results implements ArrayAccess, Countable, IteratorAggregate 26 { 27 /** 28 * Key type constants. 29 */ 30 const SEQUENCE = 1; 31 const UID = 2; 32 33 /** 34 * Internal data array. 35 * 36 * @var array 37 */ 38 protected $_data = array(); 39 40 /** 41 * Key type. 42 * 43 * @var integer 44 */ 45 protected $_keyType; 46 47 /** 48 * Class to use when creating a new fetch object. 49 * 50 * @var string 51 */ 52 protected $_obClass; 53 54 /** 55 * Constructor. 56 * 57 * @param string $ob_class Class to use when creating a new fetch 58 * object. 59 * @param integer $key_type Key type. 60 */ 61 public function __construct($ob_class = 'Horde_Imap_Client_Data_Fetch', 62 $key_type = self::UID) 63 { 64 $this->_obClass = $ob_class; 65 $this->_keyType = $key_type; 66 } 67 68 /** 69 */ 70 public function __get($name) 71 { 72 switch ($name) { 73 case 'key_type': 74 return $this->_keyType; 75 } 76 } 77 78 /** 79 * Return a fetch object, creating and storing an empty object in the 80 * results set if it doesn't currently exist. 81 * 82 * @param string $key The key to retrieve. 83 * 84 * @return Horde_Imap_Client_Data_Fetch The fetch object. 85 */ 86 public function get($key) 87 { 88 if (!isset($this->_data[$key])) { 89 $this->_data[$key] = new $this->_obClass(); 90 } 91 92 return $this->_data[$key]; 93 } 94 95 /** 96 * Return the list of IDs. 97 * 98 * @return array ID list. 99 */ 100 public function ids() 101 { 102 ksort($this->_data); 103 return array_keys($this->_data); 104 } 105 106 /** 107 * Return the first fetch object in the results, if there is only one 108 * object. 109 * 110 * @return null|Horde_Imap_Client_Data_Fetch The fetch object if there is 111 * only one object, or null. 112 */ 113 public function first() 114 { 115 return (count($this->_data) === 1) 116 ? reset($this->_data) 117 : null; 118 } 119 120 /** 121 * Clears all fetch results. 122 * 123 * @since 2.6.0 124 */ 125 public function clear() 126 { 127 $this->_data = array(); 128 } 129 130 /* ArrayAccess methods. */ 131 132 /** 133 */ 134 public function offsetExists($offset) 135 { 136 return isset($this->_data[$offset]); 137 } 138 139 /** 140 */ 141 public function offsetGet($offset) 142 { 143 return isset($this->_data[$offset]) 144 ? $this->_data[$offset] 145 : null; 146 } 147 148 /** 149 */ 150 public function offsetSet($offset, $value) 151 { 152 $this->_data[$offset] = $value; 153 } 154 155 /** 156 */ 157 public function offsetUnset($offset) 158 { 159 unset($this->_data[$offset]); 160 } 161 162 /* Countable methods. */ 163 164 /** 165 */ 166 public function count() 167 { 168 return count($this->_data); 169 } 170 171 /* IteratorAggregate methods. */ 172 173 /** 174 */ 175 public function getIterator() 176 { 177 ksort($this->_data); 178 return new ArrayIterator($this->_data); 179 } 180 181 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |