1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class WebUICommand extends ContainerAwareCommand |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
$this |
16
|
|
|
->setName('webui') |
17
|
|
|
->setDescription('Runs a local web server with web UI') |
18
|
|
|
; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Execute the command. |
23
|
|
|
* |
24
|
|
|
* @param InputInterface $input |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
*/ |
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
$routerFile = $this->getContainer()->getParameter('kernel.cache_dir').'/translation_router.php'; |
30
|
|
|
$this->createRouter($routerFile); |
31
|
|
|
|
32
|
|
|
$command = $this->getApplication()->find('server:run'); |
33
|
|
|
$arguments = array( |
34
|
|
|
'command' => 'server:run', |
35
|
|
|
'--router' => $routerFile, |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$commandInput = new ArrayInput($arguments); |
39
|
|
|
|
40
|
|
|
return $command->run($commandInput, $output); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Check if there is a custom router. |
45
|
|
|
*/ |
46
|
|
|
private function createRouter($file) |
47
|
|
|
{ |
48
|
|
|
$content = file_get_contents(__DIR__.'/../Resources/router.txt'); |
49
|
|
|
$root = $this->getContainer()->getParameter('kernel.project_dir'); |
50
|
|
|
|
51
|
|
|
$content = str_replace('__ROOT__', "'$root'", $content); |
52
|
|
|
|
53
|
|
|
file_put_contents($file, $content); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|