示例#1
0
文件: Client.php 项目: clue/ami-react
 public function __construct(Stream $stream, Parser $parser = null)
 {
     if ($parser === null) {
         $parser = new Parser();
     }
     $this->stream = $stream;
     $that = $this;
     $this->stream->on('data', function ($chunk) use($parser, $that) {
         try {
             $messages = $parser->push($chunk);
         } catch (UnexpectedValueException $e) {
             $that->emit('error', array($e, $that));
             return;
         }
         foreach ($messages as $message) {
             $that->handleMessage($message);
         }
     });
     $this->on('error', array($that, 'close'));
     $this->stream->on('close', array($that, 'close'));
     $this->stream->resume();
 }
示例#2
0
 public function testParsingMissingSpaceEmptyValue()
 {
     $parser = new Parser();
     $this->assertEquals(array(), $parser->push("Asterisk Call Manager/1.3\r\n"));
     $ret = $parser->push("Response:\r\n\r\n");
     $this->assertCount(1, $ret);
     $first = reset($ret);
     /* @var $first Clue\React\Ami\Protocol\Response */
     $this->assertInstanceOf('Clue\\React\\Ami\\Protocol\\Response', $first);
     $this->assertEquals('', $first->getFieldValue('Response'));
 }
示例#3
0
 /**
  * @expectedException UnexpectedValueException
  */
 public function testParsingInvalidResponseNoSpaceAfterColonFails()
 {
     $parser = new Parser();
     $this->assertEquals(array(), $parser->push("Asterisk Call Manager/1.3\r\n"));
     $parser->push("Response:NoSpace\r\n\r\n");
 }