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

Commit

Permalink
Merge pull request #16 from Renegade334/master+numeric-target
Browse files Browse the repository at this point in the history
Extract target from numeric replies
  • Loading branch information
elazar committed Mar 29, 2015
2 parents d9e63ea + ad796d9 commit 5b84b81
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
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

0 comments on commit 5b84b81

Please sign in to comment.