Skip to content

Commit 386e429

Browse files
authored
Merge pull request #12 from graze/addPromptMatchInterface
Add PromptMatcherInterface
2 parents 775bc96 + 5df09dd commit 386e429

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/PromptMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Graze\TelnetClient;
1616

17-
class PromptMatcher
17+
class PromptMatcher implements PromptMatcherInterface
1818
{
1919
/**
2020
* @var array
@@ -33,7 +33,7 @@ class PromptMatcher
3333
*
3434
* @return bool
3535
*/
36-
public function isMatch($prompt, $subject, $lineEnding)
36+
public function isMatch($prompt, $subject, $lineEnding = null)
3737
{
3838
// cheap line ending check before expensive regex
3939
if (substr($subject, -1 * strlen($lineEnding)) != $lineEnding) {

src/PromptMatcherInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Graze\TelnetClient;
4+
5+
interface PromptMatcherInterface
6+
{
7+
/**
8+
* @param string $prompt
9+
* @param string $subject
10+
* @param string $lineEnding
11+
* @return bool
12+
*/
13+
public function isMatch($prompt, $subject, $lineEnding = null);
14+
15+
/**
16+
* @return string[]
17+
*/
18+
public function getMatches();
19+
20+
/**
21+
* @return string
22+
*/
23+
public function getResponseText();
24+
}

src/TelnetClient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use \Graze\TelnetClient\TelnetClientInterface;
1818
use \Graze\TelnetClient\PromptMatcher;
19+
use \Graze\TelnetClient\PromptMatcherInterface;
1920
use \Graze\TelnetClient\InterpretAsCommand;
2021
use \Socket\Raw\Socket;
2122
use \Socket\Raw\Factory as SocketFactory;
@@ -31,7 +32,7 @@ class TelnetClient implements TelnetClientInterface
3132
protected $socketFactory;
3233

3334
/**
34-
* @var PromptMatcher
35+
* @var PromptMatcherInterface
3536
*/
3637
protected $promptMatcher;
3738

@@ -82,12 +83,12 @@ class TelnetClient implements TelnetClientInterface
8283

8384
/**
8485
* @param SocketFactory $socketFactory
85-
* @param PromptMatcher $promptMatcher
86+
* @param PromptMatcherInterface $promptMatcher
8687
* @param InterpretAsCommand $interpretAsCommand
8788
*/
8889
public function __construct(
8990
SocketFactory $socketFactory,
90-
PromptMatcher $promptMatcher,
91+
PromptMatcherInterface $promptMatcher,
9192
InterpretAsCommand $interpretAsCommand
9293
) {
9394
$this->socketFactory = $socketFactory;

0 commit comments

Comments
 (0)