Skip to content

Commit 4e05e51

Browse files
committed
Protocol attribute accessors added to retrieve the resource stream, meta information, encryption and stream state
1 parent 78700ea commit 4e05e51

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/Connection/Protocols/Protocol.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,66 @@ public function enableUidCache(): void {
297297
public function disableUidCache(): void {
298298
$this->enable_uid_cache = false;
299299
}
300+
301+
/**
302+
* Set the encryption method
303+
* @param string $encryption
304+
*
305+
* @return void
306+
*/
307+
public function setEncryption(string $encryption): void {
308+
$this->encryption = $encryption;
309+
}
310+
311+
/**
312+
* Get the encryption method
313+
* @return string
314+
*/
315+
public function getEncryption(): string {
316+
return $this->encryption;
317+
}
318+
319+
/**
320+
* Check if the current session is connected
321+
*
322+
* @return bool
323+
*/
324+
public function connected(): bool {
325+
return (bool)$this->stream;
326+
}
327+
328+
/**
329+
* Retrieves header/meta data from the resource stream
330+
*
331+
* @return array
332+
*/
333+
public function meta(): array {
334+
if (!$this->stream) {
335+
return [
336+
"crypto" => [
337+
"protocol" => "",
338+
"cipher_name" => "",
339+
"cipher_bits" => 0,
340+
"cipher_version" => "",
341+
],
342+
"timed_out" => true,
343+
"blocked" => true,
344+
"eof" => true,
345+
"stream_type" => "tcp_socket/unknown",
346+
"mode" => "c",
347+
"unread_bytes" => 0,
348+
"seekable" => false,
349+
];
350+
}
351+
return stream_get_meta_data($this->stream);
352+
}
353+
354+
/**
355+
* Get the resource stream
356+
*
357+
* @return mixed
358+
*/
359+
public function getStream(): mixed {
360+
return $this->stream;
361+
}
300362
}

0 commit comments

Comments
 (0)