1 | <?php |
||
23 | class ColoredSqlOutput extends Nette\Object implements OutputInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
28 | */ |
||
29 | private $output; |
||
30 | |||
31 | |||
32 | |||
33 | public function __construct(OutputInterface $output) |
||
37 | |||
38 | |||
39 | |||
40 | protected function formatSqls($message) |
||
41 | { |
||
42 | $message = Nette\Utils\Strings::replace($message, "~((?:CREATE|ALTER|DROP)\\s+TABLE|(?:DROP|CREATE)\\s+INDEX)[^;]+;~i", function (array $match) { |
||
43 | $output = Nette\Utils\Strings::replace($match[0], '~(?<=\b)([^\s]*[a-z]+[^\s]*)(?=\b)~', function ($id) { |
||
44 | return '<info>' . $id[0] . '</info>'; |
||
45 | }); |
||
46 | $output = Nette\Utils\Strings::replace($output, '~(?<=\b)(CREATE|ALTER|DROP|TABLE|INDEX|ADD|CHANGE|PRIMARY\s+KEY|UNIQUE|CONSTRAINT|FOREIGN\s+KEY|REFERENCES|COMMENT|ENGINE)(?=\b)~', function ($id) { |
||
47 | return '<fg=cyan>' . $id[0] . '</fg=cyan>'; |
||
48 | }); |
||
49 | |||
50 | return $output; |
||
51 | }); |
||
52 | $message = Nette\Utils\Strings::replace($message, '~(?<=\b)(INSERT|UPDATE|SELECT|DELETE|INTO|VALUES|ON\s+DUPLICATE\s+KEY\s+UPDATE|SET|FROM|JOIN|LEFT|RIGHT|INNER|OUTER|NATURAL|CROSS|FULL|ON|WHERE|GROUP\s+BY|HAVING|ORDER\s+BY|LIMIT|OFFSET|UNION)(?=\b)~', function ($id) { |
||
53 | return '<comment>' . $id[0] . '</comment>'; |
||
54 | }); |
||
55 | $message = Nette\Utils\Strings::replace($message, '~(?<=\b)(AS|ASC|DESC|USING|DEFAULT|DISTINCT|AND|OR|IN|BETWEEN|IS|LIKE|NOT|NULL|ALL|ANY|SOME|EXISTS|SET\s+NULL|AUTO_INCREMENT|CASCADE|RESTRICT|INT|SMALLINT|TINYINT|NUMERIC|VARCHAR|DATETIME|TIMESTAMP|TEXT)(?=\b)~', function ($id) { |
||
56 | return '<fg=magenta>' . $id[0] . '</fg=magenta>'; |
||
57 | }); |
||
58 | |||
59 | return $message; |
||
60 | } |
||
61 | |||
62 | |||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL) |
||
71 | |||
72 | |||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function writeln($messages, $type = self::OUTPUT_NORMAL) |
||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function setVerbosity($level) |
||
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getVerbosity() |
||
101 | |||
102 | |||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function setDecorated($decorated) |
||
111 | |||
112 | |||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function isDecorated() |
||
121 | |||
122 | |||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function isQuiet() |
||
131 | |||
132 | |||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | public function isVerbose() |
||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | public function isVeryVerbose() |
||
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function isDebug() |
||
161 | |||
162 | |||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function setFormatter(OutputFormatterInterface $formatter) |
||
171 | |||
172 | |||
173 | |||
174 | /** |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | public function getFormatter() |
||
181 | |||
182 | } |
||
183 |