gpt4 book ai didi

php - 是否可以从(自动)加载中抑制单个 Composer 依赖项?

转载 作者:可可西里 更新时间:2023-11-01 12:19:11 25 4
gpt4 key购买 nike

我有一个项目,其中包含以下 composer.json 依赖项:

"propel/propel1": "dev-master"`,
"halleck45/phpmetrics": "dev-master"

我最近做了一个composer update,发现PhpMetrics需要的一个新版本的库,叫做Hoa,引入了一个新的类\EngineException来模拟一个新的PHP7类(class)。不幸的是,Propel 1 还定义了 \EngineException,因此产生了冲突。

正确的解决方法是升级到使用命名空间的 Propel 2。然而,这仍处于 alpha 阶段并且会受到 BC 中断的影响,因此对我来说并不是真正可行。

我目前的解决方法是将 Hoa 锁定到没有新类的特定版本:

"hoa/core": "2.15.04.*"

这不是一个糟糕的解决方案,但将库锁定到旧版本并不完全令人满意。

在 Hoa 代码中,不加载新类的唯一方法是运行 PHP 7,这同样不可行。然而,我也想到 Hoa 只需要在 PhpMetrics 运行时被 required。这是一个独立的代码分析工具,为了方便起见,它只位于项目的根目录中;项目的其余部分不使用此库。

因此,如果我可以在 Composer 中调用一些东西来询问这个类是否(自动)加载,或者在 composer.json 中做同样的事情,那就太好了。目前正在不必要地加载它 - 我不知道它是否被错误地自动加载或者它是否被 Composer 手动要求d。

了解 Composer 已将 Hoa 类添加到自动生成的 autoload_psr4.php 脚本中可能会有所帮助。尽我所能understand the docs ,这意味着它是自动加载的,并且我的项目中没有任何内容需要任何 Hoa 类。

最佳答案

https://github.com/hoaproject/Core/commit/8ed00fe9345c4f8b2679a256926d6d24994ea842 修复.

The new exception architecture introduced in PHP7 [1] has been totally redesigned [2]. This patch updates the retro-compatibility classes according to this new architecture. Consequently, the BaseException class has been removed, along with EngineException and ParseException. While these latters could be implemented (not as is), we prefer to, so far, only implement the Throwable interface. Let see if we can implement (still for the retro-compatibility) the Error, TypeError and ParseError class.

[1]: https://wiki.php.net/rfc/engine_exceptions_for_php7

[2]: rfc/throwable-interface

关于php - 是否可以从(自动)加载中抑制单个 Composer 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com