-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeWriter.php
58 lines (46 loc) · 990 Bytes
/
CodeWriter.php
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace yentu;
class CodeWriter
{
private $lines;
private $indentation;
public function add($line = '')
{
$this->lines .= str_repeat(' ', $this->indentation) . "$line\n";
}
public function addNoLn($line = '')
{
$this->lines .= str_repeat(' ', $this->indentation) . "$line";
}
public function addNoIndent($line = '')
{
$this->lines .= $line;
}
public function ln()
{
$this->lines .= "\n";
}
public function addIndent()
{
$this->indentation += 4;
}
public function decreaseIndent()
{
$this->indentation -= 4;
}
public function __toString()
{
$timestamp = $this->getTimestamp();
$header = <<< HEAD
<?php
/**
* Generated by yentu on $timestamp
*/
HEAD;
return $header . $this->lines;
}
protected function getTimestamp()
{
return date('jS F, Y H:i:s');
}
}