1 | <?php |
||
30 | class CommandExecutor |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $host; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $path; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $cwd; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $console; |
||
51 | |||
52 | /** |
||
53 | * @var PhpFinder |
||
54 | */ |
||
55 | protected $finder; |
||
56 | |||
57 | /** |
||
58 | * @var int |
||
59 | */ |
||
60 | const TIMEOUT = 2; |
||
61 | |||
62 | /** |
||
63 | * @param PhpFinder $finder |
||
64 | * @param RouterInterface $router |
||
65 | * @param RequestStack $request_stack |
||
66 | * @param string $root_dir |
||
67 | */ |
||
68 | 5 | public function __construct(PhpFinder $finder, RouterInterface $router, RequestStack $request_stack, $root_dir) |
|
78 | |||
79 | /** |
||
80 | * @deprecated see self::send() |
||
81 | * |
||
82 | * @throws \InvalidArgumentException |
||
83 | * |
||
84 | * @param string $command |
||
85 | */ |
||
86 | 1 | public function exec($command) |
|
87 | { |
||
88 | 1 | if (!$command) { |
|
89 | 1 | throw new \InvalidArgumentException('Unknown command'); |
|
90 | } |
||
91 | $this->send('php app/console '.$command); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Execute command |
||
96 | * |
||
97 | * If timeout <= 0 and callback is null then command will be executed in background |
||
98 | * |
||
99 | * @param string $command |
||
100 | * @param int $timeout |
||
101 | * @param callable|null $callback |
||
102 | */ |
||
103 | public function execute($command, $timeout = 300, $callback = null) |
||
111 | |||
112 | /** |
||
113 | * @param string $command |
||
114 | * @param int $timeout |
||
115 | * @param callable|null $callback |
||
116 | */ |
||
117 | public function console($command, $timeout = 300, $callback = null) |
||
121 | |||
122 | /** |
||
123 | * @throws \RuntimeException |
||
124 | * |
||
125 | * @param string $command |
||
126 | * @param int $timeout |
||
127 | * @param callable|null $callback |
||
128 | */ |
||
129 | protected function executeCommand($command, $timeout = 300, $callback = null) |
||
137 | |||
138 | /** |
||
139 | * @param string $command |
||
140 | */ |
||
141 | protected function executeCommandInBackground($command) |
||
155 | |||
156 | /** |
||
157 | * Send the command to perform in a new thread |
||
158 | * |
||
159 | * @param string $command |
||
160 | * @param string $host |
||
161 | */ |
||
162 | 1 | public function send($command, $host = '') |
|
180 | |||
181 | /** |
||
182 | * @param string $command |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | 3 | public function prepare($command) |
|
203 | } |
||
204 |