[英]Cannot require a file in Symfony from google-api-php-client
我需要使用google-api-php-client。為此,我將Google的github存儲庫添加到了我的composer.json中。
"repositories": [
{
"type": "package",
"package": {
"name": "google/google-api-php-client",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client.git",
"reference": "master"
},
"autoload" :{
"classmap": ["src"]
}
}
}
]
...
"require" : {
...
"google/google-api-php-client": "dev-master"
}
一切都安裝正確,我有以下目錄結構:
/vendor
/google
/google-api-php-client
/examples
/src
/Google
Client.php
當我在Controller中創建對象時,執行以下操作:
$client = new \Google_Client();
找到路徑和類。 但是,我收到以下錯誤:
ContextErrorException: Warning: require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /Users/etienne/Developpement/Ima-Tech/Clients/lesoptions/vendor/google/google-api-php-client/src/Google/Client.php line 18
在我的Client.php文件中,我在文件的開頭有以下內容:
require_once 'Google/Auth/AssertionCredentials.php';
如果我將行更改為:
require_once 'Auth/AssertionCredentials.php';
一切都適合這種包容。 但是,我不想在google-api-php-client項目的每個文件中更改每個require_once
。 我確定有一種方法可以改變包含路徑或者某些東西,因此我想知道如何判斷命名空間“Google”是當前目錄?
編輯1:我猜這可能是因為這個項目(google-api-php-client)不使用命名空間...
嘗試以下作曲家設置:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/google/google-api-php-client"
}
],
...
"require": {
"google/apiclient": "dev-master"
}
請注意,我使用google/apiclient
而不是google/google-api-php-client
。 這對我來說似乎很好。 我在PHP 5.4上。
我認為它不適合您的原因是因為您缺少存儲庫定義中的include-path
。 如果查看庫的composer.json ,您將看到指向src
目錄的include-path
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.