Sign in

davyin-co / drupal-cms · Files

GitLab

  • Go to group
  • Project
  • Activity
  • Files
  • Commits
  • Builds 0
  • Graphs
  • Milestones
  • Issues 0
  • Merge Requests 0
  • Labels
  • Wiki
  • Forks
  • Network
  • drupal-cms
  • vendor
  • chi-teck
  • drupal-code-generator
  • src
  • InputOutput
  • IOAwareTrait.php
  • init
    b4927f1e
    Terry authored
    2025-01-17 13:04:07 +0800  
    Browse Files »
IOAwareTrait.php 422 Bytes
Raw Blame History Permalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php

declare(strict_types=1);

namespace DrupalCodeGenerator\InputOutput;

/**
 * Defines a trait to set and get console IO.
 */
trait IOAwareTrait {

  private ?IO $io = NULL;

  /**
   * {@inheritdoc}
   */
  public function io(?IO $io = NULL): IO {
    if ($io) {
      $this->io = $io;
    }
    elseif (!$this->io) {
      throw new \LogicException('IO is not initialized yet.');
    }
    return $this->io;
  }

}