@@ -164,6 +164,13 @@ protected function checkExtensionIsInstall(OutputInterface $output)
164
164
}
165
165
}
166
166
167
+ /**
168
+ * 创建根目录
169
+ * @author hihozhou
170
+ *
171
+ * @param $directory
172
+ * @param OutputInterface $output
173
+ */
167
174
protected function createBaseDir ($ directory , OutputInterface $ output )
168
175
{
169
176
@@ -257,7 +264,16 @@ public function buildOpenCV($directory)
257
264
}
258
265
}
259
266
260
- protected function buildPHPOpenCV ($ directory )
267
+
268
+ /**
269
+ * 编译安装phpopencv 扩展
270
+ * @author hihozhou
271
+ *
272
+ * @param $directory
273
+ * @param $phpizePath
274
+ * @param $phpConfigPath
275
+ */
276
+ protected function buildPHPOpenCV ($ directory , $ phpizePath , $ phpConfigPath )
261
277
{
262
278
263
279
if (!file_exists ($ directory . '/php-opencv ' )) {
@@ -275,8 +291,9 @@ protected function buildPHPOpenCV($directory)
275
291
try {
276
292
$ commands = [
277
293
'cd php-opencv ' ,
278
- 'phpize ' ,//todo
279
- './configure --with-php-config=/usr/bin/php-config ' ,//todo
294
+ $ phpizePath ,//todo
295
+ './configure --with-php-config= ' . $ phpConfigPath ,//todo
296
+ 'make clean ' ,
280
297
'make ' ,
281
298
'sudo make install '
282
299
];
@@ -289,6 +306,34 @@ protected function buildPHPOpenCV($directory)
289
306
}
290
307
}
291
308
309
+
310
+ /**
311
+ * 获取pecl
312
+ * @author hihozhou
313
+ *
314
+ * @param OutputInterface $output
315
+ */
316
+ protected function getPecl (OutputInterface $ output )
317
+ {
318
+ //尝试通过执行的php寻找对应的pecl
319
+ $ output ->writeln ('Try to get the PECL corresponding to the execution script for PHP... ' );
320
+ $ usePHPBinPath = str_replace (strrchr (PHP_BINARY , '/ ' ), '' , PHP_BINARY );
321
+ $ peclBin = $ usePHPBinPath . '/pecl ' ;
322
+ if (!file_exists ($ peclBin )) {
323
+ $ output ->writeln ('Cannot find the corresponding PECL. ' );
324
+ $ output ->write ('Please enter the path of PECL : ' );
325
+ //未找到则需要用户输入确认
326
+ $ userInput = $ this ->userInput ();
327
+ if (!file_exists ($ userInput )) {
328
+ throw new RuntimeException ('No established PECL program found ' );
329
+ }
330
+ $ peclBin = $ userInput ;
331
+ } else {
332
+ $ output ->writeln ('<info>Find the corresponding pecl script : ' . $ peclBin . '</info> ' );
333
+ }
334
+ return $ peclBin ;
335
+ }
336
+
292
337
/**
293
338
* Execute the command.
294
339
*
@@ -299,24 +344,32 @@ protected function buildPHPOpenCV($directory)
299
344
*/
300
345
protected function execute (InputInterface $ input , OutputInterface $ output )
301
346
{
302
- // 'enable sockets supports? [no] : ';
303
- //查找php配置
304
- try {
305
- $ process = new Process ('which phpize ' );
306
- $ process ->mustRun ();
307
- $ phpizePath = str_replace (PHP_EOL , '' , $ process ->getOutput ());
308
- $ process = new Process ('which php-config ' );
309
- $ process ->mustRun ();
310
- $ phpConfigPath = str_replace (PHP_EOL , '' , $ process ->getOutput ());
311
347
312
- } catch (\Exception $ e ) {
313
- throw new RuntimeException ($ process ->getErrorOutput ());
348
+ $ peclBin = $ this ->getPecl ($ output );
349
+ //todo 判断找到的pecl对应的php和执行的php是否相同
350
+ //pecl config-get bin_dir ,找到bin目录
351
+ $ process = new Process ($ peclBin . ' config-get bin_dir ' );
352
+ $ process ->mustRun ();
353
+ $ bindDir = str_replace (PHP_EOL , '' , $ process ->getOutput ());
354
+
355
+
356
+ //phpize
357
+ $ phpizeBin = $ bindDir . '/phpize ' ;
358
+ if (!file_exists ($ phpizeBin )) {
359
+ throw new RuntimeException ('未找到执行php对应的phpize ' );
314
360
}
315
- exit ;
316
- $ output ->writeln ('<comment>Application ready! Build something amazing.</comment> ' );
317
- $ output ->write ('<comment>Application ready! Build something amazing.</comment> ' );
318
- $ this ->userInput ();
319
- exit ;
361
+
362
+ //找到php-config
363
+ $ phpConfigBin = $ bindDir . '/php-config ' ;
364
+ if (!file_exists ($ phpConfigBin )) {
365
+ throw new RuntimeException ('未找到执行php对应的php-config ' );
366
+ }
367
+ //pecl config-get ext_dir,找到扩展so文件存放轮径
368
+ $ process = new Process ($ peclBin . ' config-get ext_dir ' );
369
+ $ process ->mustRun ();
370
+ $ extDir = str_replace (PHP_EOL , '' , $ process ->getOutput ());
371
+
372
+
320
373
$ this ->checkIsRoot ();
321
374
$ this ->checkExtensionIsInstall ($ output );
322
375
$ this ->buildEnvDetection ();
@@ -335,9 +388,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
335
388
}
336
389
337
390
//编译phpopencv扩展
338
- $ this ->buildPHPOpenCV ($ directory );
391
+ $ this ->buildPHPOpenCV ($ directory, $ phpizeBin , $ phpConfigBin );
339
392
340
- $ output ->writeln ('<comment>Application ready! Build something amazing.</comment> ' );
393
+ $ output ->writeln ('configuration option "php_ini" is not set to php.ini location ' );
394
+ $ output ->writeln ('You should add "extension=opencv.so" to php.ini ' );
395
+ $ output ->writeln ('<comment>PHPOpenCV ready! Build something amazing.</comment> ' );
341
396
}
342
397
343
398
0 commit comments