[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Abstract class describing Inbound Message Handlers. 19 * 20 * @package core_message 21 * @copyright 2014 Andrew Nicols 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core\message\inbound; 25 26 /** 27 * Abstract class describing Inbound Message Handlers. 28 * 29 * @copyright 2014 Andrew NIcols 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 * 32 * @property-read int $id The ID of the handler in the database 33 * @property-read string $component The component of this handler 34 * @property-read int $defaultexpiration Default expiration of new addresses for this handler 35 * @property-read string $description The description of this handler 36 * @property-read string $name The name of this handler 37 * @property-read bool $validateaddress Whether the address validation is a requiredment 38 * @property-read bool $enabled Whether this handler is currently enabled 39 * @property-read string $classname The name of handler class 40 */ 41 abstract class handler { 42 43 /** 44 * @var int $id The id of the handler in the database. 45 */ 46 private $id = null; 47 48 /** 49 * @var string $component The component to which this handler belongs. 50 */ 51 private $component = ''; 52 53 /** 54 * @var int $defaultexpiration The default expiration time to use when created a new key. 55 */ 56 private $defaultexpiration = WEEKSECS; 57 58 /** 59 * @var bool $validateaddress Whether to validate the sender address when processing this handler. 60 */ 61 private $validateaddress = true; 62 63 /** 64 * @var bool $enabled Whether this handler is currently enabled. 65 */ 66 private $enabled = false; 67 68 /** 69 * @var $accessibleproperties A list of the properties which can be read. 70 */ 71 private $accessibleproperties = array( 72 'id' => true, 73 'component' => true, 74 'defaultexpiration' => true, 75 'validateaddress' => true, 76 'enabled' => true, 77 ); 78 79 /** 80 * Magic getter to fetch the specified key. 81 * 82 * @param string $key The name of the key to retrieve 83 */ 84 public function __get($key) { 85 // Some properties have logic behind them. 86 $getter = 'get_' . $key; 87 if (method_exists($this, $getter)) { 88 return $this->$getter(); 89 } 90 91 // Check for a commonly accessibly property. 92 if (isset($this->accessibleproperties[$key])) { 93 return $this->$key; 94 } 95 96 // Unknown property - bail. 97 throw new \coding_exception('unknown_property ' . $key); 98 } 99 100 /** 101 * Set the id name. 102 * 103 * @param int $id The id to set 104 * @return int The newly set id 105 */ 106 public function set_id($id) { 107 return $this->id = $id; 108 } 109 110 /** 111 * Set the component name. 112 * 113 * @param string $component The component to set 114 * @return string The newly set component 115 */ 116 public function set_component($component) { 117 return $this->component = $component; 118 } 119 120 /** 121 * Whether the current handler allows changes to the address validation 122 * setting. 123 * 124 * By default this will return true, but for some handlers it may be 125 * necessary to disallow such changes. 126 * 127 * @return boolean 128 */ 129 public function can_change_validateaddress() { 130 return true; 131 } 132 133 /** 134 * Set whether validation of the address is required. 135 * 136 * @param bool $validateaddress The new state of validateaddress 137 * @return bool 138 */ 139 public function set_validateaddress($validateaddress) { 140 return $this->validateaddress = $validateaddress; 141 } 142 143 /** 144 * Whether this handler can be disabled (or enabled). 145 * 146 * By default this will return true, but for some handlers it may be 147 * necessary to disallow such changes. For example, a core handler to 148 * handle rejected mail validation should not be disabled. 149 * 150 * @return boolean 151 */ 152 public function can_change_enabled() { 153 return true; 154 } 155 156 /** 157 * Set the enabled name. 158 * 159 * @param bool $enabled The new state of enabled 160 * @return bool 161 */ 162 public function set_enabled($enabled) { 163 return $this->enabled = $enabled; 164 } 165 166 /** 167 * Set the default validity for new keys. 168 * 169 * @param int $period The time in seconds before a key expires 170 * @return int 171 */ 172 public function set_defaultexpiration($period) { 173 return $this->defaultexpiration = $period; 174 } 175 176 /** 177 * Get the non-namespaced name of the current class. 178 * 179 * @return string The classname 180 */ 181 private function get_classname() { 182 $classname = get_class($this); 183 if (strpos($classname, '\\') !== 0) { 184 $classname = '\\' . $classname; 185 } 186 187 return $classname; 188 } 189 190 /** 191 * Return a description for the current handler. 192 * 193 * @return string 194 */ 195 protected abstract function get_description(); 196 197 /** 198 * Return a name for the current handler. 199 * This appears in the admin pages as a human-readable name. 200 * 201 * @return string 202 */ 203 protected abstract function get_name(); 204 205 /** 206 * Process the message against the current handler. 207 * 208 * @param \stdClass $record The Inbound Message Handler record 209 * @param \stdClass $messagedata The message data 210 */ 211 public abstract function process_message(\stdClass $record, \stdClass $messagedata); 212 213 /** 214 * Return the content of any success notification to be sent. 215 * Both an HTML and Plain Text variant must be provided. 216 * 217 * If this handler does not need to send a success notification, then 218 * it should return a falsey value. 219 * 220 * @param \stdClass $messagedata The message data. 221 * @param \stdClass $handlerresult The record for the newly created post. 222 * @return \stdClass with keys `html` and `plain`. 223 */ 224 public function get_success_message(\stdClass $messagedata, $handlerresult) { 225 return false; 226 } 227 228 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |