48 if (is_array($parts)) {
50 foreach ($parts as $part) {
51 if (strpos($part,
' ') !==
false) {
56 throw new \Erebot\InvalidValueException(
57 'Multiple tokens containing spaces'
61 throw new \Erebot\InvalidValueException(
62 'At least one token must be passed'
65 } elseif (is_string($parts)) {
68 $pos = strpos($msg,
' :');
76 $parts = array((
string) substr($msg, 2));
81 $parts = explode(
' ', substr($msg, 1, $pos - 1));
82 $parts[] = (string) substr($msg, $pos + 2);
86 $parts = explode(
' ', (
string) substr($msg, 1));
89 throw new \Erebot\InvalidValueException(
90 'A string or an array was expected'
94 $this->parts = $parts;
98 public function __toString()
100 $last = count($this->parts) - 1;
102 foreach ($this->parts as $index => $part) {
103 if ($index == $last) {
104 if (strpos($part,
' ') !==
false || !strncmp($part,
':', 1)) {
107 } elseif (!strncmp($part,
':', 1)) {
108 throw new \Exception(
'Oops!');
111 if ($index != $last) {
121 return count($this->parts);
127 return $this->parts[$this->position];
133 return $this->position;
151 return ($this->position < count($this->parts));
157 return isset($this->parts[$offset]);
163 if (!is_int($offset)) {
167 $offset += count($this->parts);
169 return $this->parts[$offset];
175 throw new \RuntimeException(
'The wrapped text is read-only');
181 unset($this->parts[$offset]);
182 $this->parts = array_values($this->parts);
$parts
The parts wrapped by this instance.
offsetSet($offset, $value)
$position
Position in the text.
A wrapper that correctly splits messages received from an IRC server (data part). ...