Merge pull request #23710 from eileenmcnaughton/civi_import
[civicrm-core.git] / Civi / Pipe / LineSessionTrait.php
index f7ba82ef32388b076fa2e3de14bda8ab22427f06..d068b90d88a135477c22f398aeb1701166b48a51 100644 (file)
@@ -18,10 +18,10 @@ namespace Civi\Pipe;
  * $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();
@@ -32,10 +32,13 @@ trait LineSessionTrait {
   /**
    * 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;
   }
 
@@ -87,7 +90,7 @@ trait LineSessionTrait {
    *
    * @var int
    */
-  protected $maxLine = 524288;
+  protected $bufferSize = 524288;
 
   /**
    * A value to display immediately before the response lines.
@@ -110,11 +113,14 @@ trait LineSessionTrait {
 
   /**
    * 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;
@@ -133,16 +139,16 @@ trait LineSessionTrait {
   /**
    * @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;
   }