我使用位于 github 中的两个自行开发的库作为私有存储库,因此我可以在多个项目中重用它。我通过作曲家包括它们:
"license": "proprietary",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/my-account/puc-web-sap-client.git",
"options": {
"ssl": {
"verify_peer": "false"
}
}
},
{
"type": "vcs",
"url": "https://github.com/my-account/puc-web-soap-client.git",
"options": {
"ssl": {
"verify_peer": "false"
}
}
}
],
现在 symfony 抱怨找不到类和服务。我的第一个问题是: 为什么它们不像 symfony 使用的库中的其他类一样自动加载,例如 swiftmailer、phpmd、diablomedia/prettyprinter?所有都是库,默认情况下它们不是 symfony 的一部分。
但是这里的其他答案说,我必须在我的 services.yaml 中手动添加服务 Symfony4 使用外部类库作为服务
因此,我将库中的大量服务添加到 services.yaml 文件中:
Puc\SapClient\:
resource: '../vendor/puc/sap-client/src/*'
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscriber
public: true
Puc\SapClient\Country\CountrySapServiceInterface:
alias: Puc\SapClient\Country\CountrySapService
Puc\SapClient\Country\CountryService:
autowire: true
Puc\SapClient\Currency\CurrencyService:
autowire: true
Puc\SapClient\House\HouseService:
autowire: true
Puc\SapClient\Ressort\RessortService:
autowire: true
Puc\SapClient\Country\CountrySapService:
autowire: true
Puc\SapClient\Currency\CurrencySapService:
autowire: true
....
现在 php bin/console debug:autowiring 给了我以下错误:
Cannot autowire service "Puc\SapClient\Model\Currency": argument "$currencyIsoCode" of method "__construct()" is type-hinted "string", you should configure its value explicitly.
好吧,货币是一种模型,而不是一种服务。它由我的库填充值并返回给我的主应用程序。这是构造函数:
public function __construct(
string $currencyIsoCode,
string $name,
string $ident,
int $numberOfDecimals
) {
$this->currencyIsoCode = $currencyIsoCode;
$this->name = $name;
$this->sapIdent = $ident;
$this->numberOfDecimals = $numberOfDecimals;
}
如何配置此模型以使用字符串?我在哪里做?我真的必须声明我的库正在使用的每一个类吗?要定义每个类的每个参数?