Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec839fa

Browse files
committed
get pecl
1 parent 76523f5 commit ec839fa

File tree

1 file changed

+76
-21
lines changed

1 file changed

+76
-21
lines changed

‎src/InstallCommand.php

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ protected function checkExtensionIsInstall(OutputInterface $output)
164164
}
165165
}
166166

167+
/**
168+
* 创建根目录
169+
* @author hihozhou
170+
*
171+
* @param $directory
172+
* @param OutputInterface $output
173+
*/
167174
protected function createBaseDir($directory, OutputInterface $output)
168175
{
169176

@@ -257,7 +264,16 @@ public function buildOpenCV($directory)
257264
}
258265
}
259266

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)
261277
{
262278

263279
if (!file_exists($directory . '/php-opencv')) {
@@ -275,8 +291,9 @@ protected function buildPHPOpenCV($directory)
275291
try {
276292
$commands = [
277293
'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',
280297
'make',
281298
'sudo make install'
282299
];
@@ -289,6 +306,34 @@ protected function buildPHPOpenCV($directory)
289306
}
290307
}
291308

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+
292337
/**
293338
* Execute the command.
294339
*
@@ -299,24 +344,32 @@ protected function buildPHPOpenCV($directory)
299344
*/
300345
protected function execute(InputInterface $input, OutputInterface $output)
301346
{
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());
311347

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');
314360
}
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+
320373
$this->checkIsRoot();
321374
$this->checkExtensionIsInstall($output);
322375
$this->buildEnvDetection();
@@ -335,9 +388,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
335388
}
336389

337390
//编译phpopencv扩展
338-
$this->buildPHPOpenCV($directory);
391+
$this->buildPHPOpenCV($directory, $phpizeBin, $phpConfigBin);
339392

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>');
341396
}
342397

343398

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /