Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401]

   1  <?php
   2  
   3  /**
   4   * SCSSPHP
   5   *
   6   * @copyright 2012-2020 Leaf Corcoran
   7   *
   8   * @license http://opensource.org/licenses/MIT MIT
   9   *
  10   * @link http://scssphp.github.io/scssphp
  11   */
  12  
  13  namespace ScssPhp\ScssPhp\Logger;
  14  
  15  /**
  16   * A logger that prints to a PHP stream (for instance stderr)
  17   *
  18   * @final
  19   */
  20  class StreamLogger implements LoggerInterface
  21  {
  22      private $stream;
  23      private $closeOnDestruct;
  24  
  25      /**
  26       * @param resource $stream          A stream resource
  27       * @param bool     $closeOnDestruct If true, takes ownership of the stream and close it on destruct to avoid leaks.
  28       */
  29      public function __construct($stream, $closeOnDestruct = false)
  30      {
  31          $this->stream = $stream;
  32          $this->closeOnDestruct = $closeOnDestruct;
  33      }
  34  
  35      /**
  36       * @internal
  37       */
  38      public function __destruct()
  39      {
  40          if ($this->closeOnDestruct) {
  41              fclose($this->stream);
  42          }
  43      }
  44  
  45      /**
  46       * @inheritDoc
  47       */
  48      public function warn($message, $deprecation = false)
  49      {
  50          $prefix = ($deprecation ? 'DEPRECATION ' : '') . 'WARNING: ';
  51  
  52          fwrite($this->stream, $prefix . $message . "\n\n");
  53      }
  54  
  55      /**
  56       * @inheritDoc
  57       */
  58      public function debug($message)
  59      {
  60          fwrite($this->stream, $message . "\n");
  61      }
  62  }