|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Knowledge Base package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015 LIN3S <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LIN3S\KnowledgeBaseBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use LIN3S\KnowledgeBase\Builder\DocumentationBuilder; |
|
15
|
|
|
use LIN3S\KnowledgeBase\Generator\HTMLGenerator; |
|
16
|
|
|
use LIN3S\KnowledgeBase\Generator\MenuGenerator; |
|
17
|
|
|
use LIN3S\KnowledgeBase\Iterator\DocumentIterator; |
|
18
|
|
|
use LIN3S\KnowledgeBase\Registry\GeneratorRegistry; |
|
19
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Documents command class. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Gorka Laucirica <[email protected]> |
|
27
|
|
|
* @author Beñat Espiña <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class DocCommand extends ContainerAwareCommand |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function configure() |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
|
|
->setName('lin3s:kb:docs:load') |
|
38
|
|
|
->setDescription('Loads the documents'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
|
|
$configuration = $this->getContainer()->get('lin3s_knowledge_base.configuration'); |
|
47
|
|
|
try { |
|
48
|
|
|
$generatorRegistry = new GeneratorRegistry(); |
|
49
|
|
|
$generatorRegistry |
|
50
|
|
|
->add('html', new HTMLGenerator($configuration)) |
|
51
|
|
|
->add('route', new MenuGenerator($configuration)); |
|
52
|
|
|
|
|
53
|
|
|
$builder = new DocumentationBuilder( |
|
54
|
|
|
new DocumentIterator($configuration), $generatorRegistry |
|
55
|
|
|
); |
|
56
|
|
|
$builder->build(); |
|
57
|
|
|
|
|
58
|
|
|
$output->writeln(sprintf('<fg=green>%s</fg=green>', 'The docs are successfully loaded')); |
|
59
|
|
|
} catch (\Exception $exception) { |
|
60
|
|
|
$output->writeln( |
|
61
|
|
|
sprintf( |
|
62
|
|
|
"<fg=red>%s \n%s\n</fg=red>", |
|
63
|
|
|
'Something wrong happens during the loading process:', |
|
64
|
|
|
$exception->getMessage() |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|