@@ -47,7 +47,7 @@ public function write(string $input) {
4747 public function clearTillPrompt (): void {
4848 $ this ->write ('' );
4949 do {
50- $ promptLine = $ this ->readLine ();
50+ $ promptLine = $ this ->readTillPrompt ();
5151 if ($ promptLine === false ) {
5252 break ;
5353 }
@@ -56,13 +56,12 @@ public function clearTillPrompt(): void {
5656 if ($ this ->write ('' ) === false ) {
5757 throw new ConnectionRefusedException ();
5858 }
59- $ this ->readLine ();
59+ $ this ->readTillPrompt ();
6060 }
6161
6262 /**
6363 * get all unprocessed output from smbclient until the next prompt
6464 *
65- * @param (callable(string):bool)|null $callback (optional) callback to call for every line read
6665 * @return string[]
6766 * @throws AuthenticationException
6867 * @throws ConnectException
@@ -71,42 +70,22 @@ public function clearTillPrompt(): void {
7170 * @throws NoLoginServerException
7271 * @throws AccessDeniedException
7372 */
74- public function read (callable $ callback = null ): array {
73+ public function read (): array {
7574 if (!$ this ->isValid ()) {
7675 throw new ConnectionException ('Connection not valid ' );
7776 }
78- $ promptLine = $ this ->readLine (); //first line is prompt
79- if ($ promptLine === false ) {
80- $ this ->unknownError ($ promptLine );
81- }
82- $ this ->parser ->checkConnectionError ($ promptLine );
83-
84- $ output = [];
85- if (!$ this ->isPrompt ($ promptLine )) {
86- $ line = $ promptLine ;
87- } else {
88- $ line = $ this ->readLine ();
89- }
90- if ($ line === false ) {
91- $ this ->unknownError ($ promptLine );
92- }
93- while ($ line !== false && !$ this ->isPrompt ($ line )) { //next prompt functions as delimiter
94- if (is_callable ($ callback )) {
95- $ result = $ callback ($ line );
96- if ($ result === false ) { // allow the callback to close the connection for infinite running commands
97- $ this ->close (true );
98- break ;
99- }
100- } else {
101- $ output [] = $ line ;
102- }
103- $ line = $ this ->readLine ();
77+ $ output = $ this ->readTillPrompt ();
78+ if ($ output === false ) {
79+ $ this ->unknownError (false );
10480 }
81+ $ output = explode ("\n" , $ output );
82+ // last line contains the prompt
83+ array_pop ($ output );
10584 return $ output ;
10685 }
10786
10887 private function isPrompt (string $ line ): bool {
109- return mb_substr ($ line , 0 , self ::DELIMITER_LENGTH ) === self ::DELIMITER ;
88+ return substr ($ line , 0 , self ::DELIMITER_LENGTH ) === self ::DELIMITER ;
11089 }
11190
11291 /**
0 commit comments