Erebot  latest
A modular IRC bot for PHP 5.3+
Base.php
1 <?php
2 /*
3  This file is part of Erebot, a modular IRC bot written in PHP.
4 
5  Copyright © 2010 François Poirotte
6 
7  Erebot is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Erebot is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Erebot. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 namespace Erebot\NumericProfile;
22 
33 abstract class Base implements \ArrayAccess
34 {
36  const ERR_ALREADYREGISTERED = 'ERR_ALREADYREGISTRED';
38  const ERR_ALREADYREGISTRED = 'ERR_ALREADYREGISTERED';
39 
41  const ERR_CANTCHANGENICK = 'ERR_NONICKCHANGE';
43  const ERR_NONICKCHANGE = 'ERR_CANTCHANGENICK';
44 
46  const ERR_CANTJOINOPERSONLY = 'ERR_OPERONLY';
48  const ERR_OPERONLY = 'ERR_OPERONLYCHAN';
50  const ERR_OPERONLYCHAN = 'ERR_CANTJOINOPERSONLY';
51 
53  const ERR_CHANOPPRIVSNEEDED = 'ERR_CHANOPRIVSNEEDED';
55  const ERR_CHANOPRIVSNEEDED = 'ERR_CHANOPPRIVSNEEDED';
56 
58  const ERR_KICKNOREJOIN = 'ERR_DELAYREJOIN';
60  const ERR_DELAYREJOIN = 'ERR_KICKNOREJOIN';
61 
63  const ERR_LAST_ERR_MSG = 'ERR_NUMERICERR';
65  const ERR_NUMERICERR = 'ERR_NUMERIC_ERR';
67  const ERR_NUMERIC_ERR = 'ERR_LAST_ERR_MSG';
68 
70  const ERR_NCHANGETOOFAST = 'ERR_NICKTOOFAST';
72  const ERR_NICKTOOFAST = 'ERR_NCHANGETOOFAST';
73 
75  const ERR_NEEDPONG = 'ERR_BADPING';
77  const ERR_BADPING = 'ERR_NEEDPONG';
78 
80  const ERR_NOCTCP = 'ERR_NOCTCPALLOWED';
82  const ERR_NOCTCPALLOWED = 'ERR_NOCTCP';
83 
85  const ERR_NOSWEAR = 'ERR_WORDFILTERED';
87  const ERR_WORDFILTERED = 'ERR_NOSWEAR';
88 
90  const ERR_NOTSSLCLIENT = 'ERR_NOSSL';
92  const ERR_NOSSL = 'ERR_NOTSSLCLIENT';
93 
95  const ERR_STARTTLS = 'ERR_STARTTLSFAIL';
97  const ERR_STARTTLSFAIL = 'ERR_STARTTLS';
98 
100  const ERR_TARGETTOFAST = 'ERR_TARGETTOOFAST';
102  const ERR_TARGETTOOFAST = 'ERR_TARGETTOFAST';
103 
105  const RPL_CHANNELCREATED = 'RPL_CREATIONTIME';
107  const RPL_CREATIONTIME = 'RPL_CHANNELCREATED';
108 
110  const RPL_ENDMAP = 'RPL_MAPEND';
112  const RPL_MAPEND = 'RPL_ENDMAP';
113 
115  const RPL_ENDOFTRACE = 'RPL_TRACEEND';
117  const RPL_TRACEEND = 'RPL_ENDOFTRACE';
118 
120  const RPL_EXEMPTLIST = 'RPL_EXLIST';
122  const RPL_EXLIST = 'RPL_EXCEPTLIST';
124  const RPL_EXCEPTLIST = 'RPL_EXEMPTLIST';
125 
127  const RPL_INVEXLIST = 'RPL_INVITELIST';
129  const RPL_INVITELIST = 'RPL_INVEXLIST';
130 
132  const RPL_LISTSYNTAX = 'RPL_COMMANDSYNTAX';
134  const RPL_COMMANDSYNTAX = 'RPL_LISTSYNTAX';
135 
137  const RPL_ENDOFEXEMPTLIST = 'RPL_ENDOFEXLIST';
139  const RPL_ENDOFEXLIST = 'RPL_ENDOFEXCEPTLIST';
141  const RPL_ENDOFEXCEPTLIST = 'RPL_ENDOFEXEMPTLIST';
142 
144  const RPL_ENDOFINVEXLIST = 'RPL_ENDOFINVITELIST';
146  const RPL_ENDOFINVITELIST = 'RPL_ENDOFINVEXLIST';
147 
149  const RPL_LOAD2HI = 'RPL_TRYAGAIN';
151  const RPL_TRYAGAIN = 'RPL_LOAD2HI';
152 
154  const RPL_NAMEREPLY = 'RPL_NAMREPLY';
156  const RPL_NAMREPLY = 'RPL_NAMEREPLY';
157 
159  const RPL_REDIR = 'RPL_BOUNCE';
161  const RPL_BOUNCE = 'RPL_REDIR';
162 
164  const RPL_RULESEND = 'RPL_ENDOFRULES';
166  const RPL_ENDOFRULES = 'RPL_RULESEND';
167 
169  const RPL_RULESSTART = 'RPL_RULESTART';
171  const RPL_RULESTART = 'RPL_RULESSTART';
172 
174  const RPL_SERVERCREATED = 'RPL_CREATED';
176  const RPL_CREATED = 'RPL_SERVERCREATED';
177 
179  const RPL_SERVERVERSION = 'RPL_MYINFO';
181  const RPL_MYINFO = 'RPL_SERVERVERSION';
182 
184  const RPL_STARTTLS = 'RPL_STARTTLSOK';
186  const RPL_STARTTLSOK = 'RPL_STARTTLS';
187 
189  const RPL_TOPICTIME = 'RPL_TOPICWHOTIME';
191  const RPL_TOPICWHOTIME = 'RPL_TOPICTIME';
192 
194  const RPL_WHOISSECURE = 'RPL_USINGSSL';
196  const RPL_USINGSSL = 'RPL_WHOISSECURE';
197 
199  const RPL_YOUAREOPER = 'RPL_YOUREOPER';
201  const RPL_YOUREOPER = 'RPL_YOUAREOPER';
202 
204  const RPL_YOURHOSTIS = 'RPL_YOURHOST';
206  const RPL_YOURHOST = 'RPL_YOURHOSTIS';
207 
209  const RPL_YOURUUID = 'RPL_YOURID';
211  const RPL_YOURID = 'RPL_YOURUUID';
212 
213 
215  protected $reflector;
216 
217 
219  final public function __construct()
220  {
221  $this->reflector = new \ReflectionClass(get_called_class());
222  }
223 
225  public function offsetExists($offset)
226  {
227  return ($this[$offset] !== null);
228  }
229 
231  public function offsetGet($offset)
232  {
233  if (!is_string($offset)) {
234  throw new \Erebot\InvalidValueException('Not a valid name');
235  }
236 
237  $seen = array();
238  $name = strtoupper($offset);
239  while (!in_array($name, $seen)) {
240  $seen[] = $name;
241 
242  if (!$this->reflector->hasConstant($name)) {
243  return null;
244  }
245  $constValue = $this->reflector->getConstant($name);
246 
247  if (is_int($constValue) &&
248  $constValue > 0 &&
249  $constValue <= 999) {
250  return $constValue;
251  }
252 
253  if (is_string($constValue)) {
254  $name = strtoupper($constValue);
255  continue;
256  }
257 
258  return null;
259  }
260  throw new \Erebot\InvalidValueException('Loop detected');
261  }
262 
264  public function offsetSet($offset, $value)
265  {
266  throw new \Erebot\NotImplementedException();
267  }
268 
270  public function offsetUnset($offset)
271  {
272  throw new \Erebot\NotImplementedException();
273  }
274 }
const RPL_STARTTLS
Alias for Erebot::Interfaces::Numerics::RPL_STARTTLSOK.
Definition: Base.php:184
const ERR_LAST_ERR_MSG
Alias for Erebot::Interfaces::Numerics::ERR_NUMERICERR.
Definition: Base.php:63
const RPL_REDIR
Alias for Erebot::Interfaces::Numerics::RPL_BOUNCE.
Definition: Base.php:159
const RPL_YOURID
Alias for Erebot::Interfaces::Numerics::RPL_YOURUUID.
Definition: Base.php:211
Interface to provide accessing objects as arrays.
Definition: ArrayAccess.php:10
const RPL_COMMANDSYNTAX
Alias for Erebot::Interfaces::Numerics::RPL_LISTSYNTAX.
Definition: Base.php:134
const RPL_YOURHOST
Alias for Erebot::Interfaces::Numerics::RPL_YOURHOSTIS.
Definition: Base.php:206
const RPL_ENDOFINVEXLIST
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFINVITELIST.
Definition: Base.php:144
const RPL_STARTTLSOK
Alias for Erebot::Interfaces::Numerics::RPL_STARTTLS.
Definition: Base.php:186
const RPL_MYINFO
Alias for Erebot::Interfaces::Numerics::RPL_SERVERVERSION.
Definition: Base.php:181
const ERR_WORDFILTERED
Alias for Erebot::Interfaces::Numerics::ERR_NOSWEAR.
Definition: Base.php:87
const RPL_RULESSTART
Alias for Erebot::Interfaces::Numerics::RPL_RULESTART.
Definition: Base.php:169
Abstract class that serves as a base to create a numeric profile for an IRCd server.
Definition: Base.php:33
const ERR_NOTSSLCLIENT
Alias for Erebot::Interfaces::Numerics::ERR_NOSSL.
Definition: Base.php:90
const RPL_EXLIST
Alias for Erebot::Interfaces::Numerics::RPL_EXCEPTLIST.
Definition: Base.php:122
const RPL_RULESEND
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFRULES.
Definition: Base.php:164
const RPL_TRACEEND
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFTRACE.
Definition: Base.php:117
const ERR_ALREADYREGISTERED
Alias for Erebot::Interfaces::Numerics::ERR_ALREADYREGISTRED.
Definition: Base.php:36
const RPL_INVEXLIST
Alias for Erebot::Interfaces::Numerics::RPL_INVITELIST.
Definition: Base.php:127
const ERR_NEEDPONG
Alias for Erebot::Interfaces::Numerics::ERR_BADPING.
Definition: Base.php:75
const RPL_CREATED
Alias for Erebot::Interfaces::Numerics::RPL_SERVERCREATED.
Definition: Base.php:176
const ERR_CHANOPRIVSNEEDED
Alias for Erebot::Interfaces::Numerics::ERR_CHANOPPRIVSNEEDED.
Definition: Base.php:55
const RPL_LOAD2HI
Alias for Erebot::Interfaces::Numerics::RPL_TRYAGAIN.
Definition: Base.php:149
const RPL_YOURUUID
Alias for Erebot::Interfaces::Numerics::RPL_YOURID.
Definition: Base.php:209
const RPL_USINGSSL
Alias for Erebot::Interfaces::Numerics::RPL_WHOISSECURE.
Definition: Base.php:196
const RPL_NAMEREPLY
Alias for Erebot::Interfaces::Numerics::RPL_NAMREPLY.
Definition: Base.php:154
const RPL_EXCEPTLIST
Alias for Erebot::Interfaces::Numerics::RPL_EXEMPTLIST.
Definition: Base.php:124
const RPL_YOUREOPER
Alias for Erebot::Interfaces::Numerics::RPL_YOUAREOPER.
Definition: Base.php:201
const ERR_NOSWEAR
Alias for Erebot::Interfaces::Numerics::ERR_WORDFILTERED.
Definition: Base.php:85
const RPL_EXEMPTLIST
Alias for Erebot::Interfaces::Numerics::RPL_EXLIST.
Definition: Base.php:120
const ERR_NOSSL
Alias for Erebot::Interfaces::Numerics::ERR_NOTSSLCLIENT.
Definition: Base.php:92
const RPL_LISTSYNTAX
Alias for Erebot::Interfaces::Numerics::RPL_COMMANDSYNTAX.
Definition: Base.php:132
const ERR_NUMERICERR
Alias for Erebot::Interfaces::Numerics::ERR_NUMERIC_ERR.
Definition: Base.php:65
const RPL_ENDMAP
Alias for Erebot::Interfaces::Numerics::RPL_MAPEND.
Definition: Base.php:110
const RPL_TOPICTIME
Alias for Erebot::Interfaces::Numerics::RPL_TOPICWHOTIME.
Definition: Base.php:189
const RPL_TOPICWHOTIME
Alias for Erebot::Interfaces::Numerics::RPL_TOPICTIME.
Definition: Base.php:191
const RPL_SERVERVERSION
Alias for Erebot::Interfaces::Numerics::RPL_MYINFO.
Definition: Base.php:179
const RPL_YOURHOSTIS
Alias for Erebot::Interfaces::Numerics::RPL_YOURHOST.
Definition: Base.php:204
const RPL_BOUNCE
Alias for Erebot::Interfaces::Numerics::RPL_REDIR.
Definition: Base.php:161
const RPL_RULESTART
Alias for Erebot::Interfaces::Numerics::RPL_RULESSTART.
Definition: Base.php:171
const ERR_OPERONLYCHAN
Alias for Erebot::Interfaces::Numerics::ERR_CANTJOINOPERSONLY.
Definition: Base.php:50
const ERR_TARGETTOOFAST
Alias for Erebot::Interfaces::Numerics::ERR_TARGETTOFAST.
Definition: Base.php:102
const RPL_ENDOFEXEMPTLIST
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFEXLIST.
Definition: Base.php:137
const RPL_TRYAGAIN
Alias for Erebot::Interfaces::Numerics::RPL_LOAD2HI.
Definition: Base.php:151
const RPL_ENDOFTRACE
Alias for Erebot::Interfaces::Numerics::RPL_TRACEEND.
Definition: Base.php:115
const RPL_ENDOFINVITELIST
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFINVEXLIST.
Definition: Base.php:146
const RPL_WHOISSECURE
Alias for Erebot::Interfaces::Numerics::RPL_USINGSSL.
Definition: Base.php:194
const ERR_NCHANGETOOFAST
Alias for Erebot::Interfaces::Numerics::ERR_NICKTOOFAST.
Definition: Base.php:70
const ERR_NUMERIC_ERR
Alias for Erebot::Interfaces::Numerics::ERR_LAST_ERR_MSG.
Definition: Base.php:67
const RPL_NAMREPLY
Alias for Erebot::Interfaces::Numerics::RPL_NAMEREPLY.
Definition: Base.php:156
const ERR_CHANOPPRIVSNEEDED
Alias for Erebot::Interfaces::Numerics::ERR_CHANOPRIVSNEEDED.
Definition: Base.php:53
const RPL_ENDOFEXLIST
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFEXCEPTLIST.
Definition: Base.php:139
const RPL_INVITELIST
Alias for Erebot::Interfaces::Numerics::RPL_INVEXLIST.
Definition: Base.php:129
const ERR_CANTJOINOPERSONLY
Alias for Erebot::Interfaces::Numerics::ERR_OPERONLY.
Definition: Base.php:46
__construct()
Constructs a new instance of this numeric profile.
Definition: Base.php:219
const ERR_DELAYREJOIN
Alias for Erebot::Interfaces::Numerics::ERR_KICKNOREJOIN.
Definition: Base.php:60
const ERR_NOCTCPALLOWED
Alias for Erebot::Interfaces::Numerics::ERR_NOCTCPALLOWED.
Definition: Base.php:82
const RPL_CHANNELCREATED
Alias for Erebot::Interfaces::Numerics::RPL_CREATIONTIME.
Definition: Base.php:105
const ERR_STARTTLSFAIL
Alias for Erebot::Interfaces::Numerics::ERR_STARTTLS.
Definition: Base.php:97
$reflector
Reflection object for this class.
Definition: Base.php:215
const ERR_KICKNOREJOIN
Alias for Erebot::Interfaces::Numerics::ERR_DELAYREJOIN.
Definition: Base.php:58
offsetSet($offset, $value)
Definition: Base.php:264
const ERR_OPERONLY
Alias for Erebot::Interfaces::Numerics::ERR_OPERONLYCHAN.
Definition: Base.php:48
const RPL_MAPEND
Alias for Erebot::Interfaces::Numerics::RPL_ENDMAP.
Definition: Base.php:112
const ERR_CANTCHANGENICK
Alias for Erebot::Interfaces::Numerics::ERR_NONICKCHANGE.
Definition: Base.php:41
const RPL_ENDOFEXCEPTLIST
Alias for Erebot::Interfaces::Numerics::RPL_ENDOFEXEMPTLIST.
Definition: Base.php:141
const ERR_NOCTCP
Alias for Erebot::Interfaces::Numerics::ERR_NOCTCP.
Definition: Base.php:80
const RPL_CREATIONTIME
Alias for Erebot::Interfaces::Numerics::RPL_CHANNELCREATED.
Definition: Base.php:107
const RPL_ENDOFRULES
Alias for Erebot::Interfaces::Numerics::RPL_RULESEND.
Definition: Base.php:166
const ERR_NONICKCHANGE
Alias for Erebot::Interfaces::Numerics::ERR_CANTCHANGENICK.
Definition: Base.php:43
const ERR_NICKTOOFAST
Alias for Erebot::Interfaces::Numerics::ERR_NCHANGETOOFAST.
Definition: Base.php:72
const ERR_ALREADYREGISTRED
Alias for Erebot::Interfaces::Numerics::ERR_ALREADYREGISTERED.
Definition: Base.php:38
const ERR_TARGETTOFAST
Alias for Erebot::Interfaces::Numerics::ERR_TARGETTOOFAST.
Definition: Base.php:100
const ERR_BADPING
Alias for Erebot::Interfaces::Numerics::ERR_NEEDPONG.
Definition: Base.php:77
const RPL_SERVERCREATED
Alias for Erebot::Interfaces::Numerics::RPL_CREATED.
Definition: Base.php:174
const ERR_STARTTLS
Alias for Erebot::Interfaces::Numerics::ERR_STARTTLSFAIL.
Definition: Base.php:95
const RPL_YOUAREOPER
Alias for Erebot::Interfaces::Numerics::RPL_YOUREOPER.
Definition: Base.php:199