Composer可以在PATH中处理二进制依赖性吗? [英] Can Composer treat binary dependencies in PATH?
本文介绍了Composer可以在PATH中处理二进制依赖性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道作曲家可以确定 php
, hhvm
, ext-< name>
和一些 lib-< name>
依赖关系。在 PATH
上的命令和二进制文件上是否也有可能?实际上,例如,我编写了脚本来确保 Tesseract OCR 存在。可以使用自己的Composer功能吗?
I know that Composer can determine php
, hhvm
, ext-<name>
and some lib-<name>
dependencies. Would the same possible over commands and binaries on PATH
? Actually, for instance, I wrote scripts to ensure that Tesseract OCR is present. It can be done with own Composer features?
推荐答案
您可以使用Composer钩子来实现,例如 pre-install-cmd
或 pre-update-cmd
,它们执行PHP方法。这是我的测试:
You can achieve this using a Composer hook, like pre-install-cmd
or pre-update-cmd
, which executes a PHP method. Here is my test:
composer.json
{
"require": { "pimple/pimple": "*" },
"autoload": { "psr-0": { "Acme\\": "src/" } }
"scripts": {
"pre-install-cmd": "Acme\\Composer\\Hooks::checkBinary",
"pre-update-cmd": "Acme\\Composer\\Hooks::checkBinary"
}
}
src / Acme / Composer / Hooks.php
<?php
namespace Acme\Composer;
use Composer\Script\Event;
class Hooks
{
public static function checkBinary(Event $event) {
$io = $event->getIO();
$path = explode(':', getenv('PATH'));
// do something with $path elements or anything else
if ($somethingWentWrong) {
// Throwing an Exception will cause Composer to stop processing.
throw new \Exception('Check your PATH');
} else {
$io->write('checkBinary() completed.');
}
}
}
这篇关于Composer可以在PATH中处理二进制依赖性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文