* $session = new class {
* use LineSessionTrait;
* protected function onRequest(string $requestLine): ?string {
- * return "Thanks";
+ * return 'Thanks';
* }
* protected function onException(string $requestLine, \Throwable $t): ?string {
- * return "Oops";
+ * return 'Oops';
* }
* }
* $session->setIO(STDIN, STDOUT)->run();
/**
* The onConnect() method is called when a new session is opened.
*
+ * @param string $negotiationFlags
+ * List of pipe initialization flags. See Civi::pipe() for description of flags.
* @return string|null
* Header/welcome line, or NULL if none.
+ * @see Civi::pipe
*/
- protected function onConnect(): ?string {
+ protected function onConnect(string $negotiationFlags): ?string {
return NULL;
}
*
* @var int
*/
- protected $maxLine = 524288;
+ protected $bufferSize = 524288;
/**
* A value to display immediately before the response lines.
/**
* Run the main loop. Poll for commands on $input and write responses to $output.
+ *
+ * @param string $negotiationFlags
+ * List of pipe initialization flags. See Civi::pipe() for description of flags.
*/
- public function run() {
- $this->write($this->onConnect());
+ public function run(string $negotiationFlags = '') {
+ $this->write($this->onConnect($negotiationFlags));
- while (FALSE !== ($line = stream_get_line($this->input, $this->maxLine, $this->delimiter))) {
+ while (FALSE !== ($line = stream_get_line($this->input, $this->bufferSize, $this->delimiter))) {
$line = rtrim($line, $this->delimiter);
if (empty($line)) {
continue;
/**
* @return int
*/
- public function getMaxLine(): int {
- return $this->maxLine;
+ public function getBufferSize(): int {
+ return $this->bufferSize;
}
/**
- * @param int $maxLine
+ * @param int $bufferSize
* @return $this
*/
- public function setMaxLine(int $maxLine) {
- $this->maxLine = $maxLine;
+ public function setBufferSize(int $bufferSize) {
+ $this->bufferSize = $bufferSize;
return $this;
}