Erebot  latest
A modular IRC bot for PHP 7.0+
Numeric.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\Event;
22 
27 class Numeric implements \Erebot\Interfaces\Event\Numeric
28 {
30  protected $connection;
32  protected $numeric;
34  protected $source;
36  protected $target;
38  protected $text;
40  protected $halt;
41 
65  public function __construct(
66  \Erebot\Interfaces\Connection $connection,
67  $numeric,
68  $source,
69  $target,
70  $text
71  ) {
72  $this->halt = false;
73  $this->connection = $connection;
74  $this->numeric = $numeric;
75  $this->source = $source;
76  $this->target = $target;
77  $this->text = new \Erebot\TextWrapper((string) $text);
78  }
79 
81  public function __destruct()
82  {
83  }
84 
85  public function getConnection()
86  {
87  return $this->connection;
88  }
89 
90  public function getCode()
91  {
92  return $this->numeric;
93  }
94 
95  public function getSource()
96  {
97  return $this->source;
98  }
99 
100  public function getTarget()
101  {
102  return $this->target;
103  }
104 
105  public function getText()
106  {
107  return $this->text;
108  }
109 
110  public function preventDefault($prevent = null)
111  {
112  $res = $this->halt;
113  if ($prevent !== null) {
114  if (!is_bool($prevent)) {
115  throw new \Erebot\InvalidValueException('Bad prevention value');
116  }
117 
118  $this->halt = $prevent;
119  }
120  return $res;
121  }
122 }
$source
Source of the numeric event.
Definition: Numeric.php:34
__destruct()
Destructor.
Definition: Numeric.php:81
$halt
Whether the default action should be prevented or not.
Definition: Numeric.php:40
$text
Content of the numeric event.
Definition: Numeric.php:38
$numeric
Numeric code.
Definition: Numeric.php:32
$target
Target of the numeric event; this is usually the bot.
Definition: Numeric.php:36
__construct(\Erebot\Interfaces\Connection $connection, $numeric, $source, $target, $text)
Definition: Numeric.php:65
$connection
The connection object this numeric event came from.
Definition: Numeric.php:30
A class representing a numeric event.
Definition: Numeric.php:27