Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
}