Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

"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 :

$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:

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. 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 ?

Edit 1 : I'm guessing that this may be caused because this project (google-api-php-client) does not use namespaces...

like image 237
Etienne Noël Avatar asked Dec 28 '13 02:12

Etienne Noël


1 Answers

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. This seems to work fine for me. I'm on 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. If you look at the library's composer.json, you'll see the include-path pointing to the src dir.

like image 133
anushr Avatar answered Oct 21 '22 14:10

anushr