Passed
Push — main ( 221f6d...f8c128 )
by Siad
05:28
created

src/Phing/Io/LogWriter.php (2 issues)

1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Io;
22
23
use Phing\Project;
24
use Phing\Task;
25
26
/**
27
 * Extends the Writer class to output messages to Phing's log.
28
 *
29
 * @author  Michiel Rook <[email protected]>
30
 */
31
class LogWriter extends Writer
32
{
33
    private $task;
34
35
    private $level;
36
37
    /**
38
     * Constructs a new LogWriter object.
39
     *
40
     * @param int $level
41
     */
42 8
    public function __construct(Task $task, $level = Project::MSG_INFO)
43
    {
44 8
        $this->task = $task;
45 8
        $this->level = $level;
46 8
    }
47
48
    /**
49
     * @param string $buf
50
     * @param null   $off
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $off is correct as it would always require null to be passed?
Loading history...
51
     * @param null   $len
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $len is correct as it would always require null to be passed?
Loading history...
52
     *
53
     * @see Writer::write()
54
     */
55 7
    public function write($buf, $off = null, $len = null)
56
    {
57 7
        $lines = explode("\n", $buf);
58
59 7
        foreach ($lines as $line) {
60 7
            if ('' == $line) {
61 3
                continue;
62
            }
63
64 7
            $this->task->log($line, $this->level);
65
        }
66 7
    }
67
68
    /**
69
     * @see Writer::reset()
70
     */
71
    public function reset()
72
    {
73
    }
74
75
    /**
76
     * @see Writer::close()
77
     */
78 8
    public function close()
79
    {
80 8
    }
81
82
    /**
83
     * @see Writer::open()
84
     */
85
    public function open()
86
    {
87
    }
88
89
    /**
90
     * @see Writer::getResource()
91
     */
92
    public function getResource()
93
    {
94
        return $this->task;
95
    }
96
}
97