1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Error\Exporter; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Helper\Table; |
14
|
|
|
use Symfony\Component\Console\Helper\TableStyle; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class MarkdownTableExporter implements ErrorListExporterInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function getName(): string |
23
|
|
|
{ |
24
|
|
|
return 'markdown'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
|
|
public function export($errors, OutputInterface $output): void |
31
|
|
|
{ |
32
|
|
|
$rows = [ |
33
|
|
|
['Code', 'Text', 'Description'], |
34
|
|
|
['---', '---', '---'], |
35
|
|
|
]; |
36
|
|
|
foreach ($errors as $error) { |
37
|
|
|
$description = str_replace(["\n\n", "\n"], ['<br>', null], $error->getDescription()); |
38
|
|
|
$rows[] = [ |
39
|
|
|
sprintf('**%s**', $error->getCode()), |
40
|
|
|
sprintf('**%s**', $error->getMessage()), |
41
|
|
|
$description, |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$table = new Table($output); |
46
|
|
|
|
47
|
|
|
$styleGuide = new TableStyle(); |
48
|
|
|
$styleGuide->setHorizontalBorderChar('') |
49
|
|
|
->setVerticalBorderChar('|') |
50
|
|
|
->setCrossingChar(' ') |
51
|
|
|
->setCellHeaderFormat('%s'); |
52
|
|
|
|
53
|
|
|
$table->setStyle($styleGuide); |
54
|
|
|
$table->setRows($rows); |
55
|
|
|
$table->render(); |
56
|
|
|
} |
57
|
|
|
} |