1 | <?php |
||
31 | class CommandExecutor |
||
32 | { |
||
33 | /** |
||
34 | * Host |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $host; |
||
39 | |||
40 | /** |
||
41 | * Path |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $path; |
||
46 | |||
47 | /** |
||
48 | * Working directory |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $cwd; |
||
53 | |||
54 | /** |
||
55 | * Console |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $console; |
||
60 | |||
61 | /** |
||
62 | * Php finder |
||
63 | * |
||
64 | * @var \AnimeDb\Bundle\AppBundle\Service\PhpFinder |
||
65 | */ |
||
66 | protected $finder; |
||
67 | |||
68 | /** |
||
69 | * Connect timeout |
||
70 | * |
||
71 | * @var integer |
||
72 | */ |
||
73 | const TIMEOUT = 2; |
||
74 | |||
75 | /** |
||
76 | * Construct |
||
77 | * |
||
78 | * @param \AnimeDb\Bundle\AppBundle\Service\PhpFinder $finder |
||
79 | * @param \Symfony\Component\Routing\RouterInterface $router |
||
80 | * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack |
||
81 | * @param string $root_dir |
||
82 | */ |
||
83 | 5 | public function __construct(PhpFinder $finder, RouterInterface $router, RequestStack $request_stack, $root_dir) |
|
93 | |||
94 | /** |
||
95 | * Execute command |
||
96 | * |
||
97 | * @deprecated see self::send() |
||
98 | * |
||
99 | * @throws \InvalidArgumentException |
||
100 | * |
||
101 | * @param string $command |
||
102 | */ |
||
103 | 1 | public function exec($command) |
|
104 | { |
||
105 | 1 | if (!$command) { |
|
106 | 1 | throw new \InvalidArgumentException('Unknown command'); |
|
107 | } |
||
108 | $this->send('php app/console '.$command); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Execute command |
||
113 | * |
||
114 | * If timeout <= 0 and callback is null then command will be executed in background |
||
115 | * |
||
116 | * @param string $command |
||
117 | * @param integer $timeout |
||
118 | * @param callable|null $callback |
||
119 | */ |
||
120 | public function execute($command, $timeout = 300, $callback = null) |
||
128 | |||
129 | /** |
||
130 | * Execute console command |
||
131 | * |
||
132 | * @param string $command |
||
133 | * @param integer $timeout |
||
134 | * @param callable|null $callback |
||
135 | */ |
||
136 | public function console($command, $timeout = 300, $callback = null) |
||
140 | |||
141 | /** |
||
142 | * Execute command |
||
143 | * |
||
144 | * @throws \RuntimeException |
||
145 | * |
||
146 | * @param string $command |
||
147 | * @param integer $timeout |
||
148 | * @param callable|null $callback |
||
149 | */ |
||
150 | protected function executeCommand($command, $timeout = 300, $callback = null) |
||
158 | |||
159 | /** |
||
160 | * Execute command in background |
||
161 | * |
||
162 | * @param string $command |
||
163 | */ |
||
164 | protected function executeCommandInBackground($command) |
||
178 | |||
179 | /** |
||
180 | * Send the command to perform in a new thread |
||
181 | * |
||
182 | * @param string $command |
||
183 | * @param string $host |
||
184 | */ |
||
185 | 1 | public function send($command, $host = '') |
|
203 | |||
204 | /** |
||
205 | * Prepare command |
||
206 | * |
||
207 | * @param string $command |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | 3 | public function prepare($command) |
|
228 | } |
||
229 |