Zend Framework - Zend_Mail | ||||||||||||||||||||
|
||||||||||||||||||||
1 : <?php 2 : /** 3 : * Zend Framework 4 : * 5 : * LICENSE 6 : * 7 : * This source file is subject to version 1.0 of the Zend Framework 8 : * license, that is bundled with this package in the file LICENSE, and 9 : * is available through the world-wide-web at the following URL: 10 : * http://www.zend.com/license/framework/1_0.txt. If you did not receive 11 : * a copy of the Zend Framework license and are unable to obtain it 12 : * through the world-wide-web, please send a note to license@zend.com 13 : * so we can mail you a copy immediately. 14 : * 15 : * @package Zend_Mail 16 : * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) 17 : * @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0 18 : */ 19 : 20 : 21 : /** 22 : * Zend_Mail_Storage_Exception 23 : */ 24 : require_once 'Zend/Mail/Storage/Exception.php'; 25 : 26 : /** 27 : * @package Zend_Mail 28 : * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) 29 : * @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0 30 : */ 31 : class Zend_Mail_Storage_Folder implements RecursiveIterator 32 : { 33 : /** 34 : * subfolders of folder array(localName => Zend_Mail_Storage_Folder folder) 35 : */ 36 : private $_folders; 37 : 38 : /** 39 : * local name (name of folder in parent folder) 40 : */ 41 : private $_localName; 42 : 43 : /** 44 : * global name (absolute name of folder) 45 : */ 46 : private $_globalName; 47 : 48 : /** 49 : * folder is selectable if folder is able to hold messages, else it's just a parent folder 50 : */ 51 : private $_selectable = true; 52 : 53 : /** 54 : * create a new mail folder instance 55 : * 56 : * @param string $localName name of folder in current subdirectory 57 : * @param string $globalName absolute name of folder 58 : * @param bool $selectable if true folder holds messages, if false it's just a parent for subfolders 59 : * @param array $folders init with given instances of Zend_Mail_Storage_Folder as subfolders 60 : */ 61 : public function __construct($localName, $globalName = '', $selectable = true, array $folders = array()) 62 : { 63 29 : $this->_localName = $localName; 64 29 : $this->_globalName = $globalName ? $globalName : $localName; 65 29 : $this->_selectable = $selectable; 66 29 : $this->_folders = $folders; 67 29 : } 68 : 69 : /** 70 : * implements RecursiveIterator::hasChildren() 71 : * 72 : * @return bool current element has children 73 : */ 74 : public function hasChildren() 75 : { 76 8 : $current = $this->current(); 77 8 : return $current && $current instanceof Zend_Mail_Storage_Folder && !$current->isLeaf(); 78 : } 79 : 80 : /** 81 : * implements RecursiveIterator::getChildren() 82 : * 83 : * @return Zend_Mail_Storage_Folder same as self::current() 84 : */ 85 : public function getChildren() 86 : { 87 8 : return $this->current(); 88 : } 89 : 90 : /** 91 : * implements Iterator::valid() 92 : * 93 : * @return bool check if there's a current element 94 : */ 95 : public function valid() 96 : { 97 8 : return key($this->_folders) !== null; 98 : } 99 : 100 : /** 101 : * implements Iterator::next() 102 : */ 103 : public function next() 104 : { 105 8 : next($this->_folders); 106 8 : } 107 : 108 : /** 109 : * implements Iterator::key() 110 : * 111 : * @return string key/local name of current element 112 : */ 113 : public function key() 114 : { 115 11 : return key($this->_folders); 116 : } 117 : 118 : /** 119 : * implements Iterator::current() 120 : * 121 : * @return Zend_Mail_Storage_Folder current folder 122 : */ 123 : public function current() 124 : { 125 8 : return current($this->_folders); 126 : } 127 : 128 : /** 129 : * implements Iterator::rewind() 130 : */ 131 : public function rewind() 132 : { 133 8 : reset($this->_folders); 134 8 : } 135 : 136 : /** 137 : * get subfolder named $name 138 : * 139 : * @param string $name wanted subfolder 140 : * @return Zend_Mail_Storage_Folder folder named $folder 141 : * @throws Zend_Mail_Storage_Exception 142 : */ 143 : public function __get($name) 144 : { 145 11 : if(!isset($this->_folders[$name])) { 146 4 : throw new Zend_Mail_Storage_Exception("no subfolder named $name"); 147 : } 148 : 149 7 : return $this->_folders[$name]; 150 : } 151 : 152 : /** 153 : * add or replace subfolder named $name 154 : * 155 : * @param string $name local name of subfolder 156 : * @param Zend_Mail_Storage_Folder instance for new subfolder 157 : */ 158 : public function __set($name, Zend_Mail_Storage_Folder $folder) 159 : { 160 29 : $this->_folders[$name] = $folder; 161 29 : } 162 : 163 : /** 164 : * magic method for easy output of global name 165 : * 166 : * @return string global name of folder 167 : */ 168 : public function __toString() 169 : { 170 8 : return $this->getGlobalName(); 171 : } 172 : 173 : /** 174 : * get local name 175 : * 176 : * @return string local name 177 : */ 178 : public function getLocalName() 179 : { 180 3 : return $this->_localName; 181 : } 182 : 183 : /** 184 : * get global name 185 : * 186 : * @return string global name 187 : */ 188 : public function getGlobalName() 189 : { 190 9 : return $this->_globalName; 191 : } 192 : 193 : /** 194 : * is this folder selectable? 195 : * 196 : * @return bool selectable 197 : */ 198 : public function isSelectable() 199 : { 200 1 : return $this->_selectable; 201 : } 202 : 203 : /** 204 : * check if folder has no subfolder 205 : * 206 : * @return bool true if no subfolders 207 : */ 208 : public function isLeaf() 209 : { 210 8 : return empty($this->_folders); 211 : } 212 : } 213 : |
Generated by: PHPUnit 3.0.0 and Xdebug 2.0.0RC2-dev. |