简体   繁体   English

不能从google-api-php-client中获取Symfony中的文件

[英]Cannot require a file in Symfony from google-api-php-client

I need to use google-api-php-client.To do so, I added Google's github repository to my composer.json 我需要使用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"
}

Everything is installed properly and I have the following directory structure: 一切都安装正确,我有以下目录结构:

/vendor
  /google
    /google-api-php-client
      /examples
      /src
        /Google
          Client.php

When I create an object in my Controller, doing the following : 当我在Controller中创建对象时,执行以下操作:

$client = new \Google_Client();

The path and the class are found. 找到路径和类。 However, I get the following error : 但是,我收到以下错误:

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

In my Client.php file, I have the following at the beginning of the file: 在我的Client.php文件中,我在文件的开头有以下内容:

require_once 'Google/Auth/AssertionCredentials.php';

If I change the line to : 如果我将行更改为:

require_once 'Auth/AssertionCredentials.php';

everything works fine for that inclusion. 一切都适合这种包容。 However, I don't want to change each require_once in every file of the google-api-php-client project. 但是,我不想在google-api-php-client项目的每个文件中更改每个require_once I'm sure there is a way to change the inclusion path or something therefore I'm wondering how can I tell that the namespace "Google" is the current directory ? 我确定有一种方法可以改变包含路径或者某些东西,因此我想知道如何判断命名空间“Google”是当前目录?

Edit 1 : I'm guessing that this may be caused because this project (google-api-php-client) does not use namespaces... 编辑1:我猜这可能是因为这个项目(google-api-php-client)不使用命名空间...

Try the following composer settings: 尝试以下作曲家设置:

"repositories": [
  {
    "type": "vcs",
    "url": "https://github.com/google/google-api-php-client"
  }
],
...
"require": {
  "google/apiclient": "dev-master"
}

Notice I'm using google/apiclient instead of google/google-api-php-client . 请注意,我使用google/apiclient而不是google/google-api-php-client This seems to work fine for me. 这对我来说似乎很好。 I'm on PHP 5.4. 我在PHP 5.4上。

I think the reason it's not working for you is because you're missing the include-path in your repository definition. 我认为它不适合您的原因是因为您缺少存储库定义中的include-path If you look at the library's composer.json , you'll see the include-path pointing to the src dir. 如果查看库的composer.json ,您将看到指向src目录的include-path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM