Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Extract target from numeric replies #16

Merged
merged 1 commit into from
Mar 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,22 @@ public function parse($message)
$parsed['code'] = $command;
}
if (!empty($parsed['params'])) {
$all = $this->strip($parsed['params']);
if (strpos($parsed['params'], ' :') !== false) {
list($head, $tail) = explode(' :', $parsed['params'], 2);
} else {
$head = $parsed['params'];
$tail = '';
// Slice off the target from the front of the reply
$temp = explode(' ', ltrim($parsed['params']), 2);
$parsed['target'] = array_shift($temp);
if ($parsed['params'] = (!empty($temp)) ? (' ' . array_shift($temp)) : '') {
$all = $this->strip($parsed['params']);
if (strpos($parsed['params'], ' :') !== false) {
list($head, $tail) = explode(' :', $parsed['params'], 2);
} else {
$head = $parsed['params'];
$tail = '';
}
$params = explode(' ', $head);
$params[] = $tail;
$parsed['params'] = array_filter($params);
$parsed['params']['all'] = $all;
}
$params = explode(' ', $head);
$params[] = $tail;
$parsed['params'] = array_filter($params);
$parsed['params']['all'] = $all;
}
}

Expand Down
22 changes: 11 additions & 11 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2527,15 +2527,15 @@ public function dataProviderTestParse()
'servername' => 'pratchett.freenode.net',
'command' => '004',
'params' => array(
1 => 'Phergie3',
2 => 'pratchett.freenode.net',
3 => 'ircd-seven-1.1.3',
4 => 'DOQRSZaghilopswz',
5 => 'CFILMPQbcefgijklmnopqrstvz',
6 => 'bkloveqjfI',
'all' => 'Phergie3 pratchett.freenode.net ircd-seven-1.1.3 DOQRSZaghilopswz CFILMPQbcefgijklmnopqrstvz bkloveqjfI',
1 => 'pratchett.freenode.net',
2 => 'ircd-seven-1.1.3',
3 => 'DOQRSZaghilopswz',
4 => 'CFILMPQbcefgijklmnopqrstvz',
5 => 'bkloveqjfI',
'all' => 'pratchett.freenode.net ircd-seven-1.1.3 DOQRSZaghilopswz CFILMPQbcefgijklmnopqrstvz bkloveqjfI',
),
'code' => '004',
'target' => 'Phergie3',
),
),

Expand All @@ -2547,13 +2547,13 @@ public function dataProviderTestParse()
'servername' => 'services.',
'command' => '328',
'params' => array(
1 => 'Phergie3',
2 => '#laravel',
3 => 'http://laravel.com',
'all' => 'Phergie3 #laravel :http://laravel.com',
1 => '#laravel',
2 => 'http://laravel.com',
'all' => '#laravel :http://laravel.com',
),
'message' => ":services. 328 Phergie3 #laravel :http://laravel.com\r\n",
'code' => '328',
'target' => 'Phergie3',
),
),

Expand Down