/usr/share/php/Horde/Imap/Client/Data/Capability.php is in php-horde-imap-client 2.29.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | <?php
/**
* Copyright 2014-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
/**
* Query the capabilities of a server.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
* @since 2.24.0
*/
class Horde_Imap_Client_Data_Capability
implements Serializable, SplSubject
{
/**
* Capability data.
*
* @var array
*/
protected $_data = array();
/**
* Observers.
*
* @var array
*/
protected $_observers = array();
/**
* Add a capability (and optional parameters).
*
* @param string $capability The capability to add.
* @param mixed $params A parameter (or array of parameters) to add.
*/
public function add($capability, $params = null)
{
$capability = Horde_String::upper($capability);
if (is_null($params)) {
if (isset($this->_data[$capability])) {
return;
}
$params = true;
} else {
if (!is_array($params)) {
$params = array($params);
}
$params = array_map('Horde_String::upper', $params);
if (isset($this->_data[$capability]) &&
is_array($this->_data[$capability])) {
$params = array_merge($this->_data[$capability], $params);
}
}
$this->_data[$capability] = $params;
$this->notify();
}
/**
* Remove a capability.
*
* @param string $capability The capability to remove.
* @param string $params A parameter (or array of parameters) to
* remove from the capability.
*/
public function remove($capability, $params = null)
{
$capability = Horde_String::upper($capability);
if (is_null($params)) {
unset($this->_data[$capability]);
} elseif (isset($this->_data[$capability])) {
if (!is_array($params)) {
$params = array($params);
}
$params = array_map('Horde_String::upper', $params);
$this->_data[$capability] = is_array($this->_data[$capability])
? array_diff($this->_data[$capability], $params)
: array();
if (empty($this->_data[$capability])) {
unset($this->_data[$capability]);
}
}
$this->notify();
}
/**
* Returns whether the server supports the given capability.
*
* @param string $capability The capability string to query.
* @param string $parameter If set, require the parameter to exist.
*
* @return boolean True if the capability (and parameter) exist.
*/
public function query($capability, $parameter = null)
{
$capability = Horde_String::upper($capability);
if (!isset($this->_data[$capability])) {
return false;
}
return is_null($parameter) ?:
(is_array($this->_data[$capability]) &&
in_array(Horde_String::upper($parameter), $this->_data[$capability]));
}
/**
* Return the list of parameters for an extension.
*
* @param string $capability The capability string to query.
*
* @return array An array of parameters if the extension exists and
* supports parameters. Otherwise, an empty array.
*/
public function getParams($capability)
{
return ($this->query($capability) && is_array($out = $this->_data[Horde_String::upper($capability)]))
? $out
: array();
}
/**
* Is the extension enabled?
*
* @param string $capability The extension (+ parameter) to query. If
* null, returns all enabled extensions.
*
* @return mixed If $capability is null, return all enabled extensions.
* Otherwise, true if the extension (+ parameter) is
* enabled.
*/
public function isEnabled($capability = null)
{
return is_null($capability)
? array()
: false;
}
/**
* Returns the raw data.
*
* @deprecated
*
* @return array Capability data.
*/
public function toArray()
{
return $this->_data;
}
/* SplSubject methods. */
/**
*/
public function attach(SplObserver $observer)
{
$this->detach($observer);
$this->_observers[] = $observer;
}
/**
*/
public function detach(SplObserver $observer)
{
if (($key = array_search($observer, $this->_observers, true)) !== false) {
unset($this->_observers[$key]);
}
}
/**
* Notification is triggered internally whenever the object's internal
* data storage is altered.
*/
public function notify()
{
foreach ($this->_observers as $val) {
$val->update($this);
}
}
/* Serializable methods. */
/**
*/
public function serialize()
{
return json_encode($this->_data);
}
/**
*/
public function unserialize($data)
{
$this->_data = json_decode($data, true);
}
}
|